aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Lendacky <thomas.lendacky@amd.com>2018-01-08 17:09:21 -0500
committerThomas Gleixner <tglx@linutronix.de>2018-01-08 19:43:10 -0500
commite4d0e84e490790798691aaa0f2e598637f1867ec (patch)
tree66d52c2120951105b4b688a8615a56f89551e4bf
parent8d56eff266f3e41a6c39926269c4c3f58f881a8e (diff)
x86/cpu/AMD: Make LFENCE a serializing instruction
To aid in speculation control, make LFENCE a serializing instruction since it has less overhead than MFENCE. This is done by setting bit 1 of MSR 0xc0011029 (DE_CFG). Some families that support LFENCE do not have this MSR. For these families, the LFENCE instruction is already serializing. Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Reviewed-by: Borislav Petkov <bp@suse.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tim Chen <tim.c.chen@linux.intel.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Greg Kroah-Hartman <gregkh@linux-foundation.org> Cc: David Woodhouse <dwmw@amazon.co.uk> Cc: Paul Turner <pjt@google.com> Link: https://lkml.kernel.org/r/20180108220921.12580.71694.stgit@tlendack-t1.amdoffice.net
-rw-r--r--arch/x86/include/asm/msr-index.h2
-rw-r--r--arch/x86/kernel/cpu/amd.c10
2 files changed, 12 insertions, 0 deletions
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index ab022618a50a..1e7d710fef43 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -352,6 +352,8 @@
352#define FAM10H_MMIO_CONF_BASE_MASK 0xfffffffULL 352#define FAM10H_MMIO_CONF_BASE_MASK 0xfffffffULL
353#define FAM10H_MMIO_CONF_BASE_SHIFT 20 353#define FAM10H_MMIO_CONF_BASE_SHIFT 20
354#define MSR_FAM10H_NODE_ID 0xc001100c 354#define MSR_FAM10H_NODE_ID 0xc001100c
355#define MSR_F10H_DECFG 0xc0011029
356#define MSR_F10H_DECFG_LFENCE_SERIALIZE_BIT 1
355 357
356/* K8 MSRs */ 358/* K8 MSRs */
357#define MSR_K8_TOP_MEM1 0xc001001a 359#define MSR_K8_TOP_MEM1 0xc001001a
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index bcb75dc97d44..5b438d81beb2 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -829,6 +829,16 @@ static void init_amd(struct cpuinfo_x86 *c)
829 set_cpu_cap(c, X86_FEATURE_K8); 829 set_cpu_cap(c, X86_FEATURE_K8);
830 830
831 if (cpu_has(c, X86_FEATURE_XMM2)) { 831 if (cpu_has(c, X86_FEATURE_XMM2)) {
832 /*
833 * A serializing LFENCE has less overhead than MFENCE, so
834 * use it for execution serialization. On families which
835 * don't have that MSR, LFENCE is already serializing.
836 * msr_set_bit() uses the safe accessors, too, even if the MSR
837 * is not present.
838 */
839 msr_set_bit(MSR_F10H_DECFG,
840 MSR_F10H_DECFG_LFENCE_SERIALIZE_BIT);
841
832 /* MFENCE stops RDTSC speculation */ 842 /* MFENCE stops RDTSC speculation */
833 set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC); 843 set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
834 } 844 }