From patchwork Mon Jun 23 13:33:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lifeng Zheng X-Patchwork-Id: 899624 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37ECA253F30; Mon, 23 Jun 2025 13:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685655; cv=none; b=EdyGR2v/PhWKVvmgUEj8mRD9eI6ULsvoKUBLAB8O5DHLRka6XmS3h63hvcEL8qXh74Wnh6uUMLHhUXwTjuS9tAaW/hIyfcq0DJjl8A5AAzaUpJerLShQX63zBClYhJSElBz4MWpaJ67SS4BY4ukrGIPxC7I9K9aMHr6kR3qhyjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685655; c=relaxed/simple; bh=joFxsYCC6faUzY7yWeUR1R4xjeuO+x1xGhAFHeU9a+Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pq/1eehk6pmg4VEQnrqKiw6aQH28q18Fa058OHZAsGInePhPsRH3unTh9ZKupADZAmaCTnnEN8qmV33c7yKbgFZr9iesTl82fXjztrPQA0Ni0/ChWSi+S1zclEPJWh/oDtGiVr6ZLSdqLYTkvXPfz4WXrdislrjYgGtbT5YL+sM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4bQppN0Mshz10XJ2; Mon, 23 Jun 2025 21:29:32 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 8912514027D; Mon, 23 Jun 2025 21:34:08 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:07 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 1/7] cpufreq: Disable cpufreq-based invariance when fail to register driver Date: Mon, 23 Jun 2025 21:33:56 +0800 Message-ID: <20250623133402.3120230-2-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) The cpufreq-based invariance is enabled in cpufreq_register_driver(), but never disabled after that when fail. Add a static_branch_disable_cpuslocked() to do that as cpufreq_unregister_driver() does. Fixes: 874f63531064 ("cpufreq: report whether cpufreq supports Frequency Invariance (FI)") Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index d7426e1d8bdd..1bc665b5bba8 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2991,6 +2991,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) err_boost_unreg: remove_boost_sysfs_file(); err_null_driver: + static_branch_disable_cpuslocked(&cpufreq_freq_invariance); write_lock_irqsave(&cpufreq_driver_lock, flags); cpufreq_driver = NULL; write_unlock_irqrestore(&cpufreq_driver_lock, flags); From patchwork Mon Jun 23 13:33:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lifeng Zheng X-Patchwork-Id: 899623 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9561F347DD; Mon, 23 Jun 2025 13:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685655; cv=none; b=d+diINkLHIM9OAMBBXlESxLsCj9iFN9obBbMFJCdIFMFI7tGrAX2aS/iHI01Glkzm/l8ohS555NesucHeRUgPH4o2r3Q/QseaAVuOO5V/bfZaoJHpA8USLH6N+dVcXJbT2FQvuZy2xcibQAaWqhwr/IKJKwyBviG7lJ8W4htapw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685655; c=relaxed/simple; bh=nNs90852AvD7c/IM+vWeq4W0y61YMO+WoWSS8I/UFII=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h9G+5ziwVNNFx7h9MgpOD6V8IPryHhvcu7OqisF0S/SvcidtaV/B/DkBgLgF929YcPXaHSBH1mrzQWleGXqGg9GAqC5WNdDej/ec1vIxwYWVT2GMGmCUd0NutzvDKhsDbVH+NaRwnE1/qjJo7wJ7gQWX2WPyj0ZXj/9rhH92+qg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4bQpq81nVXz2Cff7; Mon, 23 Jun 2025 21:30:12 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id EC216180042; Mon, 23 Jun 2025 21:34:08 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:08 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 2/7] cpufreq: Init policy->rwsem before it may be possibly used Date: Mon, 23 Jun 2025 21:33:57 +0800 Message-ID: <20250623133402.3120230-3-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) In cpufreq_policy_put_kobj(), policy->rwsem is used. But in cpufreq_policy_alloc(), if freq_qos_add_notifier() returns an error, error path via err_kobj_remove or err_min_qos_notifier will be reached and cpufreq_policy_put_kobj() will be called before policy->rwsem is initialized. Thus, the calling of init_rwsem() should be moved to where before these two error paths can be reached. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 1bc665b5bba8..efc1f4ac85cb 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1284,6 +1284,8 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) goto err_free_real_cpus; } + init_rwsem(&policy->rwsem); + freq_constraints_init(&policy->constraints); policy->nb_min.notifier_call = cpufreq_notifier_min; @@ -1306,7 +1308,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) } INIT_LIST_HEAD(&policy->policy_list); - init_rwsem(&policy->rwsem); spin_lock_init(&policy->transition_lock); init_waitqueue_head(&policy->transition_wait); INIT_WORK(&policy->update, handle_update); From patchwork Mon Jun 23 13:33:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lifeng Zheng X-Patchwork-Id: 899626 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37E56253F20; Mon, 23 Jun 2025 13:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685653; cv=none; b=CZ1gNbI0vczJ7VgQ0YH4sKmG+V1RtXmzvyYRi/z9EV1KH1qLNj6uKmdUzS5iNNRbI3WmlsjfGYZomob//knJcKHD/Xl4VmVk4fmaYH6v42VHoMvcXM6h4DfB5BslCgkO8PI9/jRr+V3c9vGBFuB8I66O6M1o8ashThHfDXSh/O8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685653; c=relaxed/simple; bh=beerym7k8zgy8EcfEIxlVoGUrkuzmwMRI1FujU6b5rw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZnXYmQQX9o4JlWujsrH2NkiWJRq0CkVThtGyu2A54frgAG6eZgvL6VPGs71/GNy4mT6zYfnfBCRVXqdnsdra6A6sYzoFk8QUxcYf+jN2VcbGMrrBoB/+1b3P5bk3iIgXJB/bYj9XTymC2/QoktNobIUwJNH+hVECmxwywj0o3gQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4bQppN68Fjz10XJM; Mon, 23 Jun 2025 21:29:32 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 5B4DE18006C; Mon, 23 Jun 2025 21:34:09 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:08 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 3/7] cpufreq: Contain scaling_cur_freq.attr in cpufreq_attrs Date: Mon, 23 Jun 2025 21:33:58 +0800 Message-ID: <20250623133402.3120230-4-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) After commit c034b02e213d ("cpufreq: expose scaling_cur_freq sysfs file for set_policy() drivers"), the file scaling_cur_freq is exposed to all drivers. No need to create this file separately. It's better to be contained in cpufreq_attrs. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index efc1f4ac85cb..2303890de0ba 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -967,6 +967,7 @@ static struct attribute *cpufreq_attrs[] = { &cpuinfo_min_freq.attr, &cpuinfo_max_freq.attr, &cpuinfo_transition_latency.attr, + &scaling_cur_freq.attr, &scaling_min_freq.attr, &scaling_max_freq.attr, &affected_cpus.attr, @@ -1095,10 +1096,6 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy) return ret; } - ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); - if (ret) - return ret; - if (cpufreq_driver->bios_limit) { ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); if (ret) From patchwork Mon Jun 23 13:34:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lifeng Zheng X-Patchwork-Id: 899625 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21662253B58; Mon, 23 Jun 2025 13:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685654; cv=none; b=RfHYkNFrc9mX8BCgmLxH1uLt09OqUgri5PgG67/KRAGXnP1q8TYEsFJh7BNZS7ilcVUhTHkgxjPlpR8SWUfaVHLylsmOh+JlS0lM9ff8O3xmV+39r7oY5UZhvgf6jDyALbDM29vij7KSFuXbiBDc1ysfDHra/QiLv4uob2vG8MA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685654; c=relaxed/simple; bh=AxUz7IYwHHxE4JE7pm9jcypXdfWucVTWW86pgzSsZtw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CiPqvI9HNfnVJFUeIZG/caBB/3vpaUUBFUTdLyBMb+r/xb1yDh3VSsd4osr3ZiqroooakfSdDwAwjGOZ0SwkApZ7/Kc+hw7xBtKSWBCHr9UgjsWlhFr/lCPWTJUX9hRXzJMuOCLd3UpXarfbT2xrfvWqqKqucdpchZlqPgvERJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4bQppQ3ZRSz10XKG; Mon, 23 Jun 2025 21:29:34 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 006641402DB; Mon, 23 Jun 2025 21:34:11 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:10 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 7/7] cpufreq: Exit governor when failed to start old governor Date: Mon, 23 Jun 2025 21:34:02 +0800 Message-ID: <20250623133402.3120230-8-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) Detect the result of starting old governor in cpufreq_set_policy(). If it fails, exit the governor and clear policy->governor. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 7b82ffb50283..2b431845a8a3 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2715,10 +2715,12 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, pr_debug("starting governor %s failed\n", policy->governor->name); if (old_gov) { policy->governor = old_gov; - if (cpufreq_init_governor(policy)) + if (cpufreq_init_governor(policy)) { policy->governor = NULL; - else - cpufreq_start_governor(policy); + } else if (cpufreq_start_governor(policy)) { + cpufreq_exit_governor(policy); + policy->governor = NULL; + } } return ret;