From patchwork Wed Oct 19 08:32:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4967 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp226796wrs; Wed, 19 Oct 2022 02:46:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5fFtfQl03G0OoaU4AzJ6GAxOcOLcu59sywUatW+cukf0G8wiY0zD3gqEEerrUCCOOp/Myc X-Received: by 2002:a63:d1b:0:b0:42b:828b:f14a with SMTP id c27-20020a630d1b000000b0042b828bf14amr6571433pgl.235.1666172815306; Wed, 19 Oct 2022 02:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172815; cv=none; d=google.com; s=arc-20160816; b=NgFaxvdBizpAtO2UrpHeyh0lp4PoO4LWpdFzMTqBf27w6Xiqif+x9GlIEmN5bGidGh 5Y4TXCLBc5lrn96/n35nEYn4gr3fsxFB6ioB1d2Cte4w1X62gvXy7NxjiAJX7oamF0cn lMVknntR+nNxpsElke/O3BSjYVBXSJzUPdWNDw7alRe8zn0GLhWD+AZIMEdRnQUC4YdX oN6z6EK2rBiHbwZgKMdaou5qPv24TZgVcwXBSPy1oODBnVFMf22CC0ake2q2J/IlFHK5 mkAv+FX9b2p6TMWylVAZqMbwy5chPNoFrnLUnwu1efP66Sm/mz9KpKKysTPfTHqH7Brd /TTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ma9FpLCpZxntQhjPvuA56EGCf9dh3cQ9rCzxLDKkr34=; b=s5F8KPbxppwvmaYZkVbD7/ftaFQaQhHoTmfi71sIN7hxM/2ls+uRq0H60XbaicfqzX rDife+Lcj8KpbEbPPQcRt9NcLx5NSh6Al+QEF9JlcC48GLg1gVdDOy57km7oMqmEPJtJ KFy0l1hweIKP97R8sadN82RlzWOhe9V9+CfYGSnnCBXydAngHNCPmpIboJzZqoCCcy3C XgGxKuooqJfGf4WDAZ15ulI+x3253rH2ciyHcoPc3yqaA3bc4DoN4JmFW+O/FS8lZbcD SDXNhbZwAvyskOwHJx5NLzWGuxkAzsXELii5AWuIGT0XHExWwoZkWbD59NCsR30z4P5S jwyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vc77MsHj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id px4-20020a17090b270400b002008d0b0838si17076451pjb.178.2022.10.19.02.46.42; Wed, 19 Oct 2022 02:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vc77MsHj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234517AbiJSJoX (ORCPT + 99 others); Wed, 19 Oct 2022 05:44:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234704AbiJSJlI (ORCPT ); Wed, 19 Oct 2022 05:41:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD6A6F41B7; Wed, 19 Oct 2022 02:17:50 -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 9F6FB6187C; Wed, 19 Oct 2022 09:08:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3E3DC433D6; Wed, 19 Oct 2022 09:08:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170531; bh=sO3qeFRmk2abLCeiuvM40rE2MlBvScvIuhhFNrA1ZVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vc77MsHjGvsReZkXN0OSzxOv63afc4eWctSKx5Dl4PYM/lYPxKXx5+oQbvxui/Jlz IyjK3U+xPygGI5q/xycHwJz5fBsY5qiPO2V1BHYSyc18Wox86zfBb57bwchJ3/T9D1 zS1rzBYhbgMQj9+Qm4plJK/YdFaZG3uqgx+o2WM4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chen Yu , Srinivas Pandruvada , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.0 673/862] thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash Date: Wed, 19 Oct 2022 10:32:40 +0200 Message-Id: <20221019083319.696819430@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747108826033934437?= X-GMAIL-MSGID: =?utf-8?q?1747108826033934437?= 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);