From patchwork Mon Oct 24 11:31:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp615579wru; Mon, 24 Oct 2022 12:26:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Oebu/E1Jci+t0kR4DwOUQ5whVHdY/kd00L87yWceEWrtncCF3KBeCbJbGthAjxCsi4/Kf X-Received: by 2002:a05:6402:43cb:b0:461:912d:90f with SMTP id p11-20020a05640243cb00b00461912d090fmr10907222edc.375.1666639602091; Mon, 24 Oct 2022 12:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666639602; cv=none; d=google.com; s=arc-20160816; b=cDV3R1LejRu7Jh+z+Ane3TeR1HCx+0UyyNpllr8k1md7S38RnDSaZMjHePnoyJ6Mwe H3va1Ze/40c5qb9cGgHcaCAMgdBznn0kLyNnOGOP5C9vTNGovAAxaNkgH/ELGqr8NjX+ jpgQq0SziHRYb+S1iVg5AbBAzgL/PTjQz3QKzC6PSMs/F1/d+DExN3cNkwGXCchemqq0 SiQUXcDk4DNVXm3bFEv/1uPJtQ7f6ruE4ehjKrz1GGwXDk1RlvlOtNmNTIVwkw2ZF9+p JpjC8ClVmp1TggfC/5uTcRgAu8W2r1GpN3M4cR55fxZ2RZ7kypKfcYYuVkRatHWulSCD Z92Q== 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=rtKEV60INoCQ3414PGodlEschV/qj1go5EZmY2Rox4I=; b=RClPAf0XiKuVopbBZj8/GPPpzgb+mOOTtM46I1xd2VfWMU8AH0k3Z2xbuwZK5wNX/f rcQ7B5BYJ8QpCtUdUqebiPymJdjgyKCmGo/iiHpRWder8A+3hnyfNriyIrbny2hlU2bz ktBur2wfW4vvGY7KWAUw+c5BVAgfFLsHIlU90cwPpcd2DyfI4cGX5xpiYwEY3SvUtyCF yhd7STfiWB/y53BvWIgbft7XuvQjvRcmdWHdVcYvQgvvfvt6nQzh6AGAqqXzwi1HFDAc puzyYE/nFbUjtDq8KmaQECNRHgkPnGefF4X0oG8Cf+Xh58niMUEmnq2QznO40EVWWZQS MB9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UvlB8XkO; 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 z8-20020a056402274800b00457e1a02339si623465edd.592.2022.10.24.12.26.11; Mon, 24 Oct 2022 12:26:42 -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=UvlB8XkO; 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 S231607AbiJXTYp (ORCPT + 99 others); Mon, 24 Oct 2022 15:24:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232105AbiJXTWs (ORCPT ); Mon, 24 Oct 2022 15:22:48 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD6A8C4DA1; Mon, 24 Oct 2022 10:57:35 -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 sin.source.kernel.org (Postfix) with ESMTPS id 535D7CE134D; Mon, 24 Oct 2022 11:52:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67333C433D6; Mon, 24 Oct 2022 11:52:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612352; bh=QsAUGu98aFCufOBe4iBWZ+qBocl7d9WXykBVUjlzfZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UvlB8XkOxmPArORef54xfQrXmn/wGt4pRGP9jYk4SckPA2m8Bquv02bIXXDtNc4Py ddNP+DMwy4BVCzV9wD2sE2VDXxwX7QnKX8Chihi0H38PwO2dyHPc1Np5PdeMcihapP rzj/ix0nJVYQpGhcACL3RLu7dc2OmmS50lUd+2S0= 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 4.14 164/210] thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash Date: Mon, 24 Oct 2022 13:31:21 +0200 Message-Id: <20221024113002.289703206@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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?1747598287249118429?= X-GMAIL-MSGID: =?utf-8?q?1747598287249118429?= 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_powerclamp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/intel_powerclamp.c b/drivers/thermal/intel_powerclamp.c index c3293fa2bb1b..7ff59f86a543 100644 --- a/drivers/thermal/intel_powerclamp.c +++ b/drivers/thermal/intel_powerclamp.c @@ -550,8 +550,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);