From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.linutronix.de (193.142.43.55:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 05 Oct 2019 06:41:15 -0000 Received: from mga17.intel.com ([192.55.52.151]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iGdkg-00082s-8R for speck@linutronix.de; Sat, 05 Oct 2019 08:41:14 +0200 Date: Fri, 4 Oct 2019 23:35:31 -0700 From: Pawan Gupta Subject: [MODERATED] [PATCH v5 10/11] TAAv5 10 Message-ID: =?utf-8?q?=3C1cc0c83e8b6ea5fbdea88474c6fe491c7e4272c0=2E157025?= =?utf-8?q?5065=2Egit=2Epawan=2Ekumar=2Egupta=40linux=2Eintel=2Ecom=3E?= References: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: When the TSX state is changed from the sysfs interface, TSX Async Abort (TAA) mitigation state also needs to be updated. Set the TAA mitigation state as per TSX and VERW static branch state. Signed-off-by: Pawan Gupta Reviewed-by: Mark Gross Reviewed-by: Tony Luck Tested-by: Neelima Krishnan --- arch/x86/kernel/cpu/bugs.c | 21 ++++++++++++++++++++- arch/x86/kernel/cpu/cpu.h | 2 ++ arch/x86/kernel/cpu/tsx.c | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index b9b122b5bcae..8144f3bcc831 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -274,7 +274,7 @@ early_param("mds", mds_cmdline); #define pr_fmt(fmt) "TAA: " fmt /* Default mitigation for TAA-affected CPUs */ -static enum taa_mitigations taa_mitigation __ro_after_init = TAA_MITIGATION_VERW; +static enum taa_mitigations taa_mitigation = TAA_MITIGATION_VERW; static bool taa_nosmt __ro_after_init; static const char * const taa_strings[] = { @@ -374,6 +374,25 @@ static int __init tsx_async_abort_cmdline(char *str) } early_param("tsx_async_abort", tsx_async_abort_cmdline); +void taa_update_mitigation(bool tsx_enabled) +{ + /* + * When userspace changes the TSX state, update taa_mitigation + * so that the updated mitigation state is shown in: + * /sys/devices/system/cpu/vulnerabilities/tsx_async_abort + * + * Check if TSX is disabled. + * Check if CPU buffer clear is enabled. + * else the system is vulnerable. + */ + if (!tsx_enabled) + taa_mitigation = TAA_MITIGATION_TSX_DISABLE; + else if (static_key_count(&mds_user_clear.key)) + taa_mitigation = TAA_MITIGATION_VERW; + else + taa_mitigation = TAA_MITIGATION_OFF; +} + #undef pr_fmt #define pr_fmt(fmt) "Spectre V1 : " fmt diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h index d864ec4180cc..da2579edbb86 100644 --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -64,6 +64,8 @@ extern void x86_spec_ctrl_setup_ap(void); extern void tsx_init(struct cpuinfo_x86 *c); +extern void taa_update_mitigation(bool tsx_enabled); + extern u64 read_ia32_arch_cap(void); #endif /* ARCH_X86_CPU_H */ diff --git a/arch/x86/kernel/cpu/tsx.c b/arch/x86/kernel/cpu/tsx.c index 2cea038fdcba..44b973fd41f4 100644 --- a/arch/x86/kernel/cpu/tsx.c +++ b/arch/x86/kernel/cpu/tsx.c @@ -240,6 +240,9 @@ ssize_t hw_tx_mem_store(struct device *dev, struct device_attribute *attr, * will continue to run in non-TSX mode. */ tsx_update_on_each_cpu(val); + + if (boot_cpu_has_bug(X86_BUG_TAA)) + taa_update_mitigation(val); exit: mutex_unlock(&tsx_mutex); -- 2.20.1