Return-path: Received: from aserp2120.oracle.com ([141.146.126.78]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1f9Lll-0004A6-Ou for speck@linutronix.de; Fri, 20 Apr 2018 04:27:26 +0200 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3K2QCXx158708 for ; Fri, 20 Apr 2018 02:27:19 GMT Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2hdrxnjktv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 20 Apr 2018 02:27:19 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w3K2RImB008952 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 20 Apr 2018 02:27:19 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w3K2RIIm019158 for ; Fri, 20 Apr 2018 02:27:18 GMT Message-Id: <20180420022613.409383282@localhost.localdomain> Date: Thu, 19 Apr 2018 22:25:49 -0400 From: konrad.wilk@oracle.com Subject: [MODERATED] [patch 09/11] [PATCH v2 09/10] Linux Patch #9 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: AMD does not need the memory disambiguation to be disabled. But the parameters for this are already available and can be done via MSR C001_1020. Each family uses a different bit in that MSR for this. XXX-Suggested-by: Borislav Petkov Signed-off-by: Konrad Rzeszutek Wilk --- v2: New patch --- arch/x86/kernel/cpu/amd.c | 42 ++++++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/bugs.c | 11 +++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index f0e6456ca7d3..e207eb2e8011 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,8 @@ static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum); */ static u32 nodes_per_socket = 1; +static unsigned long long msr_MSR_AMD64_LS_CFG_val; + static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p) { u32 gprs[8] = { 0 }; @@ -787,6 +790,8 @@ static void init_amd_bd(struct cpuinfo_x86 *c) wrmsrl_safe(MSR_F15H_IC_CFG, value); } } + if (!rdmsrl_safe(MSR_AMD64_LS_CFG, &msr_MSR_AMD64_LS_CFG_val)) + set_cpu_cap(c, X86_FEATURE_MDD); } static void init_amd_zn(struct cpuinfo_x86 *c) @@ -797,6 +802,15 @@ static void init_amd_zn(struct cpuinfo_x86 *c) */ if (c->x86_model <= 1 && c->x86_stepping <= 1) set_cpu_cap(c, X86_FEATURE_CPB); + + if (!rdmsrl_safe(MSR_AMD64_LS_CFG, &msr_MSR_AMD64_LS_CFG_val)) + set_cpu_cap(c, X86_FEATURE_MDD); +} + +static void init_amd_jg(struct cpuinfo_x86 *c) +{ + if (!rdmsrl_safe(MSR_AMD64_LS_CFG, &msr_MSR_AMD64_LS_CFG_val)) + set_cpu_cap(c, X86_FEATURE_MDD); } static void init_amd(struct cpuinfo_x86 *c) @@ -827,6 +841,7 @@ static void init_amd(struct cpuinfo_x86 *c) case 0x10: init_amd_gh(c); break; case 0x12: init_amd_ln(c); break; case 0x15: init_amd_bd(c); break; + case 0x16: init_amd_jg(c); break; case 0x17: init_amd_zn(c); break; } @@ -900,6 +915,32 @@ static void init_amd(struct cpuinfo_x86 *c) set_cpu_bug(c, X86_BUG_SYSRET_SS_ATTRS); } +static void amd_fix_cpu(struct cpuinfo_x86 *c) +{ + unsigned int bit; + unsigned long long val; + + if (!ssb_mitigation_needed()) + return; + + switch (c->x86) { + case 0x15: bit = 54; break; + case 0x16: bit = 33; break; + case 0x17: bit = 10; break; + default: + goto out; + } + + val = (msr_MSR_AMD64_LS_CFG_val | (1 << bit)); + wrmsrl(MSR_AMD64_LS_CFG, val); + rdmsrl(MSR_AMD64_LS_CFG, val); + if (val & (1 << bit)) + return; + +out: + pr_warn("Unable to disable memory disambiguation on Fam%xh\n", c->x86); +} + #ifdef CONFIG_X86_32 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size) { @@ -988,6 +1029,7 @@ static const struct cpu_dev amd_cpu_dev = { .c_detect_tlb = cpu_detect_tlb_amd, .c_bsp_init = bsp_init_amd, .c_init = init_amd, + .c_bug_fix = amd_fix_cpu, .c_x86_vendor = X86_VENDOR_AMD, }; diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index fbd39d90a0fc..2e7fbe1d8bfc 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -386,7 +386,7 @@ static enum ssb_mitigation_cmd __init ssb_parse_cmdline(void) /* * On Intel it is exposed in CPUID as Memory Disambiguation Disable - * bit. + * bit. On AMD it is via an MSR, but only certain families. */ if (!boot_cpu_has(X86_FEATURE_MDD)) return SSB_CMD_NONE; @@ -424,11 +424,18 @@ static void __init ssb_select_mitigation(void) enum ssb_mitigation mode = SSB_NONE; if (!boot_cpu_has_bug(X86_BUG_CPU_SSB) && - (cmd == SSB_CMD_NONE || cmd == SSB_CMD_AUTO)) + (cmd == SSB_CMD_NONE || cmd == SSB_CMD_AUTO)) { + setup_clear_cpu_cap(X86_FEATURE_MDD); return; + } switch (cmd) { case SSB_CMD_AUTO: + /* + * AMD platforms by default don't need SSB mitigation. + */ + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) + break; case SSB_CMD_ON: mode = SSB_DISABLE; break; -- 2.14.3