From nobody Tue Oct 7 13:28:36 2025 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (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 EDE4228DF0F; Wed, 9 Jul 2025 10:41:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057721; cv=none; b=jPDx4E6HhpV7TRk8JtxcCD1nc9omHUr3VERBnPCzzIfUTTRg5Ehc1VLX4ILG8kGGPplsINY6hX+2dKcAbWVvWr5itZ/u73kY/eK+6pG0JTTcHW0j8KEnBpzq7yHipIKcZUM0IEkMIqngKL+C0SCLfJyjoqB7ZNYJblXA33Uo8wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057721; c=relaxed/simple; bh=1H+J8U5h8cpezyFExfmPP9y/qJdNuO+Eu5DsumkDTE8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jWqmrF6wWDRU1KDrf9H38RCTQezIox2reEBS0rBcLBecqrnO2FA7iaA3XhqARnUDZydnCaIE2PEl4OWXwUv9vUh16nY3Rl/0Eip4VplCS8ALV8Yl9ML5iRl2kkusdIArhIYfHXwCozQjzUgHnr2XKCgtp4iN7t4lW0z7weP00xs= 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.32 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.44]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4bcZLl2rx0z16TJ2; Wed, 9 Jul 2025 18:42:55 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id A65B5140276; Wed, 9 Jul 2025 18:41:57 +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; Wed, 9 Jul 2025 18:41:57 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH v2 1/4] cpufreq: Move cpufreq-based invariance initialization to where all other initializations have been successfully done in cpufreq_register_driver() Date: Wed, 9 Jul 2025 18:41:42 +0800 Message-ID: <20250709104145.2348017-2-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250709104145.2348017-1-zhenglifeng1@huawei.com> References: <20250709104145.2348017-1-zhenglifeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" The cpufreq-based invariance is enabled in cpufreq_register_driver(), but never disabled after registration fails. Move the invariance initialization to where all other initializations have been successfully done to solve this problem. Fixes: 874f63531064 ("cpufreq: report whether cpufreq supports Frequency In= variance (FI)") Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 6ea39181e832..eb713d116c34 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2940,15 +2940,6 @@ int cpufreq_register_driver(struct cpufreq_driver *d= river_data) cpufreq_driver =3D driver_data; write_unlock_irqrestore(&cpufreq_driver_lock, flags); =20 - /* - * Mark support for the scheduler's frequency invariance engine for - * drivers that implement target(), target_index() or fast_switch(). - */ - if (!cpufreq_driver->setpolicy) { - static_branch_enable_cpuslocked(&cpufreq_freq_invariance); - pr_debug("supports frequency invariance"); - } - if (driver_data->setpolicy) driver_data->flags |=3D CPUFREQ_CONST_LOOPS; =20 @@ -2979,6 +2970,15 @@ int cpufreq_register_driver(struct cpufreq_driver *d= river_data) hp_online =3D ret; ret =3D 0; =20 + /* + * Mark support for the scheduler's frequency invariance engine for + * drivers that implement target(), target_index() or fast_switch(). + */ + if (!cpufreq_driver->setpolicy) { + static_branch_enable_cpuslocked(&cpufreq_freq_invariance); + pr_debug("supports frequency invariance"); + } + pr_debug("driver %s up and running\n", driver_data->name); goto out; =20 --=20 2.33.0 From nobody Tue Oct 7 13:28:36 2025 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (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 DD7BB295517; Wed, 9 Jul 2025 10:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057724; cv=none; b=g8xHkiJ8s0P0bDmRTrQPZqJy4YOrzUaRWpxo3ie+p+L2GWCFDqeld8A3yxeoBaL4prox7NWsl3GVIdufh9IRI0XPXFre4KAInpOG1ZpHQsx+2P5T6scHtsEKOGjqHzhywX7uGz5gKNJlPvw+Pf+461UPtLKFAdGI7LEgS87lrGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057724; c=relaxed/simple; bh=vvmBHtD61cbnPFztUuFrT09mgfVv2kLY4F89WkAEAkU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UoAzhTlMWOIGh77xCyR+j656sarkw3JnH6JAhifAve12J0qybzmUZ8GXs3T9DY4Gr3SbOB956IFULX3oVo24SlUjTLv3/W08rkvy3wK0HPtUbE2r3TZcFxoJjL+9iTp2kfMclnH3o5TgFCbAGojZCuU1z3AXOw6erwFzWWF5svs= 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.255 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.252]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4bcZGb2ZHKz1d1sS; Wed, 9 Jul 2025 18:39:19 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 184C6180B64; Wed, 9 Jul 2025 18:41:58 +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; Wed, 9 Jul 2025 18:41:57 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH v2 2/4] cpufreq: Init policy->rwsem before it may be possibly used Date: Wed, 9 Jul 2025 18:41:43 +0800 Message-ID: <20250709104145.2348017-3-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250709104145.2348017-1-zhenglifeng1@huawei.com> References: <20250709104145.2348017-1-zhenglifeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" 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. Fixes: 67d874c3b2c6 ("cpufreq: Register notifiers with the PM QoS framework= ") 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 eb713d116c34..2175d2df95b6 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1281,6 +1281,8 @@ static struct cpufreq_policy *cpufreq_policy_alloc(un= signed int cpu) goto err_free_real_cpus; } =20 + init_rwsem(&policy->rwsem); + freq_constraints_init(&policy->constraints); =20 policy->nb_min.notifier_call =3D cpufreq_notifier_min; @@ -1303,7 +1305,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(un= signed int cpu) } =20 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); --=20 2.33.0 From nobody Tue Oct 7 13:28:36 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 B11272951BA; Wed, 9 Jul 2025 10:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057723; cv=none; b=ow3jkI2Ao632SZwTe++FIVbPrkiRsJiupyqdWHUiTUB9Jff2Pb4LDWI3sli7T82SZb4d1uR9jLKPRqS7D1GU71ntyvsIKDdhxjFWpUCdOSka+qbQA3Ci9nDeEjhiX3i5ZDLPAHBJCiK0hx5QL7W5xPzncd3WQX774lIwGe56fAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057723; c=relaxed/simple; bh=Q8dzJtRwoGAms35MU2OrgpE4DVsdeE9HVSREh7i9vI4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eFAUpyY0r1DDzNp1/6cpIrYk8dDUYUM1RAqLbtvFad4zyZkaugji4PkXHtOmUFHjiwzGpZ41I+/tYkXsi8MACm13WJXpDA0EXABUEciburQHE//BWoVSv3Zz9FXy4oJW/qtwCEiZQKaKEHSEq3HK7gB4gsRmxOQhfzhd4lem0m8= 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.188 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.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4bcZJN09rzztSmc; Wed, 9 Jul 2025 18:40:52 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 885D2180B64; Wed, 9 Jul 2025 18:41:58 +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; Wed, 9 Jul 2025 18:41:57 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH v2 3/4] cpufreq: Move the check of cpufreq_driver->get into cpufreq_verify_current_freq() Date: Wed, 9 Jul 2025 18:41:44 +0800 Message-ID: <20250709104145.2348017-4-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250709104145.2348017-1-zhenglifeng1@huawei.com> References: <20250709104145.2348017-1-zhenglifeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" Move the check of cpufreq_driver->get into cpufreq_verify_current_freq() in case of calling it without check. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 2175d2df95b6..84f175a55fc5 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1800,6 +1800,9 @@ static unsigned int cpufreq_verify_current_freq(struc= t cpufreq_policy *policy, b { unsigned int new_freq; =20 + if (!cpufreq_driver->get) + return 0; + new_freq =3D cpufreq_driver->get(policy->cpu); if (!new_freq) return 0; @@ -1922,10 +1925,7 @@ unsigned int cpufreq_get(unsigned int cpu) =20 guard(cpufreq_policy_read)(policy); =20 - if (cpufreq_driver->get) - return __cpufreq_get(policy); - - return 0; + return __cpufreq_get(policy); } EXPORT_SYMBOL(cpufreq_get); =20 @@ -2479,8 +2479,7 @@ int cpufreq_start_governor(struct cpufreq_policy *pol= icy) =20 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); =20 - if (cpufreq_driver->get) - cpufreq_verify_current_freq(policy, false); + cpufreq_verify_current_freq(policy, false); =20 if (policy->governor->start) { ret =3D policy->governor->start(policy); --=20 2.33.0 From nobody Tue Oct 7 13:28:36 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 C9229295511; Wed, 9 Jul 2025 10:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057725; cv=none; b=LPj68RwV+VrCEX3keRzi3isb3bsXE56+Hr4RTBA6uloAyJTIqacBnnFw0qPBK8y8fiOJPUuB6xP44vk4AdYD27O3DhR2sHg51Ciu2H2Vb1npR0F+VRUcn31EOeO+kuRB37RnDzI4i5/XgkotYMfrEvwHb80yV7DlDCjVyLREQkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057725; c=relaxed/simple; bh=PKdQWN6KyEHuhS8ypGuhRmp7C2lM8Wdia2DqfvuAIqE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QSJDU5rDTjQkb+FZS9PD8jlbKo6tLZj06r07MAZ5NYw/QO+u7hcXON09ieBzFD+ht6PNLbR0phY0CfUp3X52wkMGJuZ3KXdZc2CAtpHUM0oVZfHonKW0z0CK5UxM2C/JHKUYGwXPDzswQ0fw+Dw1sxEteEyV5wHdogxpq+kiBsI= 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.188 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.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4bcZJN319TztSml; Wed, 9 Jul 2025 18:40:52 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id E8B96180466; Wed, 9 Jul 2025 18:41:58 +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; Wed, 9 Jul 2025 18:41:58 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH v2 4/4] cpufreq: Exit governor when failed to start old governor Date: Wed, 9 Jul 2025 18:41:45 +0800 Message-ID: <20250709104145.2348017-5-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250709104145.2348017-1-zhenglifeng1@huawei.com> References: <20250709104145.2348017-1-zhenglifeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" 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 84f175a55fc5..d24ad67b3f1e 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2711,10 +2711,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 =3D old_gov; - if (cpufreq_init_governor(policy)) + if (cpufreq_init_governor(policy)) { policy->governor =3D NULL; - else - cpufreq_start_governor(policy); + } else if (cpufreq_start_governor(policy)) { + cpufreq_exit_governor(policy); + policy->governor =3D NULL; + } } =20 return ret; --=20 2.33.0