Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1131782rwd; Tue, 13 Jun 2023 05:26:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4eygJbkBcVVpxifp6jMkeD0iD58bBFf+H2gO8gF9fjbs+aKjhrxS64HXSb5pCgyVyUcF70 X-Received: by 2002:a05:6830:130c:b0:6af:6f25:487 with SMTP id p12-20020a056830130c00b006af6f250487mr9676861otq.6.1686659216780; Tue, 13 Jun 2023 05:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686659216; cv=none; d=google.com; s=arc-20160816; b=Sc16mb1u9h5K2ze7hNxp+S5WYMgSUtIkWBHxdqrE0Oy95JAF7hwOhFPMGnMWOUTeMf TQkvsaKpQZm5YEs2HW4aOb7mfhaAg07F+FAXHYakIqCkFeXS3H1Qg3JBWod8vuVFo3qY wkMua4iYVmFksWM8Grx9Couoq5w7wCrTo23/etwRyD3Qw78ag0kgTPfRxHHsxZefxtuH ETcdRYK4wpNc3tlM7d1bFMfk+SnIFXWW+4LyHyGjffy30EDG9hmi35kTj/Yx/la3x1NY ajZfoAbGiRG54fA63VINXVChwr+rEokSYrs3n4+zxsPDLI1kFQmyf8CtS8dRmTytIxAO OLUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=HM6V+irlq0EoYO9XtWgZJ+0ilH4pTT198i0/jTCKMCs=; b=HkeGimp5NWhaJPyhErA7uqcq3xHQx26Pqd780cqgOXVIGAakhSo5liyId6eG9RI0SQ 9n7yXtUvkhjr0P8wO68fXoAOMVI2oSQuNrFGJgHTejuY1mWyJ/yq61AKiPZBUPuTFI9m By5DDiPGQyuqL9ulWhyFIfjuN6tXNwvBF9jmEj7+X3l9yaBDHK1GLPWoRmkgFMJt5ciG SgCEVSixhI+Kzcyd/pPjZOWL0/QLGedLuKvleez3wdvQXwN9aAHw7nC6U8N4efH4xqPQ xWCtZEpEEv6k7aJKGFt79WovS7K2d52r/Q2Q4zWkw72ZFzHhvteOF5ojDd2ZeTycpnJo kwqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GJm07Y87; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv128-20020a632e86000000b0054f93b05b51si2984802pgb.96.2023.06.13.05.26.42; Tue, 13 Jun 2023 05:26:56 -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=@linutronix.de header.s=2020 header.b=GJm07Y87; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242325AbjFMMSF (ORCPT + 99 others); Tue, 13 Jun 2023 08:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240344AbjFMMR7 (ORCPT ); Tue, 13 Jun 2023 08:17:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2A7DCE for ; Tue, 13 Jun 2023 05:17:58 -0700 (PDT) Message-ID: <20230613121615.697412459@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686658677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=HM6V+irlq0EoYO9XtWgZJ+0ilH4pTT198i0/jTCKMCs=; b=GJm07Y878g9vNRWiWCyGq50zu00hhSLlq6nAhrAbyrA0rxJLVi1O8/XalaKYs5Q2A3CwR6 KkwQ6IpRoXfyLscT9bkdfkIJptf1VvUjNFQUkXsz9kxp9rMbGZqU+s9DPLPzTTQRLBaU8N 5TQucOy1T+9LZQY2pei87uZM9DkiIsUpi9DJbcGoBMUpkKIo0w2+tNkDHhmyEubRtBm94/ POvT8ZEdm8HAowmgLsE1pAjxAmbMVTLLphIIptjwzDqgIKBP3iNBd1ORvPwUTpkY3nEbMv bdEhlar1yAaVjlBpsIZDg8rjvjy2jji4fRzw0AUSdBpvyEEvOrxYnT5SIoP5zA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686658677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=HM6V+irlq0EoYO9XtWgZJ+0ilH4pTT198i0/jTCKMCs=; b=dyViilN1El+jNxDNYUEbnhtqsOckRJgiExrmzt8Tb/SNbuyGsPTqh4GWxs1VsBxF1AKKtj RdnqWTfKf1C21JAw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Mario Limonciello , Tom Lendacky , Tony Battersby , Ashok Raj , Tony Luck , Arjan van de Veen , Eric Biederman Subject: [patch V2 2/8] x86/smp: Dont access non-existing CPUID leaf References: <20230613115353.599087484@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 13 Jun 2023 14:17:57 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 From: Tony Battersby stop_this_cpu() tests CPUID leaf 0x8000001f::EAX unconditionally. CPUs return the content of the highest supported leaf when a non-existing leaf is read. So the result of the test is lottery except on AMD CPUs which support that leaf. While harmless it's incorrect and causes the conditional wbinvd() to be issued where not required. Check whether the leaf is supported before reading it. [ tglx: Adjusted changelog ] Fixes: 08f253ec3767 ("x86/cpu: Clear SME feature flag when not in use") Signed-off-by: Tony Battersby Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/3817d810-e0f1-8ef8-0bbd-663b919ca49b@cybernetics.com --- arch/x86/kernel/process.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -763,13 +763,15 @@ atomic_t stop_cpus_count; 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 @@ -783,7 +785,7 @@ void __noreturn stop_this_cpu(void *dumm * 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(); /*