From patchwork Tue Jun 13 12:17:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 107341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp499736vqr; Tue, 13 Jun 2023 05:20:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4s4J6rkXu5dGXSndZKFerAdm1LzQKl7PqsWWGQiSX5SjjXe3UgBP+qXf7F7LCK+s+ExXsx X-Received: by 2002:a17:907:320a:b0:975:942e:81d5 with SMTP id xg10-20020a170907320a00b00975942e81d5mr13024156ejb.1.1686658807854; Tue, 13 Jun 2023 05:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686658807; cv=none; d=google.com; s=arc-20160816; b=aCl64TxfiDTzipEc5Z0wpOrI/ito+YEjr/hQpQAg0guq9Vcp9Y95FlkHT+VTgd2BNU /sGbB4EnI86NDc08dpqYqWz3SrCBMmauSlWqe/xJyeTLPnhnBK5ctvY6sRhQkPcsfL1x RoncIh/KpRUrOhNR/0Vtaimun9PLKFhknnAlh+PmQdnX9G4SSxBFVui/FoLNcOnuUwgR rCkZ9ZLWpb5+od/pYd2XV7IZcm8cmAADbyfeXWPCZx67NEx3bTsugtqoyNoHNhrLGXBh ho7Kq/F68vcM+aSV77rmwD3IvbDqPklIUuUCFivUHPrBBopMbHOy4ILucmAqobrLtkGT GZ1Q== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kq19-20020a170906abd300b00965cf8f1be1si4236649ejb.617.2023.06.13.05.19.41; Tue, 13 Jun 2023 05:20:07 -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 S242331AbjFMMSG (ORCPT + 99 others); Tue, 13 Jun 2023 08:18:06 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768589946228815466?= X-GMAIL-MSGID: =?utf-8?q?1768589946228815466?= 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(); /*