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 1fBWL5-0003EM-Jy for speck@linutronix.de; Thu, 26 Apr 2018 04:08:52 +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 w3Q26Ggj168100 for ; Thu, 26 Apr 2018 02:08:45 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2hfw9ah47p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 26 Apr 2018 02:08:44 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w3Q28hiW001558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 26 Apr 2018 02:08:43 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w3Q28hB6009592 for ; Thu, 26 Apr 2018 02:08:43 GMT Message-Id: <20180426020546.338350662@localhost.localdomain> Date: Wed, 25 Apr 2018 22:04:24 -0400 From: konrad.wilk@oracle.com Subject: [MODERATED] [PATCH v5 09/11] [PATCH v5 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 Speculative Store Bypass mitigation to be enabled. 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. xSuggested-by: Borislav Petkov Signed-off-by: Konrad Rzeszutek Wilk --- v2: New patch v3: Use the right CPU features Move the whole logic in early_init_amd and init_amd v5: Set X86_FEATURE_RDS on Fam16->17h Change title to have 'bugs' in it. --- arch/x86/kernel/cpu/amd.c | 16 ++++++++++++++++ arch/x86/kernel/cpu/bugs.c | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index f0e6456ca7d3..d9ce037fdefd 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 @@ -673,6 +674,9 @@ static void early_init_amd(struct cpuinfo_x86 *c) set_cpu_bug(c, X86_BUG_AMD_E400); early_detect_mem_encrypt(c); + + if (c->x86 >= 0x15 && c->x86 <= 0x17) + set_cpu_cap(c, X86_FEATURE_RDS); } static void init_amd_k8(struct cpuinfo_x86 *c) @@ -787,6 +791,8 @@ static void init_amd_bd(struct cpuinfo_x86 *c) wrmsrl_safe(MSR_F15H_IC_CFG, value); } } + if (cpu_has(c, X86_FEATURE_SPEC_STORE_BYPASS_DISABLE)) + msr_set_bit(MSR_AMD64_LS_CFG, 54); } static void init_amd_zn(struct cpuinfo_x86 *c) @@ -797,6 +803,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 (cpu_has(c, X86_FEATURE_SPEC_STORE_BYPASS_DISABLE)) + msr_set_bit(MSR_AMD64_LS_CFG, 10); +} + +static void init_amd_jg(struct cpuinfo_x86 *c) +{ + if (cpu_has(c, X86_FEATURE_SPEC_STORE_BYPASS_DISABLE)) + msr_set_bit(MSR_AMD64_LS_CFG, 33); } static void init_amd(struct cpuinfo_x86 *c) @@ -827,6 +842,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; } diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 7c704bc36968..289eefd6c67e 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -412,7 +412,7 @@ static enum ssb_mitigation_cmd __init ssb_parse_cmdline(void) /* * On Intel it is exposed in CPUID as Reduced Data Speculation - * bit. + * bit. On AMD it is via an MSR, but only on certain families. */ if (!boot_cpu_has(X86_FEATURE_RDS)) return SPEC_STORE_BYPASS_CMD_NONE; @@ -454,6 +454,11 @@ static void __init ssb_select_mitigation(void) switch (cmd) { case SPEC_STORE_BYPASS_CMD_AUTO: + /* + * AMD platforms by default don't need SSB mitigation. + */ + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) + break; case SPEC_STORE_BYPASS_CMD_ON: mode = SPEC_STORE_BYPASS_DISABLE; break; @@ -473,7 +478,8 @@ static void __init ssb_select_mitigation(void) if (mode != SPEC_STORE_BYPASS_NONE) { setup_force_cpu_cap(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE); /* - * Intel uses the SPEC CTRL MSR Bit(2) for this. + * Intel uses the SPEC CTRL MSR Bit(2) for this, while AMD uses + * a completely different MSR. */ if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) { x86_spec_ctrl_base |= SPEC_CTRL_RDS; -- 2.14.3