]> xenbits.xensource.com Git - xen.git/commitdiff
x86/amd: split LFENCE dispatch serializing setup logic into helper
authorRoger Pau Monné <roger.pau@citrix.com>
Thu, 15 Apr 2021 11:45:09 +0000 (13:45 +0200)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 4 Feb 2022 16:29:39 +0000 (16:29 +0000)
Split the logic to attempt to setup LFENCE to be dispatch serializing
on AMD into a helper, so it can be shared with Hygon.

No functional change intended.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
(cherry picked from commit 3e9460ec93341fa6a80ecf99832aa5d9975339c9)

xen/arch/x86/cpu/amd.c
xen/arch/x86/cpu/cpu.h
xen/arch/x86/cpu/hygon.c

index c780397f18d45bd6d8ea37cb3859a54957302900..d33b7cf999bd7227dfdd3577e1250e74f71aff6a 100644 (file)
@@ -642,6 +642,38 @@ void early_init_amd(struct cpuinfo_x86 *c)
        ctxt_switch_levelling(NULL);
 }
 
+void amd_init_lfence(struct cpuinfo_x86 *c)
+{
+       uint64_t value;
+
+       /*
+        * Attempt to set lfence to be Dispatch Serialising.  This MSR almost
+        * certainly isn't virtualised (and Xen at least will leak the real
+        * value in but silently discard writes), as well as being per-core
+        * rather than per-thread, so do a full safe read/write/readback cycle
+        * in the worst case.
+        */
+       if (rdmsr_safe(MSR_AMD64_DE_CFG, value))
+               /* Unable to read.  Assume the safer default. */
+               __clear_bit(X86_FEATURE_LFENCE_DISPATCH,
+                           c->x86_capability);
+       else if (value & AMD64_DE_CFG_LFENCE_SERIALISE)
+               /* Already dispatch serialising. */
+               __set_bit(X86_FEATURE_LFENCE_DISPATCH,
+                         c->x86_capability);
+       else if (wrmsr_safe(MSR_AMD64_DE_CFG,
+                           value | AMD64_DE_CFG_LFENCE_SERIALISE) ||
+                rdmsr_safe(MSR_AMD64_DE_CFG, value) ||
+                !(value & AMD64_DE_CFG_LFENCE_SERIALISE))
+               /* Attempt to set failed.  Assume the safer default. */
+               __clear_bit(X86_FEATURE_LFENCE_DISPATCH,
+                           c->x86_capability);
+       else
+               /* Successfully enabled! */
+               __set_bit(X86_FEATURE_LFENCE_DISPATCH,
+                         c->x86_capability);
+}
+
 /*
  * Refer to the AMD Speculative Store Bypass whitepaper:
  * https://developer.amd.com/wp-content/resources/124441_AMD64_SpeculativeStoreBypassDisable_Whitepaper_final.pdf
@@ -736,37 +768,11 @@ static void init_amd(struct cpuinfo_x86 *c)
        if (c == &boot_cpu_data && !cpu_has(c, X86_FEATURE_RSTR_FP_ERR_PTRS))
                setup_force_cpu_cap(X86_BUG_FPU_PTRS);
 
-       /*
-        * Attempt to set lfence to be Dispatch Serialising.  This MSR almost
-        * certainly isn't virtualised (and Xen at least will leak the real
-        * value in but silently discard writes), as well as being per-core
-        * rather than per-thread, so do a full safe read/write/readback cycle
-        * in the worst case.
-        */
        if (c->x86 == 0x0f || c->x86 == 0x11)
                /* Always dispatch serialising on this hardare. */
                __set_bit(X86_FEATURE_LFENCE_DISPATCH, c->x86_capability);
-       else /* Implicily "== 0x10 || >= 0x12" by being 64bit. */ {
-               if (rdmsr_safe(MSR_AMD64_DE_CFG, value))
-                       /* Unable to read.  Assume the safer default. */
-                       __clear_bit(X86_FEATURE_LFENCE_DISPATCH,
-                                   c->x86_capability);
-               else if (value & AMD64_DE_CFG_LFENCE_SERIALISE)
-                       /* Already dispatch serialising. */
-                       __set_bit(X86_FEATURE_LFENCE_DISPATCH,
-                                 c->x86_capability);
-               else if (wrmsr_safe(MSR_AMD64_DE_CFG,
-                                   value | AMD64_DE_CFG_LFENCE_SERIALISE) ||
-                        rdmsr_safe(MSR_AMD64_DE_CFG, value) ||
-                        !(value & AMD64_DE_CFG_LFENCE_SERIALISE))
-                       /* Attempt to set failed.  Assume the safer default. */
-                       __clear_bit(X86_FEATURE_LFENCE_DISPATCH,
-                                   c->x86_capability);
-               else
-                       /* Successfully enabled! */
-                       __set_bit(X86_FEATURE_LFENCE_DISPATCH,
-                                 c->x86_capability);
-       }
+       else /* Implicily "== 0x10 || >= 0x12" by being 64bit. */
+               amd_init_lfence(c);
 
        amd_init_ssbd(c);
 
index 255095780139130e4dc7aa72f7c79ad7871b8a04..1a5b3918b37e35be2e8d9c3ba7656876c19dabd1 100644 (file)
@@ -20,4 +20,5 @@ extern bool detect_extended_topology(struct cpuinfo_x86 *c);
 
 void early_init_amd(struct cpuinfo_x86 *c);
 void amd_log_freq(const struct cpuinfo_x86 *c);
+void amd_init_lfence(struct cpuinfo_x86 *c);
 void amd_init_ssbd(const struct cpuinfo_x86 *c);
index ccfa27201d3b18827379c3f98d9b99007bd8bc72..3845e0cf0e89ea9437a5054fba5ab08312044179 100644 (file)
@@ -32,32 +32,7 @@ static void init_hygon(struct cpuinfo_x86 *c)
 {
        unsigned long long value;
 
-       /*
-        * Attempt to set lfence to be Dispatch Serialising.  This MSR almost
-        * certainly isn't virtualised (and Xen at least will leak the real
-        * value in but silently discard writes), as well as being per-core
-        * rather than per-thread, so do a full safe read/write/readback cycle
-        * in the worst case.
-        */
-       if (rdmsr_safe(MSR_AMD64_DE_CFG, value))
-               /* Unable to read.  Assume the safer default. */
-               __clear_bit(X86_FEATURE_LFENCE_DISPATCH,
-                           c->x86_capability);
-       else if (value & AMD64_DE_CFG_LFENCE_SERIALISE)
-               /* Already dispatch serialising. */
-               __set_bit(X86_FEATURE_LFENCE_DISPATCH,
-                         c->x86_capability);
-       else if (wrmsr_safe(MSR_AMD64_DE_CFG,
-                           value | AMD64_DE_CFG_LFENCE_SERIALISE) ||
-                rdmsr_safe(MSR_AMD64_DE_CFG, value) ||
-                !(value & AMD64_DE_CFG_LFENCE_SERIALISE))
-               /* Attempt to set failed.  Assume the safer default. */
-               __clear_bit(X86_FEATURE_LFENCE_DISPATCH,
-                           c->x86_capability);
-       else
-               /* Successfully enabled! */
-               __set_bit(X86_FEATURE_LFENCE_DISPATCH,
-                         c->x86_capability);
+       amd_init_lfence(c);
 
        amd_init_ssbd(c);