From patchwork Sat Oct 22 07:27:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7861 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1161657wrr; Sat, 22 Oct 2022 04:30:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5RMGReVEf9TTJe+BVbjJ9uvSiUW2i0s/DWhcwad7WoQCSdk0i4q8UfzBNa9uTuzt3/tt/z X-Received: by 2002:a17:90b:3e82:b0:20d:2fa1:d08d with SMTP id rj2-20020a17090b3e8200b0020d2fa1d08dmr64547826pjb.162.1666438258803; Sat, 22 Oct 2022 04:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666438258; cv=none; d=google.com; s=arc-20160816; b=i57JskPe5ew2IQAP2tPGYuHvwdtmskpdGl3jtaqqqc9G4CGOInFWzg/SVeA/tUwac/ cliE1AdkgWmacokXnYCuHPXuSpTPoXOgKkcLqzo0JrknTa7Xtw3glA+QGpgxTs+JVjHZ wgQuAmCTRF1oN3tCoynwBBhM/ofkHu70vL/6CnJpS6rqxCspER+s9DBZl4dR/nAYbaBP shJf+5WH/wQlWKNvt70f/hjlMwuy0fGA4a6mY/RTww/WMkQ+oEgwtwJgOHw9EQXwQ3yu mBF2bv+wkomDPQX1AgpLxeyev/OAoKJnbHSIUllVRPvUCt7Ld0GpCJAl6e7Gr02cS0lQ 7z5A== 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=F+sf9eh/0RQku8gQDl3Lh0OlzwiN1oZJzdQg/uRO9UYWDJkga0KxmqKZM4Q3eyEjEl G9hPaQYqaH3jcWu6IpumB5FP3xYQG8cYaiqtAN1bW1U2GD0LCwFx+Lq8b+RsuqCoGxpy fDis1HdJXoPNRpb68Bb5dTl53ARoXimsoZ6wgBejb0bKdu8vxQfvCRR1bc1gV/+5nZZv 54av2T0iCcrI+yQogS2tKsnAITJ4wpl1lYIjCT7vw2U/BT8PaM/xI03ey/btRzeU97Em vExxQevWg7pshZlhg8c0CGFbyDKo9EbrA/0pDGKZoDFbM9Bt+UK8but9Ey1huSbkGgmH vC4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c0ozydwQ; 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 v10-20020a62a50a000000b005632e26e7ffsi25319155pfm.309.2022.10.22.04.30.45; Sat, 22 Oct 2022 04:30:58 -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=c0ozydwQ; 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 S231126AbiJVLTg (ORCPT + 99 others); Sat, 22 Oct 2022 07:19:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230263AbiJVLTD (ORCPT ); Sat, 22 Oct 2022 07:19:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D0CD5D0F6; Sat, 22 Oct 2022 03:46:12 -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 9CF29B82E0F; Sat, 22 Oct 2022 07:59:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7A5CC433C1; Sat, 22 Oct 2022 07:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425589; bh=sO3qeFRmk2abLCeiuvM40rE2MlBvScvIuhhFNrA1ZVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c0ozydwQproAfgt6JOcL2WYX79wb6CiuZ58OZsD2a/nYQIfhOohBQ68+WjQOTSuPj pCHDp4nSpsdCEZzggGQmmgH2s+JH54wRt5fjlbN8LSRFBoL09vT6f5b9cBeRwaqIx6 l+y8wWoskVIPeFn3+ZQkc9r8bLf74xFZ94E3P6b4= 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.19 550/717] thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash Date: Sat, 22 Oct 2022 09:27:09 +0200 Message-Id: <20221022072522.694733012@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@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?1747387163869925458?= X-GMAIL-MSGID: =?utf-8?q?1747387163869925458?= 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);