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=1796326230; b=fWQbyT3xmB7W1+UeWA5m2wJmHKOBzJxUtQ6KZNkzY/mv9MJE9X8sk7VbjETLwHb+HnqC S+WCAxV+kjhuXMlAVyRMc4H5feW2pCged0DbvFRXM3469ooK8AKA0Osn5CrCT+DE+9Prg unebvaD3oSE2WTr3JWLbM28UFgnZzcJrgh4h4KhZ1ssQ2aDXAe4WsVP2M59zC3JlQO1o8 BniV0Lbk/zQrXkcNj7gVV1pyv3jTgECgyGXtgthXaAm/33J8Mdp8gNcJt7cW+Hkp8FiAf I383ZxZnzB7cAcKLK+xNPFkuyNwHl6LYEGyJqAYUPJvS0SiHD/H/EOdV+Tejkz5tWYg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796326230; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=o7CzZBaB29YB7mW81aQODomF80xhrLsgYWfUHOycxvc=; b=JtGZpSm5iZ49+azbHqDYr2VF6s2DcOeAvjxL74AaPhfge9U9qX6lzQiigwaEVYmUTlPW L0FNvUAYLtArtxLSGgavh4wZZ7cYV9RGRiH0c3HETgZdxnGNVB5DmzwJm5FHKVrpYH/6/ 9Mk58zO66nI3aVhBvaz6bGj6sa7DxJIxhxuam2bEIu857rOKaWWD57rlJKL50aXn3X0mu HjGTnBeQHAZuM5cfZ6EFvQwGqAYZWnFAqjAUFbQp74HedLdVWy1SsXavYxdzqql1+GHSy FSIVssY/LQ9FA7lrPIdhviB4VSN4IMq5Wv7a/J+7Mk9GYnXQ7KWLRZ20kCxZLYH3nKg== 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=KZoe0zjA; 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 2D314606A685 for ; Thu, 3 Dec 2026 19:30:30 +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=KZoe0zjA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 486B21F0092C; Thu, 3 Dec 2026 19:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796326230; bh=o7CzZBaB29YB7mW81aQODomF80xhrLsgYWfUHOycxvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KZoe0zjA+iY1SvIr38cauMaqN7386NABaeLeFjX6ujWzASISZ6J7bzaUvF33crr9j JJykucHgw3aIP/5eKOhBv2igosmO/MWxCrF7vI4WjSivEeWp14oN00pelkYCyfT0+Y JSm43rnPGA5Ak4lUOjhy1mWBvJbHtYzY1DjLCnlFNlsrJvm4rWVvhjh+8wKlcc4MEK /tIqHbY/w1611uxyGSN40RNFph8Gp1BX+DQhcOpVLyhZrtFWziueySA30kBVBwX2ti chSaEpNrNs5I8r8Oggx0l2YF1BMn72ZBz61hHGNjYesPqGhzZiUOaZyibnlVQam9PX ZhwQXBNfeWENA== From: Sasha Levin To: stable@vger.kernel.org Cc: "Rafael J. Wysocki" , Viresh Kumar , Mario Limonciello , Sudeep Holla , Sasha Levin Subject: [PATCH 6.6.y 2/4] cpufreq: Split cpufreq_online() Date: Thu, 3 Dec 2026 14:30:24 -0500 Message-ID: <20261203193010.628401-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261203193010.628401-1-sashal@kernel.org> References: <2026120247-residency-drab-33a4@gregkh> <20261203193010.628401-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 6450bca6e3b74..fd30060927f32 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1391,32 +1391,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; @@ -1443,7 +1424,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 */ @@ -1594,21 +1575,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) @@ -1622,12 +1592,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