From patchwork Mon Nov 21 13:07:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 23730 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1575741wrr; Mon, 21 Nov 2022 05:09:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf7VepywjB21EJluJJ6cfgHxzsYo3bNGnBCI7O0SH2RlctU0VkZW8C1oPWtEkfTWNu00upNQ X-Received: by 2002:a63:1760:0:b0:470:580a:c8a with SMTP id 32-20020a631760000000b00470580a0c8amr3571966pgx.505.1669036152353; Mon, 21 Nov 2022 05:09:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669036152; cv=none; d=google.com; s=arc-20160816; b=HGHU00UV6pAgvyhjWiam5FVW1sQRs1OUPza7sKUoPaJARfB1GxikoiSnDXyAUc+wo8 HDkLw7Td6KdrwwFby6p7J0ftxIszaQNYkJ1nYKWG20cWVHMXoqPV0zlj0YOM156V8pxu 97CEmxArsWBG4ni4kmrMmcyzOF54lc+gWQdVIPMn+cPjyeBUJKKAuKa4qOkTlupJrThT I34fQYuTYd5lnu9i+uif/hbOTzhLziKkejTKUKlu++bek8NCV016GBJ64cwWWe/xmjAp XWL0rm99TqbNAtmrwCiKxMvUErBx+gTBw5i7tztrX2pWy9ExlHFAGvOE8ibay4IPMWul /c+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=gkuy0zpIpPKJxWmDZ1hGuiceR642WQkScrvqMi95xNY=; b=GFecqAQdnqOwDbfpfFgM+vjuPPSSn7luGLg/ij/RGwrQjVRw0N9bDPlo9Hf5wkUAZo NUfRB0uSgFoKtqYReZi5TwQDj0qyGYKcRRzGVgDelN5dn+0Fj2XCZEOZRj2CdDJsF0tI t7RKXr8dBjTys4DROQiad1DBtppVrG7lHcByETmNmJm49eEkHBXDUoILlOdpq8C30vGD 50zR8nYiM+MIU/K8kJChgMl29u+MmhdsQx5Ll6b11UCNEwi7KeKMETd31CeXPtuS38No CMvY4vozKBOGWpCxPS7FOk6lO2PEm+eZ1741eHUr+cc2IaBo4s0oHHmKKO6lXgTkHRpt GWXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2U+8bV3O; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rcwZpLRQ; 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 gi9-20020a17090b110900b002186fd880a9si9849013pjb.169.2022.11.21.05.08.51; Mon, 21 Nov 2022 05:09:12 -0800 (PST) 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=2U+8bV3O; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rcwZpLRQ; 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 S229460AbiKUNIJ (ORCPT + 99 others); Mon, 21 Nov 2022 08:08:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbiKUNIE (ORCPT ); Mon, 21 Nov 2022 08:08:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76A78B960E; Mon, 21 Nov 2022 05:07:59 -0800 (PST) Date: Mon, 21 Nov 2022 13:07:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669036077; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gkuy0zpIpPKJxWmDZ1hGuiceR642WQkScrvqMi95xNY=; b=2U+8bV3On8mrrtxm2tNhxiVMLNSYy0XuMZiB8/J4/QyJr6uj+oQcsLO0jAZKeqDJUSZJej vkVjRyEeuOB2kz1qhyHuOP5YqOFK4fUrzm+ltqz5GT29tIa1JZ8dS6Nklox+C1A0V1k/9a B6lhIHqylGUevQv2dZwYiEwlqAgg24mfFzx2+h+yvwsWegm40mSTtCLDVY3CnFOeWS+FOU 7H+j5rLvwNiySSCIZzX/BT40fCaCMLHxxRcPSZR4BJ4uVQTFjFBwcmIuSODx1T3UDle1E1 OLb1vZmXagHhRkd+i5wv6TCahTaVGLd7ZdgVl7ias9uWLHo8W7kAV7x02WKQgw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669036077; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gkuy0zpIpPKJxWmDZ1hGuiceR642WQkScrvqMi95xNY=; b=rcwZpLRQNG93oHd7o62drkJ31PF6jNpTCmXj6Yxm/mNgHwCqhG38eLiyDeozXtcFUv9cvS Z0PmMYcmTKN1HGAg== From: "tip-bot2 for Pawan Gupta" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/tsx: Add a feature bit for TSX control MSR support Cc: Andrew Cooper , Pawan Gupta , Borislav Petkov , Dave Hansen , , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3Cde619764e1d98afbb7a5fa58424f1278ede37b45=2E1668539?= =?utf-8?q?735=2Egit=2Epawan=2Ekumar=2Egupta=40linux=2Eintel=2Ecom=3E?= References: =?utf-8?q?=3Cde619764e1d98afbb7a5fa58424f1278ede37b45=2E16685397?= =?utf-8?q?35=2Egit=2Epawan=2Ekumar=2Egupta=40linux=2Eintel=2Ecom=3E?= MIME-Version: 1.0 Message-ID: <166903607648.4906.14811798962789521601.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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 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?1750111252839474181?= X-GMAIL-MSGID: =?utf-8?q?1750111252839474181?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 545a4f150433203cab525cc5816bcfe3500c3611 Gitweb: https://git.kernel.org/tip/545a4f150433203cab525cc5816bcfe3500c3611 Author: Pawan Gupta AuthorDate: Tue, 15 Nov 2022 11:17:05 -08:00 Committer: Borislav Petkov CommitterDate: Mon, 21 Nov 2022 13:13:22 +01:00 x86/tsx: Add a feature bit for TSX control MSR support Support for the TSX control MSR is enumerated in MSR_IA32_ARCH_CAPABILITIES. This is different from how other CPU features are enumerated i.e. via CPUID. Currently, a call to tsx_ctrl_is_supported() is required for enumerating the feature. In the absence of a feature bit for TSX control, any code that relies on checking feature bits directly will not work. In preparation for adding a feature bit check in MSR save/restore during suspend/resume, set a new feature bit X86_FEATURE_TSX_CTRL when MSR_IA32_TSX_CTRL is present. Also make tsx_ctrl_is_supported() use the new feature bit to avoid any overhead of reading the MSR. [ bp: Remove tsx_ctrl_is_supported() ] Suggested-by: Andrew Cooper Signed-off-by: Pawan Gupta Signed-off-by: Borislav Petkov Reviewed-by: Dave Hansen Cc: Link: https://lore.kernel.org/r/de619764e1d98afbb7a5fa58424f1278ede37b45.1668539735.git.pawan.kumar.gupta@linux.intel.com --- arch/x86/include/asm/cpufeatures.h | 1 +- arch/x86/kernel/cpu/tsx.c | 38 ++++++++++++----------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index b71f4f2..3cda06e 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -304,6 +304,7 @@ #define X86_FEATURE_UNRET (11*32+15) /* "" AMD BTB untrain return */ #define X86_FEATURE_USE_IBPB_FW (11*32+16) /* "" Use IBPB during runtime firmware calls */ #define X86_FEATURE_RSB_VMEXIT_LITE (11*32+17) /* "" Fill RSB on VM exit when EIBRS is enabled */ +#define X86_FEATURE_MSR_TSX_CTRL (11*32+18) /* "" MSR IA32_TSX_CTRL (Intel) implemented */ /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */ #define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */ diff --git a/arch/x86/kernel/cpu/tsx.c b/arch/x86/kernel/cpu/tsx.c index ec7bbac..8009c83 100644 --- a/arch/x86/kernel/cpu/tsx.c +++ b/arch/x86/kernel/cpu/tsx.c @@ -58,24 +58,6 @@ static void tsx_enable(void) wrmsrl(MSR_IA32_TSX_CTRL, tsx); } -static bool tsx_ctrl_is_supported(void) -{ - u64 ia32_cap = x86_read_arch_cap_msr(); - - /* - * TSX is controlled via MSR_IA32_TSX_CTRL. However, support for this - * MSR is enumerated by ARCH_CAP_TSX_MSR bit in MSR_IA32_ARCH_CAPABILITIES. - * - * TSX control (aka MSR_IA32_TSX_CTRL) is only available after a - * microcode update on CPUs that have their MSR_IA32_ARCH_CAPABILITIES - * bit MDS_NO=1. CPUs with MDS_NO=0 are not planned to get - * MSR_IA32_TSX_CTRL support even after a microcode update. Thus, - * tsx= cmdline requests will do nothing on CPUs without - * MSR_IA32_TSX_CTRL support. - */ - return !!(ia32_cap & ARCH_CAP_TSX_CTRL_MSR); -} - static enum tsx_ctrl_states x86_get_tsx_auto_mode(void) { if (boot_cpu_has_bug(X86_BUG_TAA)) @@ -135,7 +117,7 @@ static void tsx_clear_cpuid(void) rdmsrl(MSR_TSX_FORCE_ABORT, msr); msr |= MSR_TFA_TSX_CPUID_CLEAR; wrmsrl(MSR_TSX_FORCE_ABORT, msr); - } else if (tsx_ctrl_is_supported()) { + } else if (cpu_feature_enabled(X86_FEATURE_MSR_TSX_CTRL)) { rdmsrl(MSR_IA32_TSX_CTRL, msr); msr |= TSX_CTRL_CPUID_CLEAR; wrmsrl(MSR_IA32_TSX_CTRL, msr); @@ -158,7 +140,8 @@ static void tsx_dev_mode_disable(void) u64 mcu_opt_ctrl; /* Check if RTM_ALLOW exists */ - if (!boot_cpu_has_bug(X86_BUG_TAA) || !tsx_ctrl_is_supported() || + if (!boot_cpu_has_bug(X86_BUG_TAA) || + !cpu_feature_enabled(X86_FEATURE_MSR_TSX_CTRL) || !cpu_feature_enabled(X86_FEATURE_SRBDS_CTRL)) return; @@ -191,7 +174,20 @@ void __init tsx_init(void) return; } - if (!tsx_ctrl_is_supported()) { + /* + * TSX is controlled via MSR_IA32_TSX_CTRL. However, support for this + * MSR is enumerated by ARCH_CAP_TSX_MSR bit in MSR_IA32_ARCH_CAPABILITIES. + * + * TSX control (aka MSR_IA32_TSX_CTRL) is only available after a + * microcode update on CPUs that have their MSR_IA32_ARCH_CAPABILITIES + * bit MDS_NO=1. CPUs with MDS_NO=0 are not planned to get + * MSR_IA32_TSX_CTRL support even after a microcode update. Thus, + * tsx= cmdline requests will do nothing on CPUs without + * MSR_IA32_TSX_CTRL support. + */ + if (x86_read_arch_cap_msr() & ARCH_CAP_TSX_CTRL_MSR) { + setup_force_cpu_cap(X86_FEATURE_MSR_TSX_CTRL); + } else { tsx_ctrl_state = TSX_CTRL_NOT_SUPPORTED; return; }