Skip to contentSkip to conversation

x86/MCE: restore CPU vendor reporting to the outside world

PATCH In review Jan Beulich 3 participants 4 messages Feb 16 – Feb 23

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/MCE: restore CPU vendor reporting to the outside world

The records reported used to contain Linux enumerators. We first broke that connection when purging unused ones, and then again when switching to the bit mask forms.

Fixes 408413051144 ("x86/cpu: Drop unused X86_VENDOR_* values")
Fixes 0cd074144cbb ("x86/cpu: Renumber X86_VENDOR_* to form a bitmap")
xen/arch/x86/cpu/mcheck/mce.c +18 -2
@@ -858,6 +858,22 @@ void *x86_mcinfo_reserve(struct mc_info
     return mic_index;
 }
 
+/* Linux values need using when reporting CPU vendors to the outside. */
+static unsigned int xen2linux_vendor(unsigned int vendor)
+{
+    switch ( vendor )
+    {
+    case X86_VENDOR_INTEL:    return 0;
+    case X86_VENDOR_AMD:      return 2;
+    case X86_VENDOR_CENTAUR:  return 5;
+    case X86_VENDOR_HYGON:    return 9;
+    case X86_VENDOR_SHANGHAI: return 10; /* X86_VENDOR_ZHAOXIN */
+    default: break;
+    }
+
+    return 0xff; /* X86_VENDOR_UNKNOWN */
+}
+
 static void x86_mcinfo_apei_save(
     struct mcinfo_global *mc_global, struct mcinfo_bank *mc_bank)
 {
@@ -866,7 +882,7 @@ static void x86_mcinfo_apei_save(
     memset(&m, 0, sizeof(struct mce));
 
     m.cpu = mc_global->mc_coreid;
-    m.cpuvendor = boot_cpu_data.x86_vendor;
+    m.cpuvendor = xen2linux_vendor(boot_cpu_data.x86_vendor);
     m.cpuid = cpuid_eax(1);
     m.socketid = mc_global->mc_socketid;
     m.apicid = mc_global->mc_apicid;
@@ -968,7 +984,7 @@ static void cf_check __maybe_unused do_m
                         &xcp->mc_ncores_active, &xcp->mc_nthreads);
     xcp->mc_cpuid_level = c->cpuid_level;
     xcp->mc_family = c->x86;
-    xcp->mc_vendor = c->x86_vendor;
+    xcp->mc_vendor = xen2linux_vendor(c->x86_vendor);
     xcp->mc_model = c->x86_model;
     xcp->mc_step = c->x86_mask;
     xcp->mc_cache_size = c->x86_cache_size;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

The records reported used to contain Linux enumerators. We first broke that connection when purging unused ones, and then again when switching to the bit mask forms.

Fixes 408413051144 ("x86/cpu: Drop unused X86_VENDOR_* values")
Fixes 0cd074144cbb ("x86/cpu: Renumber X86_VENDOR_* to form a bitmap")
#2 lore raw
In reply to Jan Beulich
Quoted 7 lines · Jan Beulich

The records reported used to contain Linux enumerators. We first broke that connection when purging unused ones, and then again when switching to the bit mask forms.

Fixes 408413051144 ("x86/cpu: Drop unused X86_VENDOR_* values")
Fixes 0cd074144cbb ("x86/cpu: Renumber X86_VENDOR_* to form a bitmap")

I see you've committed this, but it's not a viable approach.

Quoted 11 lines
xen/arch/x86/cpu/mcheck/mce.c +5 -0
@@ -858,6 +858,22 @@ void *x86_mcinfo_reserve(struct mc_info
     return mic_index;
 }
 
+/* Linux values need using when reporting CPU vendors to the outside. */
+static unsigned int xen2linux_vendor(unsigned int vendor)
+{
+    switch ( vendor )
+    {

xen/arch/x86/cpu/mcheck/mce.c void *x86_mcinfo_reserve(struct mc_info · line 875

Quoted 10 lines
xen/arch/x86/cpu/mcheck/mce.c +10 -0
+    case X86_VENDOR_INTEL:    return 0;
+    case X86_VENDOR_AMD:      return 2;
+    case X86_VENDOR_CENTAUR:  return 5;
+    case X86_VENDOR_HYGON:    return 9;
+    case X86_VENDOR_SHANGHAI: return 10; /* X86_VENDOR_ZHAOXIN */
+    default: break;
+    }
+
+    return 0xff; /* X86_VENDOR_UNKNOWN */
+}

The Linux x86 maintainers say that the numbers are internal and not an ABI, even they haven't changed since 2008.

xen/arch/x86/cpu/mcheck/mce.c static void x86_mcinfo_apei_save( · line 885

Quoted 10 lines
xen/arch/x86/cpu/mcheck/mce.c +2 -1
+
 static void x86_mcinfo_apei_save(
     struct mcinfo_global *mc_global, struct mcinfo_bank *mc_bank)
 {
@@ -866,7 +882,7 @@ static void x86_mcinfo_apei_save(
     memset(&m, 0, sizeof(struct mce));
 
     m.cpu = mc_global->mc_coreid;
-    m.cpuvendor = boot_cpu_data.x86_vendor;
+    m.cpuvendor = xen2linux_vendor(boot_cpu_data.x86_vendor);

This is an internal Xen structure.  This hunk needs reverting.

xen/arch/x86/cpu/mcheck/mce.c static void cf_check __maybe_unused do_m · line 990

Quoted 12 lines
xen/arch/x86/cpu/mcheck/mce.c +1 -1
     m.cpuid = cpuid_eax(1);
     m.socketid = mc_global->mc_socketid;
     m.apicid = mc_global->mc_apicid;
@@ -968,7 +984,7 @@ static void cf_check __maybe_unused do_m
                         &xcp->mc_ncores_active, &xcp->mc_nthreads);
     xcp->mc_cpuid_level = c->cpuid_level;
     xcp->mc_family = c->x86;
-    xcp->mc_vendor = c->x86_vendor;
+    xcp->mc_vendor = xen2linux_vendor(c->x86_vendor);
     xcp->mc_model = c->x86_model;
     xcp->mc_step = c->x86_mask;
     xcp->mc_cache_size = c->x86_cache_size;

This is an external structure, but a crap one at that.

It's full of wrong information, including mc_cpu_caps[] which has been wrong forever (Xen never had the Linux internal leaf as Linux had it, and the standard leaves haven't had that order since Xen 4.6 or so), and mc_cpunr which is Xen's idea of the CPU number, not Linuxes.

It seems to be copy&paste of an internal Linux structure, but given as a Xen-wide interface.

I find it hard to believe that this is even usable, which begs the question is it even used?

Deleting xen-mca.h is probably the only reasonable approach I can see here.  It should have been hard-nacked at the point of being proposed, and never gotten into Xen...

~Andrew

#3 lore raw
Quoted 10 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich

The records reported used to contain Linux enumerators. We first broke that connection when purging unused ones, and then again when switching to the bit mask forms.

Fixes 408413051144 ("x86/cpu: Drop unused X86_VENDOR_* values")
Fixes 0cd074144cbb ("x86/cpu: Renumber X86_VENDOR_* to form a bitmap")

I see you've committed this, but it's not a viable approach.

Well, depends on what the goal is, I suppose: It's viable to restore previously regressed behavior. We have been in agreement, I think, that vMCE itself is doomed.

Quoted 16 lines
Quoted 16 lines
xen/arch/x86/cpu/mcheck/mce.c +10 -0
@@ -858,6 +858,22 @@ void *x86_mcinfo_reserve(struct mc_info
     return mic_index;
 }
 
+/* Linux values need using when reporting CPU vendors to the outside. */
+static unsigned int xen2linux_vendor(unsigned int vendor)
+{
+    switch ( vendor )
+    {
+    case X86_VENDOR_INTEL:    return 0;
+    case X86_VENDOR_AMD:      return 2;
+    case X86_VENDOR_CENTAUR:  return 5;
+    case X86_VENDOR_HYGON:    return 9;
+    case X86_VENDOR_SHANGHAI: return 10; /* X86_VENDOR_ZHAOXIN */
Quoted 8 lines

xen/arch/x86/cpu/mcheck/mce.c void *x86_mcinfo_reserve(struct mc_info · line 875

Quoted 5 lines
xen/arch/x86/cpu/mcheck/mce.c +5 -0
+    default: break;
+    }
+
+    return 0xff; /* X86_VENDOR_UNKNOWN */
+}

The Linux x86 maintainers say that the numbers are internal and not an ABI, even they haven't changed since 2008.

Yet the numbers are propagated to the outside world there as well, aiui.

Quoted 8 lines

xen/arch/x86/cpu/mcheck/mce.c static void x86_mcinfo_apei_save( · line 885

Quoted 6 lines
xen/arch/x86/cpu/mcheck/mce.c +1 -1
@@ -866,7 +882,7 @@ static void x86_mcinfo_apei_save(
     memset(&m, 0, sizeof(struct mce));
 
     m.cpu = mc_global->mc_coreid;
-    m.cpuvendor = boot_cpu_data.x86_vendor;
+    m.cpuvendor = xen2linux_vendor(boot_cpu_data.x86_vendor);

This is an internal Xen structure.  This hunk needs reverting.

It's not, unless I'm missing something. The struct is passed to apei_write_mce(), to then be passed to erst_write(). ERST isn't Xen- internal anymore, is it?

Jan