From patchwork Mon Oct 24 11:31:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9514 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp481983wru; Mon, 24 Oct 2022 07:24:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4C1cGn/WrIJjJj86gvIzVYkeK8R7HYkvkvxhPwkXIBWjTqSfk9DYs/l0vUP4vgIGlnQBWa X-Received: by 2002:a05:6402:5483:b0:45c:1336:6d9b with SMTP id fg3-20020a056402548300b0045c13366d9bmr31063967edb.100.1666621440097; Mon, 24 Oct 2022 07:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666621440; cv=none; d=google.com; s=arc-20160816; b=VvTkaG91HMhnHM2lOunkSQM/LextC69znfbIofWeNGwygsJhMfiFO3/WWzsSyYTK0o njr57EowJ4YZ/L+XHS9gTFL8kZ9wvK+LGeKe3vc3kpyHmwA6jI46EQoAuB7gvXVwNAvO PBEyy2Nx4b5ahDJspMsMzvgcig9Cw4AQDRxUR2Q5hLh+zLEogLfDDCkn8IUWqFcd1vZ2 3folXKouDlrpsJA+BW7CNtAKr3eP5/WoS4HJtcZEhqa6oFuk/yi7gaPr4kcsR7wuGf/K XvPwqgmdBuj1mTMsxKy+cC+/tq3ivJ7l80f3sJeP0tHUmkizpSY61fvox2v8kwmGeVfd Z7xA== 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=SzCnd8F0uIomxgYBaxg/YS8VIwVAO0rHcSo5Xqb19c8=; b=b3VQGOkcnOMFv+mRjr+J1yc9aIV/Z/6z03P/iKzhHD/WK22Y76+yc1Yfj931u3WHJp 1zIVJ4IafMcX7qno+r+1WOHAm8OzuB6E+JF7DfEi7CF9+cUfHMM6V3h9AKlmMJyAdCi9 xdXYDdduaE7E+irmy6PLKYjo2BM+ar4vHp795x500F14f7ZJcKUblAyHrl6Wj/avcbha lP8MFbuhrIqND3VqCbhk2KvyTJXARSC+5I3okseJlOp5kooQO5HN/JqwLICpdVU+i5tK X6ZAjxWOFh9yc0owBN72ZYYuW3oyYEueyH8ZSX12QGj9BzcnvhkNaECsB0s5RsShxM2m fj9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lYTtHGZg; 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 fk5-20020a056402398500b0045154775089si27165859edb.625.2022.10.24.07.23.36; Mon, 24 Oct 2022 07:24:00 -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=lYTtHGZg; 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 S235176AbiJXOWS (ORCPT + 99 others); Mon, 24 Oct 2022 10:22:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231738AbiJXORm (ORCPT ); Mon, 24 Oct 2022 10:17:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D42193685D; Mon, 24 Oct 2022 05:56:16 -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 ams.source.kernel.org (Postfix) with ESMTPS id 734BDB81696; Mon, 24 Oct 2022 12:29:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0ABAC433C1; Mon, 24 Oct 2022 12:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614539; bh=sMbI5Gj5LiK/Mj6Nr4l6ukPafQ7m5GMQYGZXTlMT9Ck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lYTtHGZglLl6iXzw0Nso53vN6fTm3Bg9USPDJy7B58BJ4udMpchiqRlYXCgAG8+hw EJbGymFSs2QEcuI1ZHg22zojFhmaLp8yCNhQVGDTT0AQIqKzIfGbg2juzfG/qdlzSj ovapUKCj9jAPoUIvqLEQoqxXgckgtVMRtoVdhrxw= 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 5.10 300/390] thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash Date: Mon, 24 Oct 2022 13:31:37 +0200 Message-Id: <20221024113035.795106399@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747579243116871605?= X-GMAIL-MSGID: =?utf-8?q?1747579243116871605?= 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 b0eb5ece9243..14381f7587ff 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);