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=1796382017; b=j2ev+ZvKTOUtzhVhZZF3E6LUHiHLxgKXtR0820LEK0Vv06VyBTLeyfOWPIgOFNxgq/UL mkh+gdi42uFTiUvkSZ1u2G4WNqwEbaS5HaW456mDaoEiIWfdMifI38O1HduYlGK5TZPtR pTdC9ErBiIYkgxiZ0Gkgz9GQJg2cRrZz8g7egfxrVMt2oKtbmph5Acusxyrd8WmKXMhpY AdyPBmaUPNJ9ZwBJFgyeApwLJ3kI9gye1pAhSUWE1Q0rNS2zNBP5BLICEnG7ttrud8cl9 5FqkUfCzsqxk40Cnyzp/Zs32J8+3np3XCuz9VqG2SFB5Bhrk8c0IhVqbcVdo/GVDo3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382017; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=xwOeGINLvUBpQRWE3eN7Lv3X3axPYVQ+2EeTHChvaM4=; b=CKN4SIuXPfWiHc1KQ2exgN5oI1OYMG1QGxHat1exmYYOqN9tXG26p3S5KKspBXBB6f8K UQ9qf/HlfbvXSRh9pMo8MqIs1Un/NLWa1Yy6ZZLRru28N27Rowxz4sXWQnmCIERv8b/9q zAOgEhlRoU/TD9lx98ix5vilYH2mR8OtAaQdz2K23juitu5Jh8V1ENsgftziqm7r7+SNA O+7RgdLbTDPtEz5LkoQ8VRZGfLJ53DGEvy0XNQvqUF16CoLSEa4p/54/K1FuGa9VFlEVm sp1AH4KNu9VT7QeCCE76Ss5dNISsU1B+k6CWa7XErNZGqHnpJllVOw1m5I+pCj3Fc2w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=BHY0pRLo; 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 AD084606A335; Fri, 4 Dec 2026 11:00:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=BHY0pRLo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13FCD1F000C2; Fri, 4 Dec 2026 11:00:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382017; bh=xwOeGINLvUBpQRWE3eN7Lv3X3axPYVQ+2EeTHChvaM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BHY0pRLoSvvBCRU8sEx+MpVynSjanpxF5JsZwqn5F/RGWpZE26pt8HeHo//2tgEo6 ZnbxMOt5/jZyzWgXZxNRzBA+lpg9tHeaobYrzuKayqKBmGrQw7+gVh8rwENfb2nd59 ec70GLn655vOccFMa7mUjUFH7GC6US/vHXJp+2Nw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Borah, Chaitanya Kumar" , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.18 270/703] cpufreq: intel_pstate: Use dedicated lock in set_power_ctl_ee_state() Date: Fri, 4 Dec 2026 19:02:49 +0900 Message-ID: <20261204100634.964505122@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rafael J. Wysocki [ Upstream commit 569e1eb36b033f42a9c363ffe4bfbf50bdadae51 ] Commit eee2a44e4e2b ("cpufreq: Improve suspend-resume synchronization") caused lockdep to complain about a possible circular locking dependency because intel_pstate_resume() is now called under cpus_read_lock, and it calls set_power_ctl_ee_state() that acquires intel_pstate_driver_lock which can be held around CPU hotplug locking. Fortunately, this cannot lead to a real deadlock because intel_pstate_resume() does not run in parallel with the other holders of intel_pstate_driver_lock, but in fact set_power_ctl_ee_state() need not use that particular lock either. Moreover, the original purpose of that lock is different, so using it in set_power_ctl_ee_state() is questionable. Accordingly, introduce a dedicated mutex for protecting MSR_IA32_POWER_CTL updates and power_ctl_ee_state accesses and make set_power_ctl_ee_state() use it instead of intel_pstate_driver_lock. Also take it directly in intel_pstate_resume() around the EE state restore. Fixes: eee2a44e4e2b ("cpufreq: Improve suspend-resume synchronization") Reported-by: "Borah, Chaitanya Kumar" Closes: https://lore.kernel.org/linux-pm/efcb1647-46fd-442a-bbda-283560d9df53@intel.com/ Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/2862244.mvXUDI8C0e@rafael.j.wysocki Signed-off-by: Sasha Levin --- drivers/cpufreq/intel_pstate.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 23262ce56c246..a7c877c668c01 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -1385,13 +1385,14 @@ static void intel_pstate_hwp_offline(struct cpudata *cpu) /* Enable bit for Dynamic Efficiency Control (DEC) */ #define POWER_CTL_DEC_ENABLE 27 +static DEFINE_MUTEX(power_ctl_update_lock); static int power_ctl_ee_state; -static void set_power_ctl_ee_state(bool input) +static void __set_power_ctl_ee_state(bool input) { u64 power_ctl; - guard(mutex)(&intel_pstate_driver_lock); + lockdep_assert_held(&power_ctl_update_lock); rdmsrq(MSR_IA32_POWER_CTL, power_ctl); if (input) { @@ -1404,6 +1405,13 @@ static void set_power_ctl_ee_state(bool input) wrmsrq(MSR_IA32_POWER_CTL, power_ctl); } +static void set_power_ctl_ee_state(bool input) +{ + guard(mutex)(&power_ctl_update_lock); + + __set_power_ctl_ee_state(input); +} + static void intel_pstate_hwp_enable(struct cpudata *cpudata); static void intel_pstate_hwp_reenable(struct cpudata *cpu) @@ -1432,11 +1440,13 @@ static int intel_pstate_resume(struct cpufreq_policy *policy) pr_debug("CPU %d resuming\n", cpu->cpu); - /* Only restore if the system default is changed */ - if (power_ctl_ee_state == POWER_CTL_EE_ENABLE) - set_power_ctl_ee_state(true); - else if (power_ctl_ee_state == POWER_CTL_EE_DISABLE) - set_power_ctl_ee_state(false); + scoped_guard(mutex, &power_ctl_update_lock) { + /* Only restore if the system default has changed */ + if (power_ctl_ee_state == POWER_CTL_EE_ENABLE) + __set_power_ctl_ee_state(true); + else if (power_ctl_ee_state == POWER_CTL_EE_DISABLE) + __set_power_ctl_ee_state(false); + } if (cpu->suspended && hwp_active) { mutex_lock(&intel_pstate_limits_lock); -- 2.53.0