From patchwork Wed Apr 26 17:41:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Battersby X-Patchwork-Id: 87928 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp417080vqo; Wed, 26 Apr 2023 10:59:45 -0700 (PDT) X-Google-Smtp-Source: AKy350aELTiaqP/9SXIcMa2N+2r/nF2xU2GvVswuFthd67GM7osjUtiwO/BtmEaNGC0SnJJMhHoY X-Received: by 2002:a05:6a20:3948:b0:f3:57b2:79e2 with SMTP id r8-20020a056a20394800b000f357b279e2mr17988920pzg.12.1682531985518; Wed, 26 Apr 2023 10:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682531985; cv=none; d=google.com; s=arc-20160816; b=ClEBmasHrfdeAYQsgy3a50xLt5/t7ooHaHJL+KoQZi625H/ZxRcSi3D3N2Y7BNI8MY irnz9XiBxST62PFlYYobZVJ11PhFCMxOYyBWszVtcwM5HP3v6HopPMhGeIWh5Rp39E3t IL5DLVCj5vnQU9A/y3P+StH9/uGa/fXUbMMGeureK75QgLWCIWYqoEL+vCbrIZlwB8bC WLeZNW5Cr6x5YsSy4WPR/mfnIw/Q5HPyTzTgvowlH/9/SapzLypLQWfppm6RLUENJxU7 +TIUR/WYR1VbZTAZ9O5wttfguXgteVTYJTkqIg15AlvKNwzSG2EXatvNjUHjR1vIU+EN 15EQ== 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=MoGhA43xzvvZ8t2pH9I2y5/awsGm9F2RnX1GrXJNuEU=; b=SaQgC/irrcuCYc6pVjel6sguYDbFmSGyMmFsy1HnALLeKiZf2juGA70/RxuRCDG0JR LqTaT42Vuqjyxb3ZcNLIHx4QzfZBItBuIHwx2J2+6U6R/1GXD2FzUtia7EdQ3qs2wEh1 tkrO4UKxqrj7lEAHrVblRQf8CXfXMe3YTSODgSmoX0z99IjsheR2C2T0W0h3LYNQtKF8 lHyvOKbvdjzzf8CQd9pctoJ2dq56FuunqIJAJoAhwB69qHraDPgs8j834UiWgahpikWC iIGqMWmvZmgQTzgmGVxja6qL+DUMh3Hx1WzEF9pBjSJoUWorPxx0rFcpy+xI4guc0Dgt mKOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b="oLeM/Elw"; 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 a63-20020a639042000000b0051f8b655e04si16879464pge.505.2023.04.26.10.59.33; Wed, 26 Apr 2023 10:59:45 -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="oLeM/Elw"; 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 S236122AbjDZRlh (ORCPT + 99 others); Wed, 26 Apr 2023 13:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234679AbjDZRlg (ORCPT ); Wed, 26 Apr 2023 13:41:36 -0400 X-Greylist: delayed 219 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 26 Apr 2023 10:41:34 PDT Received: from mail.cybernetics.com (mail.cybernetics.com [72.215.153.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B06AF10C for ; Wed, 26 Apr 2023 10:41:34 -0700 (PDT) X-ASG-Debug-ID: 1682530892-1cf4391215320530001-xx1T2L Received: from cybernetics.com ([10.10.4.126]) by mail.cybernetics.com with ESMTP id dsNGcVgsbSHQHQZD; Wed, 26 Apr 2023 13:41:32 -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=MoGhA43xzvvZ8t2pH9I2y5/awsGm9F2RnX1GrXJNuEU=; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Cc:To:From: Content-Language:Subject:MIME-Version:Date:Message-ID; b=oLeM/ElwziYQWjsUDZZ3 LYmoa3ncBhpfAPF/JpY7sj5FNjOvNEo/4nmPQZYI3oVltpvarxlDSZXYLqIqrKLgUW+HF9eg2xoGP PDslMvd9eTbxMNgzp9VHdYZH2H/c0BkfmcU1L1+gQtpgO0KorASHBwdjMF4UbSbxkoB7mZDa+M= Received: from [10.157.2.224] (HELO [192.168.200.1]) by cybernetics.com (CommuniGate Pro SMTP 7.1.1) with ESMTPS id 12591946; Wed, 26 Apr 2023 13:41:32 -0400 Message-ID: <90428c6d-97f6-794f-8cfd-5b30dd5ed140@cybernetics.com> Date: Wed, 26 Apr 2023 13:41:32 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: [PATCH v2] x86/cpu: fix SME test in stop_this_cpu() Content-Language: en-US X-ASG-Orig-Subj: [PATCH v2] 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> In-Reply-To: X-Barracuda-Connect: UNKNOWN[10.10.4.126] X-Barracuda-Start-Time: 1682530892 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: 1719 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?1764262659158412921?= X-GMAIL-MSGID: =?utf-8?q?1764262659158412921?= 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(-) 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 (;;) { /*