From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41FEEC433FE for ; Sun, 9 Oct 2022 20:53:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230331AbiJIUxL (ORCPT ); Sun, 9 Oct 2022 16:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230082AbiJIUwY (ORCPT ); Sun, 9 Oct 2022 16:52:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10A4E2FFC0; Sun, 9 Oct 2022 13:52:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 99B6560C4F; Sun, 9 Oct 2022 20:52:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF1D1C433C1; Sun, 9 Oct 2022 20:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665348728; bh=sO3qeFRmk2abLCeiuvM40rE2MlBvScvIuhhFNrA1ZVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jv+ZvW4mpqN6GfuNrNUHojDuqIPBKyUKK+A3wjUxdckLDmDQhu+ZzZrSKl5Gv32Z+ SenGZeLRavstYdjkqw6PAeWWDXrgIpWAASWTgwnEpbjBHIaj0tdAGZAjdI3R5Ll+gp fyY6K03N/kJJ6xpAOjgpYrPRmnw5Ywuk+dYpGZvLsmfEGeu/t5mosGmSObiZjJm2YZ kDOAyZdmwJEL/jBJgxMpdpTMi7oiELJg7SFxKGVIbW6AqMs56aRYlCHU+oizCoft7j rv6eTeaoYs2k/HX1ut5AyNxpoxSZVeBjYmy/xYp4nhD8csZth7f5CyvwuaU5fTh5m8 voDSuBUBi5wDA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Srinivas Pandruvada , Chen Yu , "Rafael J . Wysocki" , Sasha Levin , rafael@kernel.org, daniel.lezcano@linaro.org, rikard.falkeborn@gmail.com, yury.norov@gmail.com, linux-pm@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 13/18] thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash Date: Sun, 9 Oct 2022 16:51:30 -0400 Message-Id: <20221009205136.1201774-13-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009205136.1201774-1-sashal@kernel.org> References: <20221009205136.1201774-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Srinivas Pandruvada [ Upstream commit 68b99e94a4a2db6ba9b31fe0485e057b9354a640 ] When CPU 0 is offline and intel_powerclamp is used to inject idle, it generates kernel BUG: BUG: using smp_processor_id() in preemptible [00000000] code: bash/15687 caller is debug_smp_processor_id+0x17/0x20 CPU: 4 PID: 15687 Comm: bash Not tainted 5.19.0-rc7+ #57 Call Trace: dump_stack_lvl+0x49/0x63 dump_stack+0x10/0x16 check_preemption_disabled+0xdd/0xe0 debug_smp_processor_id+0x17/0x20 powerclamp_set_cur_state+0x7f/0xf9 [intel_powerclamp] ... ... Here CPU 0 is the control CPU by default and changed to the current CPU, if CPU 0 offlined. This check has to be performed under cpus_read_lock(), hence the above warning. Use get_cpu() instead of smp_processor_id() to avoid this BUG. Suggested-by: Chen Yu Signed-off-by: Srinivas Pandruvada [ rjw: Subject edits ] Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/thermal/intel/intel_powerclamp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c index c841ab37e7c6..46cd799af148 100644 --- a/drivers/thermal/intel/intel_powerclamp.c +++ b/drivers/thermal/intel/intel_powerclamp.c @@ -532,8 +532,10 @@ static int start_power_clamp(void) /* prefer BSP */ control_cpu = 0; - if (!cpu_online(control_cpu)) - control_cpu = smp_processor_id(); + if (!cpu_online(control_cpu)) { + control_cpu = get_cpu(); + put_cpu(); + } clamping = true; schedule_delayed_work(&poll_pkg_cstate_work, 0); -- 2.35.1