From patchwork Mon May 22 14:07:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tony Battersby X-Patchwork-Id: 97498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1513535vqo; Mon, 22 May 2023 08:03:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4LKyqZvwpl6Y2/dPC2FS2ZQ5tKO4TTFDpr+4bv8caFN6owBHsD9g2zCzoUzsW1LkN4Iggz X-Received: by 2002:a17:902:c1c4:b0:1af:b681:5313 with SMTP id c4-20020a170902c1c400b001afb6815313mr2659281plc.33.1684767780552; Mon, 22 May 2023 08:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684767780; cv=none; d=google.com; s=arc-20160816; b=awBw4w9Q5Re94e6pSmfT3r/1Nf+HMmaU75c23FDVsx+uasbybC+beODBZYbzJ4K3Lj jIhKMuGLKMERxspr/J6RBAIUpFO2xokWemeuYrBQYvWvkgtKCJTXl/Tr+AXnXEhSm8xW jvBs4SXrurfOUSFrWTq1cp+Sw7L7fXaNui43clXm4yFivoxWowoQNQvbLlhN4YPaZ8fH aT3D68HmOLQktx6LyR1RmNIw6GdO8yGsKabC/ZslrNNI0iK0gkdi82TLvW/IKaQa40Vf ce4B4jByOuqn9UWHIZwPV0ZmY2/dI8kXaAJYtEk/18lpf9nkec3S2ojsK0/QJ9PykDjG Qbdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=4E6O0lAp7AWjLeYBN4LPsbrcKqkqgWhw9cCQDP1+2Jg=; b=t80QFuX/UMxDZLP9h/IVyvLmFm9iBJWGmlY1mdkMaaljVkPHxHp/IUup5F8oxo0Wns SsL0T++3BbStgqBbI9ZTtxSzIn5gSHaUAz7s3vG9iBd0YLhp2NUu5ysP5GPbupPrrCoo 37GMFLv79jPrv1Wcss3Jwm14Fyqitb+q7j0Y12QQGVvUBfWtnR/q+iS1N/l6kEqkZtdy Qo/WVBk+kw/y72ry5KZ3zkE/zU3v66S5+0V8sIythqb9JIS6Whj6RxkC1JA/Nqz2Kz8X Jeph5JAO4HqtKvyZ6DBny9dyYJ6O0OT5nhlm0UozWEFsL5FLWr9dAzeTckfyZfDRGRIu 1V6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b=Cf8Js0wN; 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=cybernetics.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 21-20020a170902c11500b001aaed82c2afsi3176520pli.171.2023.05.22.08.02.44; Mon, 22 May 2023 08:03: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=@cybernetics.com header.s=mail header.b=Cf8Js0wN; 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=cybernetics.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234098AbjEVO53 (ORCPT + 99 others); Mon, 22 May 2023 10:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234044AbjEVO5Z (ORCPT ); Mon, 22 May 2023 10:57:25 -0400 X-Greylist: delayed 2984 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 22 May 2023 07:57:19 PDT Received: from mail.cybernetics.com (mail.cybernetics.com [72.215.153.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1694A133 for ; Mon, 22 May 2023 07:57:18 -0700 (PDT) X-ASG-Debug-ID: 1684764420-1cf43912154487a0001-xx1T2L Received: from cybernetics.com ([10.10.4.126]) by mail.cybernetics.com with ESMTP id sFbFNjxpWl4KZr3q; Mon, 22 May 2023 10:07:00 -0400 (EDT) X-Barracuda-Envelope-From: tonyb@cybernetics.com X-ASG-Whitelist: Client DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cybernetics.com; s=mail; bh=4E6O0lAp7AWjLeYBN4LPsbrcKqkqgWhw9cCQDP1+2Jg=; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Cc:To:From: Content-Language:Subject:MIME-Version:Date:Message-ID; b=Cf8Js0wNTqS4JiDyRot5 UWCtaPLqG3Obt4CZ6gaKHSYqSKk0gjnX11/A+IyaYsnIc8EohHBizyr9XWGvfKwEBF2pAY7iD/ELj X9ZKhV3N7nSfIlDA/zGDu/elSNnWwRJPILVQ+3Vzs+kPtyzKG4KfuqyO75/whyOYq5q1uKQUw0= Received: from [10.157.2.224] (HELO [192.168.200.1]) by cybernetics.com (CommuniGate Pro SMTP 7.1.1) with ESMTPS id 12632356; Mon, 22 May 2023 10:07:00 -0400 Message-ID: <3a2c6e29-15bc-c519-573c-c08e5c042868@cybernetics.com> Date: Mon, 22 May 2023 10:07:00 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: [PATCH v2 RESEND] x86/cpu: fix SME test in stop_this_cpu() Content-Language: en-US X-ASG-Orig-Subj: [PATCH v2 RESEND] x86/cpu: fix SME test in stop_this_cpu() From: Tony Battersby To: Thomas Gleixner , Dave Hansen , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H. Peter Anvin" , Mario Limonciello , Tom Lendacky , "linux-kernel@vger.kernel.org" , Andi Kleen References: <3817d810-e0f1-8ef8-0bbd-663b919ca49b@cybernetics.com> <87o7nbzn8w.ffs@tglx> <5f8a9cb8-70cf-2a17-cfc4-cb31cb658de4@cybernetics.com> <87y1mey503.ffs@tglx> <90428c6d-97f6-794f-8cfd-5b30dd5ed140@cybernetics.com> In-Reply-To: <90428c6d-97f6-794f-8cfd-5b30dd5ed140@cybernetics.com> X-Barracuda-Connect: UNKNOWN[10.10.4.126] X-Barracuda-Start-Time: 1684764420 X-Barracuda-URL: https://10.10.4.122:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at cybernetics.com X-Barracuda-Scan-Msg-Size: 2055 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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?1764262659158412921?= X-GMAIL-MSGID: =?utf-8?q?1766607060192845357?= Original thread title: "x86/cpu: fix intermittent lockup on poweroff" I think we all agreed that my small patch below was correct.  tglx also had an additional patch to fix the underlying race condition, but the thread seems to have died out.  Can I get my patch applied at least? Thanks, Tony Battersby Cybernetics --- Check that the CPU supports the desired CPUID leaf before attempting to read it. On Intel, querying an invalid extended CPUID leaf returns the values of the maximum basic CPUID leaf. Depending on the CPU, this could cause the SME test to incorrectly evaluate to true, causing native_wbinvd() to be executed when it should have been skipped (seen on a Supermicro X8DTH-6F board with Intel Xeon X5650). Fixes: 08f253ec3767 ("x86/cpu: Clear SME feature flag when not in use") Cc: # 5.18+ Signed-off-by: Tony Battersby --- Changes since v1: updated title and description. arch/x86/kernel/process.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index b650cde3f64d..26aa32e8f636 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -754,13 +754,15 @@ bool xen_set_default_idle(void) void __noreturn stop_this_cpu(void *dummy) { + struct cpuinfo_x86 *c = this_cpu_ptr(&cpu_info); + local_irq_disable(); /* * Remove this CPU: */ set_cpu_online(smp_processor_id(), false); disable_local_APIC(); - mcheck_cpu_clear(this_cpu_ptr(&cpu_info)); + mcheck_cpu_clear(c); /* * Use wbinvd on processors that support SME. This provides support @@ -774,7 +776,8 @@ void __noreturn stop_this_cpu(void *dummy) * Test the CPUID bit directly because the machine might've cleared * X86_FEATURE_SME due to cmdline options. */ - if (cpuid_eax(0x8000001f) & BIT(0)) + if (c->extended_cpuid_level >= 0x8000001f && + (cpuid_eax(0x8000001f) & BIT(0))) native_wbinvd(); for (;;) { /*