From patchwork Thu Jun 15 20:33:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 108717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp909868vqr; Thu, 15 Jun 2023 13:56:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64YJ9WRwIxfuVW8QeTGh7UnRfErUSLFyJtAsGswchthmFftw+0zMUij/wN1JDGItHRTqy8 X-Received: by 2002:a05:6358:1a91:b0:12b:e7be:b495 with SMTP id gm17-20020a0563581a9100b0012be7beb495mr9259595rwb.7.1686862612158; Thu, 15 Jun 2023 13:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686862612; cv=none; d=google.com; s=arc-20160816; b=bA96qjKF/ZzWenGLexAeIbp8cqYLCacobzgGmz39D/H3qEBNPAP60a8mfYpxTbQC6h JGlBKHLBTIi6h+SUBN2ac0M3ducvOCOZuJ0QqEgFolPyPg5/Lz9jyW392KWKh5be78hc WtLfEOcFGdzkzkR9CoUP4CamxBxjhtZrUwJ6bLfhpa+A3IP922+1S/mt/d590I5f4R1f +FuJQnZrd3XJOS2lv8gkknA1m20bnYW9x/ZQx5uckf5d4lrPkW6f1lNeNbg0XHXqbbMw 9iOHY24bL78FjXrV/ife2WOb4KYLUCuwUf9juH4PHrG/zXQ1b/BEhScKRr2yRPjNtJL8 /tcw== 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=F5oJwB0GE84n/VmQ+gAa3Veuk6SxbBp4c68eFnUy6Y0=; b=o0F2vsjzHMw3HiNX3bVmecdeRpIbY4VyG21lxDMFO0JtWg49QNS4mlEn1WIHTpJYGd YOgQuKtCNlN5hfR4XRWCJviRRlA+mBpV5TkARO5mu9SPwfsYir9FzcevDrsMCyocr53x 9CrYvum4YIkylcDJSNNrKkNSiEFPhjKjZdeyiS83VhANmkpXEPaNRx11uDH7eHPsvzMB R+rPbw2baR06rRyp86Vc75bi3NlIm3g/cmq4G1VvJSlFi1ZYzdF6wPoZZ6A6dP5Fu11R uLmjuMdqAgdWXh7//ZUsj4hsW6Oyo/OB5AtGltGfzE3kg6wu0htPFtpqcxzXeNHussP0 WmNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UMuAs2SM; 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 l20-20020a639854000000b005533c53e642si617786pgo.47.2023.06.15.13.56.39; Thu, 15 Jun 2023 13:56:52 -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=UMuAs2SM; 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 S231837AbjFOUeB (ORCPT + 99 others); Thu, 15 Jun 2023 16:34:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232027AbjFOUdz (ORCPT ); Thu, 15 Jun 2023 16:33:55 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C9EC2711 for ; Thu, 15 Jun 2023 13:33:54 -0700 (PDT) Message-ID: <20230615193330.322186388@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686861233; 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=F5oJwB0GE84n/VmQ+gAa3Veuk6SxbBp4c68eFnUy6Y0=; b=UMuAs2SM92SW0z9tELVFy5u/AMkL0NDmXH+pafezqQnMYC6OcnR88nEjpLcIpn5Z31tJ5C W91OTZbh7MzxP0ZllmRwkGkeyQN5UNiiJzrNYM+LXF15SvSD08/SZwXgKw1zfeg4uHevjR F8k9caqbsp+XR4MbKy6RyPOuTt7yVGEiI0lizgpovAvqGYur+DGqGXWOTcthd6Hov1hqZV 5CoSfIv9E6/BcqfiQGAUo7BhhyODWKAF8yfLhx+0zXqJdpAA5V2+7RIwrwCKjQE3SvO/Dp EP6QVqvQBCZ4A5Cc9S2SKdFgu0mV2lwucvNBc4xvYhl/2NHl6QVSZLgS7OD6QA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686861233; 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=F5oJwB0GE84n/VmQ+gAa3Veuk6SxbBp4c68eFnUy6Y0=; b=c6anQgBHPb6ZHy+bj8yaIUYehPRUCxgGiX9lejOeWUl50NRgTNB9O6jeTDFaMRCzcZoeNN luLww6OHL36NQdAA== 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 v3 2/7] x86/smp: Dont access non-existing CPUID leaf References: <20230615190036.898273129@linutronix.de> MIME-Version: 1.0 Date: Thu, 15 Jun 2023 22:33:52 +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 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?1768803650342093502?= X-GMAIL-MSGID: =?utf-8?q?1768803650342093502?= 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 Reviewed-by: Mario Limonciello Reviewed-by: Borislav Petkov (AMD) --- arch/x86/kernel/process.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -763,6 +763,7 @@ struct cpumask cpus_stop_mask; void __noreturn stop_this_cpu(void *dummy) { + struct cpuinfo_x86 *c = this_cpu_ptr(&cpu_info); unsigned int cpu = smp_processor_id(); local_irq_disable(); @@ -777,7 +778,7 @@ void __noreturn stop_this_cpu(void *dumm */ set_cpu_online(cpu, 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 @@ -791,7 +792,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(); /*