Skip to contentSkip to conversation

x86: make Intel/AMD vPMU & MCE support configurable

PATCH In review Sergiy Kibrik 4 participants 9 messages May 22, 2024 – May 29, 2024

lore
Share & tools
lore
#0 lore raw

v4 cover x86: make Intel/AMD vPMU & MCE support configurable

Three remaining patches to separate support of Intel & AMD CPUs in Xen build. Most of related patches from previous series had already been merged. Specific changes since v3 are provided per-patch.

v3 series here:
https://lore.kernel.org/xen-devel/[email protected]/

-Sergiy

Sergiy Kibrik (3):
x86/intel: move vmce_has_lmce() routine to header x86/MCE: add default switch case in init_nonfatal_mce_checker() x86/MCE: optional build of AMD/Intel MCE code

 xen/arch/x86/cpu/mcheck/Makefile    | 8 ++++----
 xen/arch/x86/cpu/mcheck/mce.c       | 4 ++++
 xen/arch/x86/cpu/mcheck/mce.h       | 5 +++++
 xen/arch/x86/cpu/mcheck/mce_intel.c | 8 --------
 xen/arch/x86/cpu/mcheck/non-fatal.c | 9 +++++++++
 xen/arch/x86/cpu/mcheck/vmce.c      | 5 ++---
 xen/arch/x86/include/asm/mce.h      | 1 -
 xen/arch/x86/msr.c                  | 2 ++
 8 files changed, 26 insertions(+), 16 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 1/3 x86/intel: move vmce_has_lmce() routine to header

Moving this function out of mce_intel.c will make it possible to disable build of Intel MCE code later on, because the function gets called from common x86 code.

Also replace boilerplate code that checks for MCG_LMCE_P flag with vmce_has_lmce(), which might contribute to readability a bit.

---
changes in v4:
- changed description a bit
changes in v3:
- do not check for CONFIG_INTEL
- remove CONFIG_INTEL from patch description
changes in v2:
- move vmce_has_lmce() to cpu/mcheck/mce.h
- move IS_ENABLED(CONFIG_INTEL) check inside vmce_has_lmce()
- changed description

---
 xen/arch/x86/cpu/mcheck/mce.h       | 5 +++++
 xen/arch/x86/cpu/mcheck/mce_intel.c | 4 ----
 xen/arch/x86/cpu/mcheck/vmce.c      | 5 ++---
 xen/arch/x86/include/asm/mce.h      | 1 -
 xen/arch/x86/msr.c                  | 2 ++
 5 files changed, 9 insertions(+), 8 deletions(-)
xen/arch/x86/cpu/mcheck/mce.h +5 -0
index 4806405f96..eba4b536c7 100644
@@ -170,6 +170,11 @@ static inline int mce_bank_msr(const struct vcpu *v, uint32_t msr)
     return 0;
 }
 
+static inline bool vmce_has_lmce(const struct vcpu *v)
+{
+    return v->arch.vmce.mcg_cap & MCG_LMCE_P;
+}
+
 struct mce_callbacks {
     void (*handler)(const struct cpu_user_regs *regs);
     bool (*check_addr)(uint64_t status, uint64_t misc, int addr_type);
xen/arch/x86/cpu/mcheck/mce_intel.c +0 -4
index 3f5199b531..af43281cc6 100644
@@ -1050,7 +1050,3 @@ int vmce_intel_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
     return 1;
 }
 
-bool vmce_has_lmce(const struct vcpu *v)
-{
-    return v->arch.vmce.mcg_cap & MCG_LMCE_P;
-}
xen/arch/x86/cpu/mcheck/vmce.c +2 -3
index 4da6f4a3e4..5abdf4cb5f 100644
@@ -203,7 +203,7 @@ int vmce_rdmsr(uint32_t msr, uint64_t *val)
          * bits are always set in guest MSR_IA32_FEATURE_CONTROL by Xen, so it
          * does not need to check them here.
          */
