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 1fBqp8-00061V-3X for speck@linutronix.de; Fri, 27 Apr 2018 02:01:14 +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 w3QNwZ9Z088448 for ; Fri, 27 Apr 2018 00:01:07 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2hfw9anb7p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 27 Apr 2018 00:01:07 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w3R0148v027614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 27 Apr 2018 00:01:06 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w3R013PE002994 for ; Fri, 27 Apr 2018 00:01:03 GMT Message-Id: <20180426234831.676221339@localhost.localdomain> Date: Thu, 26 Apr 2018 19:48:29 -0400 From: konrad.wilk@oracle.com Subject: [MODERATED] [PATCH v6 09/11] [PATCH v6 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. xReviewed-by: Borislav Petkov 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. v6: Added Reviewed-by --- 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 12bc0a1139da..6d6a03aa1870 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 e7338b04770f..191293e18676 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -411,7 +411,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; @@ -453,6 +453,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; @@ -472,7 +477,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