From patchwork Tue Apr 25 19:26:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Battersby X-Patchwork-Id: 87537 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3641221vqo; Tue, 25 Apr 2023 13:04:17 -0700 (PDT) X-Google-Smtp-Source: AKy350bvAX1szjpoOAFXYV9BDbaHtxHsJLtMFwHwrQxkBeCu/Sh1aWEQfsBpDHXT4mQBRK+wFNqd X-Received: by 2002:a17:90a:b102:b0:246:f8a8:af02 with SMTP id z2-20020a17090ab10200b00246f8a8af02mr17924115pjq.5.1682453056693; Tue, 25 Apr 2023 13:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682453056; cv=none; d=google.com; s=arc-20160816; b=HslFJtxC95v3QdS2zwfrs/p51TADS0jRkEVKIVHRjos9j8vsXXLNJbU/9jE6v4MeHv eUR3MVj3iUqaFm6/ewBHLXFOvToiIYZWbMT6q85tZd1R4c2Bsd8PcW6lqvnZ28X3ch3g CY70XIfmBY1s59ebzXtD2Qoj0hpd5HfPEwhtKiFCMpOwE20ikx0R8kQyKv4M9Icybpbc sxoictxWfnLSSl05tJutMkt4jBZU2EUCviQsGaGgMCDxnzzdOlSC3WFguNR/MsjH6Ugu Q/62KwAf3v15wd4q3hhU7msVSMY+2+xCOmWo+MBJ5Ol94VW1MimvgXDjaSFNfmD1E2wQ Oamg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id :dkim-signature; bh=NKoTw0X5ggn4GP4rCHMZBRbxnmfIguEqeaihKcA5REk=; b=RBABw9ZYPgkKHKvPJaNDvAYHrf0M74CX3WTsew3NsCf0+pdeuafxGx8WNbeqrzPoOG YOi0g2ILl4QGGZ3Dt0azo7y4yh3vjnbn/zJdf+jBhQcq57W+bXUXzS+L6FR8Onfl5Tw+ POfe5f1i2LRIoddzr137QFQFN9g8Kkts4nt8XNSCQeyDz4xKW/ADtby+cuH3/qciAeSC VxR0UAYhCFJ1luf0hpCDKb0DYEhGBlBqdYvWHbf/oNO0h0Ma/NIsWiqo/0A1z0D4FAin Ot6yd0wnPeiXT6RXKzW+tJ5+hU956ahFKS+HjGd83nliRptuqWCPAYp1gowyYIAMpf9V +v7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b=XjJvQNfR; 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 l7-20020a6542c7000000b004dacaa17ecbsi13620698pgp.559.2023.04.25.13.03.37; Tue, 25 Apr 2023 13:04:16 -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=XjJvQNfR; 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 S236150AbjDYT5Q (ORCPT + 99 others); Tue, 25 Apr 2023 15:57:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234754AbjDYT5O (ORCPT ); Tue, 25 Apr 2023 15:57:14 -0400 X-Greylist: delayed 1817 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 25 Apr 2023 12:57:12 PDT Received: from mail.cybernetics.com (mail.cybernetics.com [72.215.153.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC25C19A2 for ; Tue, 25 Apr 2023 12:57:12 -0700 (PDT) X-ASG-Debug-ID: 1682450813-1cf4391215313690001-xx1T2L Received: from cybernetics.com ([10.10.4.126]) by mail.cybernetics.com with ESMTP id UJmp3BejnK1cjIIr; Tue, 25 Apr 2023 15:26:53 -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=NKoTw0X5ggn4GP4rCHMZBRbxnmfIguEqeaihKcA5REk=; h=Content-Transfer-Encoding:Content-Type:Subject:From:Cc:To:Content-Language: MIME-Version:Date:Message-ID; b=XjJvQNfRCimTBY0NYTJiqaV9m5jO6rqZsItwTv2jCDwOE avvzTgWVFYvLTXnDb4GXZREDk1+OzndudyR/3Q9FlskrpRtPaFaczQNSQ12HBhOF1DvPeBiMCO0zE njol8uefnZ/keDtObWbQu/fhnYfYYmZHFqIc9bRsxOj06gv4o= Received: from [10.157.2.224] (HELO [192.168.200.1]) by cybernetics.com (CommuniGate Pro SMTP 7.1.1) with ESMTPS id 12590162; Tue, 25 Apr 2023 15:26:53 -0400 Message-ID: <3817d810-e0f1-8ef8-0bbd-663b919ca49b@cybernetics.com> Date: Tue, 25 Apr 2023 15:26:53 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Content-Language: en-US To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H. Peter Anvin" , Mario Limonciello , Tom Lendacky , "linux-kernel@vger.kernel.org" From: Tony Battersby Subject: [PATCH RFC] x86/cpu: fix intermittent lockup on poweroff X-ASG-Orig-Subj: [PATCH RFC] x86/cpu: fix intermittent lockup on poweroff X-Barracuda-Connect: UNKNOWN[10.10.4.126] X-Barracuda-Start-Time: 1682450813 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: 1697 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,URIBL_BLOCKED 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?1764178577694427736?= X-GMAIL-MSGID: =?utf-8?q?1764179896442095303?= In stop_this_cpu(), make sure the CPUID leaf exists before accessing the leaf. This fixes a lockup on poweroff 50% of the time due to the wrong branch being taken randomly on some CPUs (seen on Supermicro X8DTH-6F with Intel Xeon X5650). Fixes: 08f253ec3767 ("x86/cpu: Clear SME feature flag when not in use") Cc: # 5.18+ Signed-off-by: Tony Battersby Tested-by: Tony Battersby --- NOTE: I don't have any AMD CPUs to test, so I was unable to fully test this patch. Could someone with an AMD CPU that supports SME please test this and make sure it calls native_wbinvd()? arch/x86/kernel/process.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 (;;) { /*