-        if ( cur->arch.vmce.mcg_cap & MCG_LMCE_P )
+        if ( vmce_has_lmce(cur) )
         {
             *val = cur->arch.vmce.mcg_ext_ctl;
             mce_printk(MCE_VERBOSE, "MCE: %pv: rd MCG_EXT_CTL %#"PRIx64"\n",
@@ -332,8 +332,7 @@ int vmce_wrmsr(uint32_t msr, uint64_t val)
         break;
 
     case MSR_IA32_MCG_EXT_CTL:
-        if ( (cur->arch.vmce.mcg_cap & MCG_LMCE_P) &&
-             !(val & ~MCG_EXT_CTL_LMCE_EN) )
+        if ( vmce_has_lmce(cur) && !(val & ~MCG_EXT_CTL_LMCE_EN) )
             cur->arch.vmce.mcg_ext_ctl = val;
         else
             ret = -1;
xen/arch/x86/include/asm/mce.h +0 -1
index 6ce56b5b85..2ec47a71ae 100644
@@ -41,7 +41,6 @@ extern void vmce_init_vcpu(struct vcpu *v);
 extern int vmce_restore_vcpu(struct vcpu *v, const struct hvm_vmce_vcpu *ctxt);
 extern int vmce_wrmsr(uint32_t msr, uint64_t val);
 extern int vmce_rdmsr(uint32_t msr, uint64_t *val);
-extern bool vmce_has_lmce(const struct vcpu *v);
 extern int vmce_enable_mca_cap(struct domain *d, uint64_t cap);
 
 DECLARE_PER_CPU(unsigned int, nr_mce_banks);
xen/arch/x86/msr.c +2 -0
index 9babd441f9..b0ec96f021 100644
@@ -24,6 +24,8 @@
 
 #include <public/hvm/params.h>
 
+#include "cpu/mcheck/mce.h"
+
 DEFINE_PER_CPU(uint32_t, tsc_aux);
 
 int init_vcpu_msr_policy(struct vcpu *v)
Signature · 1 line
2.25.1
Acked-by on v4 1/3
#2 lore raw

Re: [XEN PATCH v4 1/3] x86/intel: move vmce_has_lmce() routine to header

xen/arch/x86/msr.c line 27

Quoted 7 lines · Sergiy Kibrik
xen/arch/x86/msr.c +1 -0
@@ -24,6 +24,8 @@
 
 #include <public/hvm/params.h>
 
+#include "cpu/mcheck/mce.h"

Considering that I asked about this before, I'm a little irritated that this is is entirely unadorned. Such an unusual #include wants explaining some, you'll find similar comments elsewhere:

#include "cpu/mcheck/mce.h" /* for vmce_has_lmce() */

With that, which could also be adjusted while committing,

Jan

#3 lore raw

PATCH v4 2/3 x86/MCE: add default switch case in init_nonfatal_mce_checker()

In reply to Sergiy Kibrik

The default switch case block is wanted here, to handle situation e.g. of unexpected c->x86_vendor value -- then no mcheck init is done, but misleading message still gets logged anyway.

---
changes in v4:
- return 0 instead of -ENODEV and put a comment
- update description a bit

---
 xen/arch/x86/cpu/mcheck/non-fatal.c | 5 +++++
 1 file changed, 5 insertions(+)
xen/arch/x86/cpu/mcheck/non-fatal.c +5 -0
index 33cacd15c2..5a53bcd0b7 100644
@@ -29,9 +29,14 @@ static int __init cf_check init_nonfatal_mce_checker(void)
 		/* Assume we are on K8 or newer AMD or Hygon CPU here */
 		amd_nonfatal_mcheck_init(c);
 		break;
+
 	case X86_VENDOR_INTEL:
 		intel_nonfatal_mcheck_init(c);
 		break;
+
+	default:
+		/* unhandled vendor isn't really an error */
+		return 0;
 	}
 	printk(KERN_INFO "mcheck_poll: Machine check polling timer started.\n");
 	return 0;
Signature · 1 line
2.25.1
Reviewed-by on v4 2/3
#4 lore raw

Re: [XEN PATCH v4 2/3] x86/MCE: add default switch case in init_nonfatal_mce_checker()

Quoted 6 lines · Sergiy Kibrik

The default switch case block is wanted here, to handle situation e.g. of unexpected c->x86_vendor value -- then no mcheck init is done, but misleading message still gets logged anyway.

Quoted 30 lines

---
changes in v4:
- return 0 instead of -ENODEV and put a comment
- update description a bit

---
 xen/arch/x86/cpu/mcheck/non-fatal.c | 5 +++++
 1 file changed, 5 insertions(+)
xen/arch/x86/cpu/mcheck/non-fatal.c +5 -0
index 33cacd15c2..5a53bcd0b7 100644
@@ -29,9 +29,14 @@ static int __init cf_check init_nonfatal_mce_checker(void)
 		/* Assume we are on K8 or newer AMD or Hygon CPU here */
 		amd_nonfatal_mcheck_init(c);
 		break;
+
 	case X86_VENDOR_INTEL:
 		intel_nonfatal_mcheck_init(c);
 		break;
+
+	default:
+		/* unhandled vendor isn't really an error */
+		return 0;
 	}
 	printk(KERN_INFO "mcheck_poll: Machine check polling timer started.\n");
 	return 0;
