Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7506038rwi; Mon, 24 Oct 2022 15:57:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7L8nLR2WLGoYJrw0S5ExEi0BW7B3tnGNLTqBJJVwZNIxSreklF1J07B19GcwfSE3iKW8p5 X-Received: by 2002:a17:90a:c78a:b0:212:e56b:2b17 with SMTP id gn10-20020a17090ac78a00b00212e56b2b17mr15989066pjb.51.1666652266420; Mon, 24 Oct 2022 15:57:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666652266; cv=none; d=google.com; s=arc-20160816; b=pVztYDFNGH+BJlBZFMYLPfLjvsddWuV17FLNtmiUzs4gZB+i1cXZkmAUiwq0JNyrIQ fEs6dWYZuqLspva73wQ/sYKC1XDBISRunUtZcCFbvSslRSoj3q1n0p2+hmB9XbZ1fx4D 7jHKDQyMS2qZgTKRYkBdpGuwxzliveQRedagv26R4M6VSf7bz80nAmqqcho6WNYjpyZS jEnWbcHL4lzfABLuQ3J1Tb9g52GHgHVen16We6ZcUNPLXIEAjQjxKh/3awjN1dP/k8xN xt1SoS+/ff8o7iQBD1otff9YBhdtp8pP0s+VTsK8ZBw9skqAPJIGc1SP8QTe8DulCUaW RWbg== 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=tWzqNkGwZ46AK4R8Wrhrr2GPjlO23rnGKUbSrIRCb44=; b=s/beSxGTkzb/2r4PdM64KFrkZ2KVEDNoDjqMj3kPvfc3uwtaSfJXr11u/iWaEVHcTH 4kwDk3rITum1EhQ2GR5d8t42wPTQmt0nxfrf7Nldogy3N8BXiBEmz050ZxN9IcgrP6Sa 05SnTTvhBcIsSR5fUM9d4XQM8ZiGid4Aneag5b8e6X7WAl8D0J0xviNGK7tRXELf1lnP r39tqaOuN99cpcgpBaJsY1D75DSCjrSAMfgn6uPZuIT59PkfA5YirN4n7v3wQY4nbyeo AX8w4Zt8x7DeIq07uqKEbHqb0Xc15dQ79WTSgD0YFKrkBASwSNGjqzKjir7TpM0sCxRw Taew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hmOKx+zq; 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 q3-20020a634303000000b00439a5dfc7absi797086pga.365.2022.10.24.15.57.34; Mon, 24 Oct 2022 15:57:46 -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=hmOKx+zq; 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 S231245AbiJXVn0 (ORCPT + 99 others); Mon, 24 Oct 2022 17:43:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbiJXVnJ (ORCPT ); Mon, 24 Oct 2022 17:43:09 -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 4D7B02E8BAD; Mon, 24 Oct 2022 12:53:29 -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 80AEFB8160C; Mon, 24 Oct 2022 12:13:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDCF7C433C1; Mon, 24 Oct 2022 12:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613619; bh=WwLmp2q3LG4H7tU6nfLi2QNNkpGu3VvUBc/Mb+G7hoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hmOKx+zqLgTr2zrTA/dwvZd+rGOzkYZXn/ydTR2bDuYqX2R2J2XR8LDqz1FjFfKFJ /N9zLENLidmVJe2o+U/E9BkKxNZW8mWz7aaZihm5/USMxX6neMKuGkQUNw7RMYMYx9 FeRzY6vk+4NC2lPKSsS77eRYG9FNwEpph8PyDq4g= 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.4 188/255] thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash Date: Mon, 24 Oct 2022 13:31:38 +0200 Message-Id: <20221024113009.197311082@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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/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 53216dcbe173..5e4f32733caf 100644 --- a/drivers/thermal/intel/intel_powerclamp.c +++ b/drivers/thermal/intel/intel_powerclamp.c @@ -535,8 +535,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