[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] x86/amd: split LFENCE dispatch serializing setup logic into helper


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Wed, 14 Apr 2021 13:04:32 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XHgQn41rDI5whB93Ym85E1U2wOPzHicCd0BkH1NVL9I=; b=RmmaUeI90iX9HQYUvchCry531vN+ktCo1wQ3aY30gH0TqNGDhVassjtQnJ44Hz5KYTcvFYTc41wUmfrfWlwkkzYUvdup/KDYf1zlkKXhrI7leFtiyBxfKPtJX94yZLBJhKGfa7TE8+AvkDpmS300RT8wf3Q9f049RNnQyg+gT+qi1KRPKQ79LY6ihw//L5c/PakTE2n3JCn9psUQoZ/oVkm3VIN7M/dPK4lMlDJVbuWQT1VejANil1j4FK1Xo8JW+tR4cDFGyQPMjs1vjXpmwwR4qoUs4tObYnQ20OXzvPC894EVMHe8+zgqHsIsdbh2p3biXrxo/52LaIvrOblyAQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ByKilPfKc1aWHxulc+pIAFbdkIBkPhYGSmwkvedYmi7wMEWnQGI/6IYmndjTBq4yQeQIprEIELqugvDk3j+LilNDeF10fqyVR0IvITypo+yjH1NtF+2RZ1PclU9SiqnjtYnmrPYb5pxu/7qZbMSGRfAPdBR+OVF2cRYMdkDGSu5u3mTkOeamAUq5mtIaqqTti1ckllpTwM+h73bRaI/JXEwkLKfktkEwspydj5OvsxV9YwNWgAKI4JPhMcf2Uw4oKOUGC50hGv0CmDAJ9GPB+PsDJw/fjUAp6X78Mh+Yax9Li3+yhs/P1wZN93Qrh27sPnJZsRVVczguel6NFlel5g==
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Wed, 14 Apr 2021 11:05:35 +0000
  • Ironport-hdrordr: A9a23:0XFYFqCdMQN2w8XlHegptMeALOonbusQ8zAX/mhLY1h8btGYm8 eynP4SyB/zj3IrVGs9nM2bUZPufVr1zrQwxYUKJ7+tUE3duGWuJJx/9oeK+VHdMgXE3Kpm2a 9kGpISNPTZEUV6gcHm4AOxDtYnx529/Lq1gPrFpk0NcShBQchbnmNEIyycFVB7QxQDOIEwE4 CS6tECiz2rf3kWacrTPAh4Y8HoodrXmJX6JSMXHhJP0njysRqEyp7fVyKZ0BAXTi9Vzd4Zn1 TtvgTl6syYwpeG4zDG0Wu71eU1pPLAzZ95CNWImowpLFzX+32VTaBAf5HHgzwvuuGo7z8R4a nxijMtJd565X+UXkzdm2qV5yDa3Dwj62DvxDaj6BOJy6yJJ0NJN+N7iY1UaRff4UY71esMqp 5j5G6Fq4FRSSrJgSWV3am4azhRikG2rXA++NRj6EB3bI12Us41kaUvuGlREJsGARvg7pEmHO REHKjnlYhrWGLfQHbDsmZ1xtuwGlw1AxedW0AH/veYyj5MgRlCvgcl7f1auk1F2IM2SpFC6e iBGqN0lItWRstTSa5mHu8OTea+F2Sle2OCDEuiZXDcUI0XMXPErJD6pJ8v4vuxRZAOxJwu3L zcTVJxrwcJCgLTIPzL+KcO3gHGQW27Uzio4NpZ/YJFtrr1Q6euGTGfSWopj9Crr5wkc4zmcs f2HKgTL+7oLGPoF4oM9Rb5QYNuJX4XV9BQlc08X36Iv8LXOqznvuHWa5/oVfjQOAdh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3OrBTM6ESlazM8RkF9lQVZNUrCpT uio/f6hUIihM/Oe1dHvuiRMbYenTJA2zEZvg6tnu0tinlRsy1HaKo5SJYJUMyDrdK2dwKP50E1 Jhx04128J427iOnEOywI5x9WqrbVvXytStoueZ1M5q4kymSOR7/CB2WTZxZeMZU6qF65r+kW0U CTk=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Split the logic to attempt to setup the 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@xxxxxxxxxx>
---
 xen/arch/x86/cpu/amd.c   | 62 ++++++++++++++++++++++------------------
 xen/arch/x86/cpu/cpu.h   |  1 +
 xen/arch/x86/cpu/hygon.c | 27 +----------------
 3 files changed, 36 insertions(+), 54 deletions(-)

diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index 8bc51bec10d..9c8dcd91eef 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -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);
+}
+
 static void init_amd(struct cpuinfo_x86 *c)
 {
        u32 l, h;
@@ -686,37 +718,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);
 
        /*
         * If the user has explicitly chosen to disable Memory Disambiguation
diff --git a/xen/arch/x86/cpu/cpu.h b/xen/arch/x86/cpu/cpu.h
index 1992596d1b2..1ac3b2867a0 100644
--- a/xen/arch/x86/cpu/cpu.h
+++ b/xen/arch/x86/cpu/cpu.h
@@ -20,3 +20,4 @@ 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);
diff --git a/xen/arch/x86/cpu/hygon.c b/xen/arch/x86/cpu/hygon.c
index 46293f1f367..2272e1113f1 100644
--- a/xen/arch/x86/cpu/hygon.c
+++ b/xen/arch/x86/cpu/hygon.c
@@ -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);
 
        /*
         * If the user has explicitly chosen to disable Memory Disambiguation
-- 
2.30.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.