Signature · 1 line
2.25.1
#6 lore raw

PATCH v4 3/3 x86/MCE: optional build of AMD/Intel MCE code

In reply to Sergiy Kibrik

Separate Intel/AMD-specific MCE code using CONFIG_{INTEL,AMD} config options. Now we can avoid build of mcheck code if support for specific platform is intentionally disabled by configuration.

Also global variables lmce_support & cmci_support from Intel-specific mce_intel.c have to moved to common mce.c, as they get checked in common code.

---
changes in v4:
- attribute {lmce_support,cmci_support} with __ro_after_init
changes in v3:
- default return value of init_nonfatal_mce_checker() done in separate patch
- move lmce_support & cmci_support to common mce.c code
- changed patch description
changes in v2:
- fallback to original ordering in Makefile
- redefine lmce_support & cmci_support global vars to false when !INTEL
- changed patch description

---
 xen/arch/x86/cpu/mcheck/Makefile    | 8 ++++----
 xen/arch/x86/cpu/mcheck/mce.c       | 4 ++++
 xen/arch/x86/cpu/mcheck/mce_intel.c | 4 ----
 xen/arch/x86/cpu/mcheck/non-fatal.c | 4 ++++
 4 files changed, 12 insertions(+), 8 deletions(-)
xen/arch/x86/cpu/mcheck/Makefile +4 -4
index f927f10b4d..e6cb4dd503 100644
@@ -1,12 +1,12 @@
-obj-y += amd_nonfatal.o
-obj-y += mce_amd.o
+obj-$(CONFIG_AMD) += amd_nonfatal.o
+obj-$(CONFIG_AMD) += mce_amd.o
 obj-y += mcaction.o
 obj-y += barrier.o
-obj-y += intel-nonfatal.o
+obj-$(CONFIG_INTEL) += intel-nonfatal.o
 obj-y += mctelem.o
 obj-y += mce.o
 obj-y += mce-apei.o
-obj-y += mce_intel.o
+obj-$(CONFIG_INTEL) += mce_intel.o
 obj-y += non-fatal.o
 obj-y += util.o
 obj-y += vmce.o
xen/arch/x86/cpu/mcheck/mce.c +4 -0
index fb9dec5b89..1664ca6412 100644
@@ -38,6 +38,10 @@ DEFINE_PER_CPU_READ_MOSTLY(unsigned int, nr_mce_banks);
 unsigned int __read_mostly firstbank;
 unsigned int __read_mostly ppin_msr;
 uint8_t __read_mostly cmci_apic_vector;
