From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796325070; b=fpbe2vZxfqHkRrU7F/9Rdpld/nwVs3D8qvgk9GHmxE8uQ8yzZweCEikajHB0HK+dtooC 12YKr+fKZtHKuHglThMW+8rATEH3zTH9v7QKHeQwgENg9NZtDl/a06fb4M1zE0tQtj9VS Bk2HTflKigIR4c0nCVvEOZpO+d13mzKHkkxcEUTeGhFjFLfECYj8W4lp3zJLDR7BvT0H8 RTzKkVwIlugZOi5xpz9sn9SH3fc96NRZ8FURyvAO+BTGRBRIm9tNf1X8WJvHX2+8Qd6IC hReyOCTrlwxkudNVwtmHIS4hOllv26BTOn85pXm5hf6nuzzlGUxRYOHZd9Vsr3v0vsg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325070; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=hs2agVfngl494Oyz6W0Oh8z3j0zWosPpHbAPGuwI5oc=; b=iIEwf8309SMSbyMsGXFL3k2UtOi4AdovTyQDPQXALoPUI8VyO34Z+MoPKJEQ2oBrESlS y0Y6XbkGnCRKWyh5N9rwi0hPwaDVdtjJVbleIQhvOxvEeHeCEuu8++IfEOpA7UUr1rK0c Yzflzwu+ky/HZjq62H1B5e2nC2rW1aMz2V2qR2LG+o+wSQNZ08cAechFUxDYnKMea4/aX Ol8uUOqA5Kz1XPTK+RgfVHTPrsfbAHJRE6Kat6cHn+kGMq9k1jb2XYRRlZQHrUeRyUxr0 yc5F2GSshfomoLvs4xCd5w/3rVNnvAzqVtzDWsBN7NHDVsaMnd//8Tkal2G7tCNQU2w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=njnx6FYW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3350260A2612 for ; Thu, 3 Dec 2026 19:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=njnx6FYW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F6A11F0092B; Thu, 3 Dec 2026 19:11:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796325070; bh=hs2agVfngl494Oyz6W0Oh8z3j0zWosPpHbAPGuwI5oc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=njnx6FYWwFvLtbCi1VBPLNK15Yiirdg5sWg2WMqFJgwraFikyok3h9grqTrYXTj64 pVOe242T6z7GVA/+U8OqyeGDwzL3E+tFzY/NrlKgLb+eX6K0OGVCkvuDg0xmgK9kpq iE7kl4CrCV8NgghiX366Bszo277pyVbLE96N3i1Eh6LKBEv9TaAHAwvzOksYQSRXS5 di1P86kbfKfWpvQvhMpPmjotT9doKMo/5RF8R/3jyWWDhRFAOOWGT5jtvfxSGt0ZHb xh02PW4HH6l/Q8+De5fqh7c0yDe9XHoa/WdyBFGJpKKTlJ/dc329o/Tu/qzAbzlMB2 N7kbJLQSuKovw== From: Sasha Levin To: stable@vger.kernel.org Cc: "Rafael J. Wysocki" , Viresh Kumar , Mario Limonciello , Sudeep Holla , Sasha Levin Subject: [PATCH 6.12.y 2/4] cpufreq: Split cpufreq_online() Date: Thu, 3 Dec 2026 14:11:04 -0500 Message-ID: <20261203191049.594480-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261203191049.594480-1-sashal@kernel.org> References: <2026120246-salami-crudely-9a3f@gregkh> <20261203191049.594480-1-sashal@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Rafael J. Wysocki" [ Upstream commit 68974e3a15b92639396f39d1cd09d5288ba687bc ] In preparation for the introduction of cpufreq policy locking guards, move the part of cpufreq_online() that is carried out under the policy rwsem into a separate function called cpufreq_policy_online(). No intentional functional impact. Signed-off-by: Rafael J. Wysocki Acked-by: Viresh Kumar Reviewed-by: Mario Limonciello Acked-by: Sudeep Holla Tested-by: Sudeep Holla Link: https://patch.msgid.link/3354747.aeNJFYEL58@rjwysocki.net Stable-dep-of: c5bdb8757372 ("cpufreq: Skip inactive policies in cpufreq_driver_target()") Signed-off-by: Sasha Levin --- drivers/cpufreq/cpufreq.c | 91 ++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 79a2bbda0d944..7970e6f706c9d 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1379,32 +1379,13 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy) kfree(policy); } -static int cpufreq_online(unsigned int cpu) +static int cpufreq_policy_online(struct cpufreq_policy *policy, + unsigned int cpu, bool new_policy) { - struct cpufreq_policy *policy; - bool new_policy; unsigned long flags; unsigned int j; int ret; - pr_debug("%s: bringing CPU%u online\n", __func__, cpu); - - /* Check if this CPU already has a policy to manage it */ - policy = per_cpu(cpufreq_cpu_data, cpu); - if (policy) { - WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); - if (!policy_is_inactive(policy)) - return cpufreq_add_policy_cpu(policy, cpu); - - /* This is the only online CPU for the policy. Start over. */ - new_policy = false; - } else { - new_policy = true; - policy = cpufreq_policy_alloc(cpu); - if (!policy) - return -ENOMEM; - } - down_write(&policy->rwsem); policy->cpu = cpu; @@ -1431,7 +1412,7 @@ static int cpufreq_online(unsigned int cpu) if (ret) { pr_debug("%s: %d: initialization failed\n", __func__, __LINE__); - goto out_free_policy; + goto out_clear_policy; } /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */ @@ -1582,21 +1563,10 @@ static int cpufreq_online(unsigned int cpu) goto out_destroy_policy; } +out_unlock: up_write(&policy->rwsem); - kobject_uevent(&policy->kobj, KOBJ_ADD); - - /* Callback for handling stuff after policy is ready */ - if (cpufreq_driver->ready) - cpufreq_driver->ready(policy); - - /* Register cpufreq cooling only for a new policy */ - if (new_policy && cpufreq_thermal_control_enabled(cpufreq_driver)) - policy->cdev = of_cpufreq_cooling_register(policy); - - pr_debug("initialization complete\n"); - - return 0; + return ret; out_destroy_policy: for_each_cpu(j, policy->real_cpus) @@ -1610,12 +1580,55 @@ static int cpufreq_online(unsigned int cpu) if (cpufreq_driver->exit) cpufreq_driver->exit(policy); -out_free_policy: +out_clear_policy: cpumask_clear(policy->cpus); - up_write(&policy->rwsem); - cpufreq_policy_free(policy); - return ret; + goto out_unlock; +} + +static int cpufreq_online(unsigned int cpu) +{ + struct cpufreq_policy *policy; + bool new_policy; + int ret; + + pr_debug("%s: bringing CPU%u online\n", __func__, cpu); + + /* Check if this CPU already has a policy to manage it */ + policy = per_cpu(cpufreq_cpu_data, cpu); + if (policy) { + WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); + if (!policy_is_inactive(policy)) + return cpufreq_add_policy_cpu(policy, cpu); + + /* This is the only online CPU for the policy. Start over. */ + new_policy = false; + } else { + new_policy = true; + policy = cpufreq_policy_alloc(cpu); + if (!policy) + return -ENOMEM; + } + + ret = cpufreq_policy_online(policy, cpu, new_policy); + if (ret) { + cpufreq_policy_free(policy); + return ret; + } + + kobject_uevent(&policy->kobj, KOBJ_ADD); + + /* Callback for handling stuff after policy is ready */ + if (cpufreq_driver->ready) + cpufreq_driver->ready(policy); + + /* Register cpufreq cooling only for a new policy */ + if (new_policy && cpufreq_thermal_control_enabled(cpufreq_driver)) + policy->cdev = of_cpufreq_cooling_register(policy); + + pr_debug("initialization complete\n"); + + return 0; } /** -- 2.53.0