Linux Patch #9
Subsystems (2)
PATCH v2 9/10 Linux Patch #9
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.
---
v2: New patch
--- arch/x86/kernel/cpu/amd.c | 42 ++++++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/bugs.c | 11 +++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/amd.c +42 -0
@@ -10,6 +10,7 @@#include <asm/processor.h> #include <asm/apic.h> #include <asm/cpu.h> +#include <asm/nospec-branch.h> #include <asm/smp.h> #include <asm/pci-direct.h> #include <asm/delay.h>
@@ -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, };
arch/x86/kernel/cpu/bugs.c +9 -2
@@ -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 ;
Signature · 1 line
2.14.3
Quoted 38 lines · speck for konrad.wilk_at_oracle.com
x86/ssb/AMD: Add support to disable MD on Fam[15,16,17]h.
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 <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>---
v2: New patch--- arch/x86/kernel/cpu/amd.c | 42 ++++++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/bugs.c | 11 +++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/amd.c +3
-0@@ -10,6 +10,7 @@#include <asm/processor.h> #include <asm/apic.h> #include <asm/cpu.h> +#include <asm/nospec-branch.h> #include <asm/smp.h> #include <asm/pci-direct.h> #include <asm/delay.h> @@ -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 };
arch/x86/kernel/cpu/amd.c static void init_amd_bd(struct cpuinfo_x86 *c) · line 794
Quoted 5 lines
arch/x86/kernel/cpu/amd.c +2
-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 );
This is not needed since you'll be setting X86_FEATURE_MDD in the early function early_init_amd() now.
The only thing you need to do then in those functions is:
if (cpu_has(c, X86_FEATURE_USE_MDD))
msr_set_bit(MSR_AMD64_LS_CFG, 54);with the respective bits used in each function.
And then drop that ad-hoc ssb_mitigation_needed() thing.
Signature · 5 lines
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
--