Skip to contentSkip to conversation

x86/amd: Expand comment about NullSelectorClearsBase

PATCH In review Andrew Cooper 2 participants 2 messages Aug 20 – Aug 21

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/amd: Expand comment about NullSelectorClearsBase

Rework detect_zen2_null_seg_behaviour() to use the new MSR infrastructure.

Zen2 doesn't have WRMSRNS so don't bother relaxing the write. All it will do is insert a useless alternative.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>

Naming Zen2/3 in init_hygon() isn't ideal, but the early hygons really were not far removed from the AMD microarchitectures.

---
 xen/arch/x86/cpu/amd.c   | 17 ++++++++---------
 xen/arch/x86/cpu/hygon.c |  5 ++++-
 2 files changed, 12 insertions(+), 10 deletions(-)
xen/arch/x86/cpu/amd.c +8 -9
index 70783c9a0af0..ddd73f64c2d5 100644
@@ -828,15 +828,11 @@ void amd_init_spectral_chicken(void)
 
 void __init detect_zen2_null_seg_behaviour(void)
 {
-	uint64_t base;
-
-	wrmsrl(MSR_FS_BASE, 1);
-	asm volatile ( "mov %0, %%fs" :: "r" (0) );
-	rdmsrl(MSR_FS_BASE, base);
-
-	if (base == 0)
-		setup_force_cpu_cap(X86_FEATURE_NSCB);
+    wrmsr(MSR_FS_BASE, 1);
+    asm volatile ( "mov %0, %%fs" :: "r" (0) );
 
+    if ( rdmsr(MSR_FS_BASE) == 0 )
+        setup_force_cpu_cap(X86_FEATURE_NSCB);
 }
 
 static void cf_check fam17_disable_c6(void *arg)
@@ -1110,7 +1106,10 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)
 	if (c->family == 0x17)
 		amd_init_spectral_chicken();
 
-	/* Probe for NSCB on Zen2 CPUs when not virtualised */
+	/*
+	 * Zen3 and later enumerate NullSelectorClearsBase.  Zen2 has this
+	 * behaviour but doesn't enumerate it.  Probe when not virtualised.
+	 */
 	if (!cpu_has_hypervisor && !cpu_has_nscb && c == &boot_cpu_data &&
 	    c->family == 0x17)
 		detect_zen2_null_seg_behaviour();
xen/arch/x86/cpu/hygon.c +4 -1
index 7a9fc25d3157..ef19c2b36783 100644
@@ -39,7 +39,10 @@ static void cf_check init_hygon(struct cpuinfo_x86 *c)
 
 	amd_init_ssbd(c);
 
-	/* Probe for NSCB on Zen2 CPUs when not virtualised */
+	/*
+	 * Zen3 and later enumerate NullSelectorClearsBase.  Zen2 has this
+	 * behaviour but doesn't enumerate it.  Probe when not virtualised.
+	 */
 	if (!cpu_has_hypervisor && !cpu_has_nscb && c == &boot_cpu_data &&
 	    c->family == 0x18)
 		detect_zen2_null_seg_behaviour();
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Andrew Cooper

Rework detect_zen2_null_seg_behaviour() to use the new MSR infrastructure.

Zen2 doesn't have WRMSRNS so don't bother relaxing the write. All it will do is insert a useless alternative.

No functional change.

Quoted 2 lines

Naming Zen2/3 in init_hygon() isn't ideal, but the early hygons really were not far removed from the AMD microarchitectures.

I wonder what we should do about Hygon. Just recently I saw patches going into somewhere (gcc?) to support recent hardware. We haven't seen any contributions in many years to keep our support up-to-date. We may want/need to consider removing support if that code is effectively unmaintained.

Jan