Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7032548rwi; Mon, 24 Oct 2022 09:02:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5iFGjWcG5nv7IohqjiKO4PN4Xcd+XTVPxOaCk6f4ONkaQBprT4Dgl06X0wwZSSwLacsm4A X-Received: by 2002:a17:906:5dcc:b0:78d:e76a:ef23 with SMTP id p12-20020a1709065dcc00b0078de76aef23mr27461627ejv.317.1666627327299; Mon, 24 Oct 2022 09:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666627327; cv=none; d=google.com; s=arc-20160816; b=ckvegnkF3Vy2Md7SofS9X4him4oAjQwTjYhX5fBoa7M2/tmSR+rv7Ve4rri6fH/GkX BcBHdYrIsjeFdGajzGmQLe/RmVChnoXyBDlaGdUrDQpY9KNC7ZWSj9ieY2LPxCoaT2cQ 6Hq3ejvkX2UqYA+x42KgxjEWwCeirebMbeLgRK0mAP2nYrQazgJ34o3R+POm8FevnA1r GpJTLva6bkkm+QqWGMzcCfXP6yMAK6bRb1VfXfkyocz0zh6ph0iZtMsrns6yVZOyxbiY 16I8EihbJAvvbZZjXxA/uSEnWS2hqJyqI8SdekJXDrjShUTILRjI5h7r/8RCARCRdBcC 3BDA== 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=Qzo53QIVpXVFtL1ORHULqRih5y+ZkovW33Zxqt/oJOo=; b=CQBk+JBN/xq7vh6pw7rMKSG/z/Gi9OK01Yd4DpWlYqufxaTuFnGJKX6GtOxflPuCkO mUezB/sEjhUYeBX0eSgvRD9xf1iC2KXd1aRBaJgwwqdxu0F5DFnn1/cml6zM6ofoZ/4j nidA2OUQDqQspXQ+JQRqPSCyLJKP0kfhunINJn+yZbzPTYcuqYXlWurx5i+6I8SSc+wS /wlbw6RGnRmC/Bj0a9ivsBUxSTbveEdMMFzkoLeMbb1nNHEr6bzTKyKtRCDWdM7DKAv4 pVIw/CZ41mt4iHnQoj2sl3ybpLyxfCCHys1qkC3e11RPv3B3DrkqJgKs4wnaTXQ4V+rE MEIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i+iSbkU3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a05640207d200b0045d4b7ad0e4si112572edy.400.2022.10.24.09.01.41; Mon, 24 Oct 2022 09:02:07 -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=i+iSbkU3; 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 S231450AbiJXP6r (ORCPT + 99 others); Mon, 24 Oct 2022 11:58:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232168AbiJXP5x (ORCPT ); Mon, 24 Oct 2022 11:57:53 -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 9ED4D12B373; Mon, 24 Oct 2022 07:52:59 -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 482BEB81196; Mon, 24 Oct 2022 11:43:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 955EFC433C1; Mon, 24 Oct 2022 11:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611825; bh=9S9Jzqh/QQ0jJHUzmYwU6n8cgbVBAGr8mD+X8spS9Kk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i+iSbkU3HGTiE2kHg6lrAITkURIqG0fXrV9+VOi9m1Y9xoui+Q/TXEIeCzntmBw28 gTi1rTm0YuZozbfpniSScW8qjikn8GxpQWlNKQbKfst4nIDmipfxUQUqKr596yo3y/ qLlSYCdYq1AutglIhUoFR0pbSYzLLvRrbwi/+Gzk= 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.9 126/159] thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash Date: Mon, 24 Oct 2022 13:31:20 +0200 Message-Id: <20221024112954.112545109@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 afada655f861..492bb3ec6546 100644 --- a/drivers/thermal/intel_powerclamp.c +++ b/drivers/thermal/intel_powerclamp.c @@ -519,8 +519,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