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=1796326857; b=dmV1sjTzsykqYOU6I0YY/p02zcZ27+124JebWjeMZyfLxZZ18mEI/uLwE/CcZAcJ9nJY hvIrf/QetR4pbmjw9Li71H8U+tUitPCPXmpj7bHhxD/lOgcLFk9G7FoY8YsxEz4hUZc7m F27+hin68qpWja0suuz80BU/DV/RLAmZGmPeZRjsFyeeroSqu/8dmMX+pkctfx6QNF5Gj CprJ4zyraOjKzA78ilaiDVmXnTdfaR0FhK66TGNu+grKNO+5lSS5kFZuNqoQDVQHxhyfV tK1zA4XK6+5IU1Ig4oHvIiziTUEQ2ichCMksCS9oWojLcENcnS0TpVRj1MFTLQt12pA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796326857; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=o0/vzdCN7XFZPxnGASEfa7v9PJ+9h38FSSEE4e4j60w=; b=r/FfCWSnLNZeDQxjBoiLnxmPKgVpsusUt1kjNuWWhgloZmAOD3QDt0IzYcOCIXfi+NKJ UR7kh17H49eSv0vJn9p2uc2gruroRBVaSbIb+tMG77Il1B0oM/k5jASsJCJdEQNwt0Jwc 2kSn0NLhUWiDkVJMWwgiZAtPantE1w7E413+K9pnIojP8B4oDSaZsStRDY/YaHvFYndLe NBE4AaSZT+Rt88t2yEYwyHWazUhXsBE2MhlImaNrD8BFI/DOZF1dEsPcIKksLTFFgZjnw nlUc7dCq92BqKSXsrb7VDoB/J34OpgmPJAyPbSIupCUnIyZ7mCSbjYd819L0XKhvJ2Q== 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=BJXxO31N; 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 600B660A3808 for ; Thu, 3 Dec 2026 19:40:57 +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=BJXxO31N Received: by smtp.kernel.org (Postfix) with ESMTPSA id 772481F000CE; Thu, 3 Dec 2026 19:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796326857; bh=o0/vzdCN7XFZPxnGASEfa7v9PJ+9h38FSSEE4e4j60w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BJXxO31Nh6wpiYAk8Ev8irbKwM9H8Si9NzVXZhU+3gxyyzuUiFlQNPbnCjaoNOX9l I4NxDqk4Pcb+P7KIlAAn39LI2oSHL7RAsX/HMOQOmWoLjC+lMOuH4UjH/euvSBes0r hwNpSsUM5QlpftoOt8L8/Hos3e+5zJGmiNq1qSBcYM00LLk0StEIpiXCXzGiTpG0jm AaIpewkSC65tOzbG3mIjLG0LNQz4kcUe4C8hYfe97gpQFv4pN/8f5s3kI/7C0uoijO mdWyw9swEqaGBnBrGMACcODPdzGNCW4yRrLr9JFKxBlDK64O4+UPUMWCjsQWxFVAT6 JNd/IWTXGrHlg== From: Sasha Levin To: stable@vger.kernel.org Cc: "Rafael J. Wysocki" , Viresh Kumar , Mario Limonciello , Sudeep Holla , Sasha Levin Subject: [PATCH 6.1.y 2/4] cpufreq: Split cpufreq_online() Date: Thu, 3 Dec 2026 14:40:51 -0500 Message-ID: <20261203194041.666445-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261203194041.666445-1-sashal@kernel.org> References: <2026120248-concerned-system-eb91@gregkh> <20261203194041.666445-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 de9dec99781b0..b49d7bd3eeb83 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1342,32 +1342,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; @@ -1394,7 +1375,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; } /* @@ -1541,21 +1522,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) @@ -1569,12 +1539,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