+bool __ro_after_init cmci_support;
+
+/* If mce_force_broadcast == 1, lmce_support will be disabled forcibly. */
+bool __ro_after_init lmce_support;
 
 DEFINE_PER_CPU_READ_MOSTLY(struct mca_banks *, poll_bankmask);
 DEFINE_PER_CPU_READ_MOSTLY(struct mca_banks *, no_cmci_banks);
xen/arch/x86/cpu/mcheck/mce_intel.c +0 -4
index af43281cc6..dd812f4b8a 100644
@@ -26,16 +26,12 @@
 #include "mcaction.h"
 
 static DEFINE_PER_CPU_READ_MOSTLY(struct mca_banks *, mce_banks_owned);
-bool __read_mostly cmci_support;
 static bool __read_mostly ser_support;
 static bool __read_mostly mce_force_broadcast;
 boolean_param("mce_fb", mce_force_broadcast);
 
 static int __read_mostly nr_intel_ext_msrs;
 
-/* If mce_force_broadcast == 1, lmce_support will be disabled forcibly. */
-bool __read_mostly lmce_support;
-
 /* Intel SDM define bit15~bit0 of IA32_MCi_STATUS as the MC error code */
 #define INTEL_MCCOD_MASK 0xFFFF
 
xen/arch/x86/cpu/mcheck/non-fatal.c +4 -0
index 5a53bcd0b7..a9ee9bb94f 100644
@@ -24,15 +24,19 @@ static int __init cf_check init_nonfatal_mce_checker(void)
 	 * Check for non-fatal errors every MCE_RATE s
 	 */
 	switch (c->x86_vendor) {
+#ifdef CONFIG_AMD
 	case X86_VENDOR_AMD:
 	case X86_VENDOR_HYGON:
 		/* Assume we are on K8 or newer AMD or Hygon CPU here */
 		amd_nonfatal_mcheck_init(c);
 		break;
+#endif
 
+#ifdef CONFIG_INTEL
 	case X86_VENDOR_INTEL:
 		intel_nonfatal_mcheck_init(c);
 		break;
+#endif
 
 	default:
 		/* unhandled vendor isn't really an error */
Signature · 1 line
2.25.1
#7 lore raw
In reply to Sergiy Kibrik

Oleksii,

Quoted 7 lines · Sergiy Kibrik

Three remaining patches to separate support of Intel & AMD CPUs in Xen build. Most of related patches from previous series had already been merged. Specific changes since v3 are provided per-patch.

v3 series here:
https://lore.kernel.org/xen-devel/[email protected]/

Quoted 6 lines

-Sergiy

Sergiy Kibrik (3):
x86/intel: move vmce_has_lmce() routine to header x86/MCE: add default switch case in init_nonfatal_mce_checker() x86/MCE: optional build of AMD/Intel MCE code

As I'm apparently confused as to the state 4.19 is in, may I please ask whether this series is still okay to go in, or whether it should be postponed until after branching.

Thanks, Jan

#8 lore raw
Quoted 19 lines · Jan Beulich

Oleksii,

Quoted 9 lines · Sergiy Kibrik

Three remaining patches to separate support of Intel & AMD CPUs in Xen build.
Most of related patches from previous series had already been merged.
Specific changes since v3 are provided per-patch.

v3 series here:
https://lore.kernel.org/xen-devel/[email protected]/

Quoted 6 lines

  -Sergiy

Sergiy Kibrik (3):
  x86/intel: move vmce_has_lmce() routine to header x86/MCE: add default switch case in init_nonfatal_mce_checker() x86/MCE: optional build of AMD/Intel MCE code

Quoted 4 lines

As I'm apparently confused as to the state 4.19 is in, may I please ask
whether this series is still okay to go in, or whether it should be postponed until after branching.

I am okay to go in this release.

Sorry for the confusion with the 4.19 state. I'll send a proper schedule today.

~ Oleksii