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

[PATCH v2 2/2] x86/cpuid: Detect null segment behaviour on Zen2 CPUs


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jane Malalane <jane.malalane@xxxxxxxxxx>
  • Date: Wed, 8 Sep 2021 09:19:45 +0100
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Jane Malalane <jane.malalane@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, "Jan Beulich" <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Pu Wen <puwen@xxxxxxxx>, Andy Lutomirski <luto@xxxxxxxxxx>
  • Delivery-date: Wed, 08 Sep 2021 08:20:10 +0000
  • Ironport-hdrordr: A9a23:1J0Cu6wGeGnLjTrmK2RrKrPwFL1zdoMgy1knxilNoRw8SKKlfq eV7Y0mPH7P+VAssR4b+exoVJPtfZqYz+8R3WBzB8bEYOCFghrKEGgK1+KLqFeMJ8S9zJ846U 4JSdkHNDSaNzlHZKjBjzVQa+xQouW6zA==
  • Ironport-sdr: WkLE+G5BwbTYK+RdRMVIg/26UTHktzIcSXsqOe2TAMVOPeO7OuOEUSFZ9nhssQ5V1W0LLfqKcf g5g0mhBoHtPv0t7o4ZJ0vrZPSjdoZm/r2Q6Cfb/hH/9wAP+5jG95P4Bzv56qQHGZWVmeG6dSwt BmIA4A4qvuyBTg5Seysuwazfmw0vp9cKedHis1wQpmvme7S6+4NrgZcrSUlHpS/ttzDdRC75Mp uihwgdioZSmlh9dRWEDIGPwgc+wAflGAqKW2s+DvE7b//UHM53zBcZKeCQ4qn2vd0sS4Dl3wct /X+KJkSAR9hxvw3WxFZ506+o
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Zen2 CPUs actually have this behaviour, but the CPUID bit couldn't be
introduced into Zen2 due to a lack of leaves. So, it was added in a
new leaf in Zen3. Nonetheless, hypervisors can synthesize the CPUID
bit in software.

So, Xen probes for NSCB (NullSelectorClearsBit) and
synthesizes the bit, if the behaviour is present.

Suggested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Signed-off-by: Jane Malalane <jane.malalane@xxxxxxxxxx>
---
CC: Wei Liu <wl@xxxxxxx>
CC: Jan Beulich <jbeulich@xxxxxxxx>
CC: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CC: "Roger Pau Monné" <roger.pau@xxxxxxxxxx>
CC: Pu Wen <puwen@xxxxxxxx>
CC: Andy Lutomirski <luto@xxxxxxxxxx>

v2:
 * Mark detect_zen2_null_seg_behaviour() with __init
 * Remove model checks
---
 xen/arch/x86/cpu/amd.c           | 18 ++++++++++++++++++
 xen/arch/x86/cpu/cpu.h           |  1 +
 xen/arch/x86/cpu/hygon.c         |  5 +++++
 xen/include/asm-x86/cpufeature.h |  1 +
 4 files changed, 25 insertions(+)

diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index 2260eef3aa..cb12861481 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -681,6 +681,19 @@ void amd_init_lfence(struct cpuinfo_x86 *c)
                          c->x86_capability);
 }
 
+void __init detect_zen2_null_seg_behaviour(void)
+{
+       uint64_t base;
+
+       wrmsrl(MSR_FS_BASE, 1);
+       asm volatile ( "mov %0, %%fs" :: "rm" (0) );
+       rdmsrl(MSR_FS_BASE, base);
+
+       if (base == 0)
+               setup_force_cpu_cap(X86_FEATURE_NSCB);
+
+}
+
 static void init_amd(struct cpuinfo_x86 *c)
 {
        u32 l, h;
@@ -731,6 +744,11 @@ static void init_amd(struct cpuinfo_x86 *c)
        else /* Implicily "== 0x10 || >= 0x12" by being 64bit. */
                amd_init_lfence(c);
 
+       /* Probe for NSCB on Zen2 CPUs when not virtualised */
+       if (!cpu_has_hypervisor && !cpu_has_nscb && c == &boot_cpu_data &&
+           c->x86 == 0x17)
+               detect_zen2_null_seg_behaviour();
+
        /*
         * If the user has explicitly chosen to disable Memory Disambiguation
         * to mitigiate Speculative Store Bypass, poke the appropriate MSR.
diff --git a/xen/arch/x86/cpu/cpu.h b/xen/arch/x86/cpu/cpu.h
index 1ac3b2867a..0dd1b762ff 100644
--- a/xen/arch/x86/cpu/cpu.h
+++ b/xen/arch/x86/cpu/cpu.h
@@ -21,3 +21,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);
+void detect_zen2_null_seg_behaviour(void);
diff --git a/xen/arch/x86/cpu/hygon.c b/xen/arch/x86/cpu/hygon.c
index 67e23c5df9..d7a04af2bb 100644
--- a/xen/arch/x86/cpu/hygon.c
+++ b/xen/arch/x86/cpu/hygon.c
@@ -34,6 +34,11 @@ static void init_hygon(struct cpuinfo_x86 *c)
 
        amd_init_lfence(c);
 
+       /* Probe for NSCB on Zen2 CPUs when not virtualised */
+       if (!cpu_has_hypervisor && !cpu_has_nscb && c == &boot_cpu_data &&
+           c->x86 == 0x18)
+               detect_zen2_null_seg_behaviour();
+
        /*
         * If the user has explicitly chosen to disable Memory Disambiguation
         * to mitigiate Speculative Store Bypass, poke the appropriate MSR.
diff --git a/xen/include/asm-x86/cpufeature.h b/xen/include/asm-x86/cpufeature.h
index 5f6b83f71c..4faf9bff29 100644
--- a/xen/include/asm-x86/cpufeature.h
+++ b/xen/include/asm-x86/cpufeature.h
@@ -146,6 +146,7 @@
 #define cpu_has_cpuid_faulting  boot_cpu_has(X86_FEATURE_CPUID_FAULTING)
 #define cpu_has_aperfmperf      boot_cpu_has(X86_FEATURE_APERFMPERF)
 #define cpu_has_lfence_dispatch boot_cpu_has(X86_FEATURE_LFENCE_DISPATCH)
+#define cpu_has_nscb            boot_cpu_has(X86_FEATURE_NSCB)
 #define cpu_has_xen_lbr         boot_cpu_has(X86_FEATURE_XEN_LBR)
 #define cpu_has_xen_shstk       boot_cpu_has(X86_FEATURE_XEN_SHSTK)
 
-- 
2.11.0




 


Rackspace

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