Skip to contentSkip to conversation

KVM: x86: Add CMCI and UCNA emulation

PATCH Superseded Jue Wang 2 participants 10 messages May 13, 2022

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Jue Wang

author
#0 lore raw

v3 cover KVM: x86: Add CMCI and UCNA emulation

This patch series implement emulation for Corrected Machine Check Interrupt (CMCI) signaling and UnCorrectable No Action required (UCNA) error injection.

UCNA errors signaled via CMCI allow a guest to be notified as soon as uncorrectable memory errors get detected by some background threads, e.g., threads that migrate guest memory across hosts or threads that constantly scan system memory for errors [1].

Upon receiving UCNAs, guest kernel isolates the poisoned pages which may still be free, preventing future accesses that may cause fatal MCEs.

1. https://lore.kernel.org/linux-mm/[email protected]/t/

Patch 1-3 clean up KVM APIC LVT logic.

Patch 4 adds CMCI emulation to lapic.

Patch 5 updates the allocation of mce_array to use array allocation api:
kcalloc.

Patch 6 adds emulation for the per-bank MSR_IA32_MCx_CTL2 MSRs that controls CMCI signaling.

Patch 7 enables MCG_CMCI_P on x86 and handles injected UCNA errors.

v3 changes
- Incorporate feedback from Sean Christopherson <[email protected]>
- Split clean up to KVM APIC LVT logic to 3 patches.
- Put the clean up of mce_array allocation in a separate patch.
- Base the MCi_CTL2 register emulation on Sean's clean up and fix series [2]
- Fix bugs around MCi_CTL2 register offset validation and the free of mci_ctl2_banks array.
- Rewrite the change log with more details in architectural information about CMCI, UCNA and MCG_CMCI_P.
- Fix various comments and wrapping style.

2. https://lore.kernel.org/lkml/[email protected]/T/

v2 chanegs
- Incorporate feedback from Sean Christopherson <[email protected]>
- Split the single patch into 4:
1). clean up KVM APIC LVT logic
2). add CMCI emulation to lapic
3). add emulation of MSR_IA32_MCx_CTL2
4). enable MCG_CMCI_P and handle injected UCNAs
- Fix various style issues.

Jue Wang (7):
KVM: x86: Make APIC_VERSION capture only the magic 0x14UL.
KVM: x86: Fill apic_lvt_mask with enums / explicit entries.
KVM: x86: Add APIC_LVTx() macro.
KVM: x86: Add Corrected Machine Check Interrupt (CMCI) emulation to
lapic.
KVM: x86: Use kcalloc to allocate the mce_banks array.
KVM: x86: Add emulation for MSR_IA32_MCx_CTL2 MSRs.
KVM: x86: Enable MCG_CMCI_P and handle injected UCNAs.

 arch/x86/include/asm/kvm_host.h |   1 +
 arch/x86/kvm/lapic.c            |  58 +++++++---
 arch/x86/kvm/lapic.h            |  15 ++-
 arch/x86/kvm/vmx/vmx.c          |   1 +
 arch/x86/kvm/x86.c              | 182 +++++++++++++++++++++++++-------
 5 files changed, 200 insertions(+), 57 deletions(-)
Signature · 1 line
2.36.0.550.gb090851708-goog
author
#1 lore raw

PATCH v3 1/7 KVM: x86: Make APIC_VERSION capture only the magic 0x14UL.

This series adds the Corrected Machine Check Interrupt (CMCI) and Uncorrectable Error No Action required (UCNA) emulation to KVM. The former is implemented as a LVT CMCI vector. The emulation of UCNA share the MCE emulation infrastructure.

This is the first of 3 patches that clean up KVM APIC LVT logic.

---
 arch/x86/kvm/lapic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/lapic.c +2 -2
index 9322e6340a74..73b94e312f97 100644
@@ -54,7 +54,7 @@
 #define PRIo64 "o"
 
 /* 14 is the version for Xeon and Pentium 8.4.8*/
-#define APIC_VERSION			(0x14UL | ((KVM_APIC_LVT_NUM - 1) << 16))
+#define APIC_VERSION			0x14UL
 #define LAPIC_MMIO_LENGTH		(1 << 12)
 /* followed define is not in apicdef.h */
 #define MAX_APIC_VECTOR			256
@@ -367,7 +367,7 @@ static inline int apic_lvt_nmi_mode(u32 lvt_val)
 void kvm_apic_set_version(struct kvm_vcpu *vcpu)
 {
 	struct kvm_lapic *apic = vcpu->arch.apic;
-	u32 v = APIC_VERSION;
+	u32 v = APIC_VERSION | ((KVM_APIC_LVT_NUM - 1) << 16);
 
 	if (!lapic_in_kernel(vcpu))
 		return;
Signature · 1 line
2.36.0.550.gb090851708-goog
#2 lore raw

Re: [PATCH v3 1/7] KVM: x86: Make APIC_VERSION capture only the magic 0x14UL.

Quoted 7 lines · Jue Wang

This series adds the Corrected Machine Check Interrupt (CMCI) and Uncorrectable Error No Action required (UCNA) emulation to KVM. The former is implemented as a LVT CMCI vector. The emulation of UCNA share the MCE emulation infrastructure.

This is the first of 3 patches that clean up KVM APIC LVT logic.

The change log should explain what a patch does and why. With the current change log it's not clear what is being cleaned up in the KVM APIC logic, and it's not clear what that has to do with CMCI/UNCA emulation. This is important for reviewing (I can't tell if this patch is correct since I can't tell what it's trying to accomplish) and for future reference (e.g. people reading the git history).

Quoted 21 lines
---
 arch/x86/kvm/lapic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/lapic.c +1 -1
index 9322e6340a74..73b94e312f97 100644
@@ -54,7 +54,7 @@
 #define PRIo64 "o"
 
 /* 14 is the version for Xeon and Pentium 8.4.8*/
-#define APIC_VERSION                   (0x14UL | ((KVM_APIC_LVT_NUM - 1) << 16))
+#define APIC_VERSION                   0x14UL
 #define LAPIC_MMIO_LENGTH              (1 << 12)
 /* followed define is not in apicdef.h */
 #define MAX_APIC_VECTOR                        256

arch/x86/kvm/lapic.c static inline int apic_lvt_nmi_mode(u32 lvt_val) · line 370

Quoted 5 lines
arch/x86/kvm/lapic.c +1 -1
@@ -367,7 +367,7 @@ static inline int apic_lvt_nmi_mode(u32 lvt_val)
 void kvm_apic_set_version(struct kvm_vcpu *vcpu)
 {
        struct kvm_lapic *apic = vcpu->arch.apic;
-       u32 v = APIC_VERSION;
+       u32 v = APIC_VERSION | ((KVM_APIC_LVT_NUM - 1) << 16);

This change looks redundant with the change to APIC_VERSION above.

Quoted 6 lines
arch/x86/kvm/lapic.c +0 -1
        if (!lapic_in_kernel(vcpu))
                return;
--

2.36.0.550.gb090851708-goog

author
#3 lore raw

PATCH v3 2/7 KVM: x86: Fill apic_lvt_mask with enums / explicit entries.

In reply to Jue Wang

This series adds the Corrected Machine Check Interrupt (CMCI) and Uncorrectable Error No Action required (UCNA) emulation to KVM. The former is implemented as a LVT CMCI vector. The emulation of UCNA share the MCE emulation infrastructure.

This is the second of 3 patches that clean up KVM APIC LVT logic.

---
 arch/x86/kvm/lapic.c | 19 ++++++++++---------
 arch/x86/kvm/lapic.h | 12 +++++++++++-
 2 files changed, 21 insertions(+), 10 deletions(-)
arch/x86/kvm/lapic.c +10 -9
index 73b94e312f97..0886fb6adbcd 100644
@@ -367,7 +367,7 @@ static inline int apic_lvt_nmi_mode(u32 lvt_val)
 void kvm_apic_set_version(struct kvm_vcpu *vcpu)
 {
 	struct kvm_lapic *apic = vcpu->arch.apic;
-	u32 v = APIC_VERSION | ((KVM_APIC_LVT_NUM - 1) << 16);
+	u32 v = APIC_VERSION | ((KVM_APIC_MAX_NR_LVT_ENTRIES - 1) << 16);
 
 	if (!lapic_in_kernel(vcpu))
 		return;
@@ -385,12 +385,13 @@ void kvm_apic_set_version(struct kvm_vcpu *vcpu)
 	kvm_lapic_set_reg(apic, APIC_LVR, v);
 }
 
-static const unsigned int apic_lvt_mask[KVM_APIC_LVT_NUM] = {
-	LVT_MASK ,      /* part LVTT mask, timer mode mask added at runtime */
-	LVT_MASK | APIC_MODE_MASK,	/* LVTTHMR */
-	LVT_MASK | APIC_MODE_MASK,	/* LVTPC */
-	LINT_MASK, LINT_MASK,	/* LVT0-1 */
-	LVT_MASK		/* LVTERR */
+static const unsigned int apic_lvt_mask[KVM_APIC_MAX_NR_LVT_ENTRIES] = {
+	[LVT_TIMER] = LVT_MASK,      /* timer mode mask added at runtime */
+	[LVT_THERMAL_MONITOR] = LVT_MASK | APIC_MODE_MASK,
+	[LVT_PERFORMANCE_COUNTER] = LVT_MASK | APIC_MODE_MASK,
+	[LVT_LINT0] = LINT_MASK,
+	[LVT_LINT1] = LINT_MASK,
+	[LVT_ERROR] = LVT_MASK
 };
 
 static int find_highest_vector(void *bitmap)
@@ -2039,7 +2040,7 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
 			int i;
 			u32 lvt_val;
 
-			for (i = 0; i < KVM_APIC_LVT_NUM; i++) {
+			for (i = 0; i < KVM_APIC_MAX_NR_LVT_ENTRIES; i++) {
 				lvt_val = kvm_lapic_get_reg(apic,
 						       APIC_LVTT + 0x10 * i);
 				kvm_lapic_set_reg(apic, APIC_LVTT + 0x10 * i,
@@ -2341,7 +2342,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
 		kvm_apic_set_xapic_id(apic, vcpu->vcpu_id);
 	kvm_apic_set_version(apic->vcpu);
 
-	for (i = 0; i < KVM_APIC_LVT_NUM; i++)
+	for (i = 0; i < KVM_APIC_MAX_NR_LVT_ENTRIES; i++)
 		kvm_lapic_set_reg(apic, APIC_LVTT + 0x10 * i, APIC_LVT_MASKED);
 	apic_update_lvtt(apic);
 	if (kvm_vcpu_is_reset_bsp(vcpu) &&
arch/x86/kvm/lapic.h +11 -1
index 2b44e533fc8d..f8368dca177a 100644
@@ -10,7 +10,6 @@
 
 #define KVM_APIC_INIT		0
 #define KVM_APIC_SIPI		1
-#define KVM_APIC_LVT_NUM	6
 
 #define APIC_SHORT_MASK			0xc0000
 #define APIC_DEST_NOSHORT		0x0
@@ -29,6 +28,17 @@ enum lapic_mode {
 	LAPIC_MODE_X2APIC = MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE,
 };
 
+enum lapic_lvt_entry {
+	LVT_TIMER,
+	LVT_THERMAL_MONITOR,
+	LVT_PERFORMANCE_COUNTER,
+	LVT_LINT0,
+	LVT_LINT1,
+	LVT_ERROR,
+
+	KVM_APIC_MAX_NR_LVT_ENTRIES,
+};
+
 struct kvm_timer {
 	struct hrtimer timer;
 	s64 period; 				/* unit: ns */
Signature · 1 line
2.36.0.550.gb090851708-goog
author
#4 lore raw

PATCH v3 3/7 KVM: x86: Add APIC_LVTx() macro.

In reply to Jue Wang

This series adds the Corrected Machine Check Interrupt (CMCI) and Uncorrectable Error No Action required (UCNA) emulation to KVM. The former is implemented as a LVT CMCI vector. The emulation of UCNA share the MCE emulation infrastructure.

This is the third of 3 patches that clean up KVM APIC LVT logic.

---
 arch/x86/kvm/lapic.c | 7 +++----
 arch/x86/kvm/lapic.h | 2 ++
 2 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/kvm/lapic.c +3 -4
index 0886fb6adbcd..c01f6ecb3d12 100644
@@ -2041,9 +2041,8 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
 			u32 lvt_val;
 
 			for (i = 0; i < KVM_APIC_MAX_NR_LVT_ENTRIES; i++) {
-				lvt_val = kvm_lapic_get_reg(apic,
-						       APIC_LVTT + 0x10 * i);
-				kvm_lapic_set_reg(apic, APIC_LVTT + 0x10 * i,
+				lvt_val = kvm_lapic_get_reg(apic, APIC_LVTx(i));
+				kvm_lapic_set_reg(apic, APIC_LVTx(i),
 					     lvt_val | APIC_LVT_MASKED);
 			}
 			apic_update_lvtt(apic);
@@ -2343,7 +2342,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
 	kvm_apic_set_version(apic->vcpu);
 
 	for (i = 0; i < KVM_APIC_MAX_NR_LVT_ENTRIES; i++)
-		kvm_lapic_set_reg(apic, APIC_LVTT + 0x10 * i, APIC_LVT_MASKED);
+		kvm_lapic_set_reg(apic, APIC_LVTx(i), APIC_LVT_MASKED);
 	apic_update_lvtt(apic);
 	if (kvm_vcpu_is_reset_bsp(vcpu) &&
 	    kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_LINT0_REENABLED))
arch/x86/kvm/lapic.h +2 -0
index f8368dca177a..7ba4c548853e 100644
@@ -39,6 +39,8 @@ enum lapic_lvt_entry {
 	KVM_APIC_MAX_NR_LVT_ENTRIES,
 };
 
+#define APIC_LVTx(x) (APIC_LVTT + 0x10 * (x))
+
 struct kvm_timer {
 	struct hrtimer timer;
 	s64 period; 				/* unit: ns */
Signature · 1 line
2.36.0.550.gb090851708-goog
author
#5 lore raw

PATCH v3 4/7 KVM: x86: Add Corrected Machine Check Interrupt (CMCI) emulation to lapic.

In reply to Jue Wang

This series adds the Corrected Machine Check Interrupt (CMCI) and Uncorrectable Error No Action required (UCNA) emulation to KVM. The former is implemented as a LVT CMCI vector. The emulation of UCNA share the MCE emulation infrastructure.

CMCI emulation is only enabled when user space has opted in to enable MCG_CMCI_P bit in MCG_CAP via KVM_X86_SETUP_MCE.

---
 arch/x86/kvm/lapic.c | 40 +++++++++++++++++++++++++++++++++-------
 arch/x86/kvm/lapic.h |  3 ++-
 2 files changed, 35 insertions(+), 8 deletions(-)
arch/x86/kvm/lapic.c +33 -7
index c01f6ecb3d12..b451fbe8b394 100644
@@ -27,6 +27,7 @@
 #include <linux/math64.h>
 #include <linux/slab.h>
 #include <asm/processor.h>
+#include <asm/mce.h>
 #include <asm/msr.h>
 #include <asm/page.h>
 #include <asm/current.h>
@@ -364,14 +365,26 @@ static inline int apic_lvt_nmi_mode(u32 lvt_val)
 	return (lvt_val & (APIC_MODE_MASK | APIC_LVT_MASKED)) == APIC_DM_NMI;
 }
 
+static inline bool kvm_is_cmci_supported(struct kvm_vcpu *vcpu)
+{
+	return vcpu->arch.mcg_cap & MCG_CMCI_P;
+}
+
+static inline int kvm_apic_get_nr_lvt_entries(struct kvm_lapic *apic)
+{
+	return KVM_APIC_MAX_NR_LVT_ENTRIES - !kvm_is_cmci_supported(apic->vcpu);
+}
+
 void kvm_apic_set_version(struct kvm_vcpu *vcpu)
 {
 	struct kvm_lapic *apic = vcpu->arch.apic;
-	u32 v = APIC_VERSION | ((KVM_APIC_MAX_NR_LVT_ENTRIES - 1) << 16);
+	u32 v = 0;
 
 	if (!lapic_in_kernel(vcpu))
 		return;
 
+	v = APIC_VERSION | ((kvm_apic_get_nr_lvt_entries(apic) - 1) << 16);
+
 	/*
 	 * KVM emulates 82093AA datasheet (with in-kernel IOAPIC implementation)
 	 * which doesn't have EOI register; Some buggy OSes (e.g. Windows with
@@ -391,7 +404,8 @@ static const unsigned int apic_lvt_mask[KVM_APIC_MAX_NR_LVT_ENTRIES] = {
 	[LVT_PERFORMANCE_COUNTER] = LVT_MASK | APIC_MODE_MASK,
 	[LVT_LINT0] = LINT_MASK,
 	[LVT_LINT1] = LINT_MASK,
-	[LVT_ERROR] = LVT_MASK
+	[LVT_ERROR] = LVT_MASK,
+	[LVT_CMCI] = LVT_MASK | APIC_MODE_MASK
 };
 
 static int find_highest_vector(void *bitmap)
@@ -1406,6 +1420,9 @@ int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len,
 		APIC_REG_MASK(APIC_TMCCT) |
 		APIC_REG_MASK(APIC_TDCR);
 
+	if (kvm_is_cmci_supported(apic->vcpu))
+		valid_reg_mask |= APIC_REG_MASK(APIC_LVTCMCI);
+
 	/* ARBPRI is not valid on x2APIC */
 	if (!apic_x2apic_mode(apic))
 		valid_reg_mask |= APIC_REG_MASK(APIC_ARBPRI);
@@ -2038,12 +2055,10 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
 		apic_set_spiv(apic, val & mask);
 		if (!(val & APIC_SPIV_APIC_ENABLED)) {
 			int i;
-			u32 lvt_val;
 
-			for (i = 0; i < KVM_APIC_MAX_NR_LVT_ENTRIES; i++) {
-				lvt_val = kvm_lapic_get_reg(apic, APIC_LVTx(i));
+			for (i = 0; i < kvm_apic_get_nr_lvt_entries(apic); i++) {
 				kvm_lapic_set_reg(apic, APIC_LVTx(i),
-					     lvt_val | APIC_LVT_MASKED);
+					kvm_lapic_get_reg(apic, APIC_LVTx(i)) | APIC_LVT_MASKED);
 			}
 			apic_update_lvtt(apic);
 			atomic_set(&apic->lapic_timer.pending, 0);
@@ -2093,6 +2108,17 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
 		apic_update_lvtt(apic);
 		break;
 
+	case APIC_LVTCMCI:
+		if (!kvm_is_cmci_supported(apic->vcpu)) {
+			ret = 1;
+			break;
+		}
+		if (!kvm_apic_sw_enabled(apic))
+			val |= APIC_LVT_MASKED;
+		val &= apic_lvt_mask[LVT_CMCI];
+		kvm_lapic_set_reg(apic, APIC_LVTCMCI, val);
+		break;
+
 	case APIC_TMICT:
 		if (apic_lvtt_tscdeadline(apic))
 			break;
@@ -2341,7 +2367,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
 		kvm_apic_set_xapic_id(apic, vcpu->vcpu_id);
 	kvm_apic_set_version(apic->vcpu);
 
-	for (i = 0; i < KVM_APIC_MAX_NR_LVT_ENTRIES; i++)
+	for (i = 0; i < kvm_apic_get_nr_lvt_entries(apic); i++)
 		kvm_lapic_set_reg(apic, APIC_LVTx(i), APIC_LVT_MASKED);
 	apic_update_lvtt(apic);
 	if (kvm_vcpu_is_reset_bsp(vcpu) &&
arch/x86/kvm/lapic.h +2 -1
index 7ba4c548853e..64ed18fe0fb4 100644
@@ -35,11 +35,12 @@ enum lapic_lvt_entry {
 	LVT_LINT0,
 	LVT_LINT1,
 	LVT_ERROR,
+	LVT_CMCI,
 
 	KVM_APIC_MAX_NR_LVT_ENTRIES,
 };
 
-#define APIC_LVTx(x) (APIC_LVTT + 0x10 * (x))
+#define APIC_LVTx(x) ((x) == LVT_CMCI ? APIC_LVTCMCI : APIC_LVTT + 0x10 * (x))
 
 struct kvm_timer {
 	struct hrtimer timer;
Signature · 1 line
2.36.0.550.gb090851708-goog
author
#6 lore raw

PATCH v3 5/7 KVM: x86: Use kcalloc to allocate the mce_banks array.

In reply to Jue Wang

Update the array allocations to use the array allocation API: kcalloc. This sets up pattern for future array allocations, e.g., mci_ctl2_banks.

---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +1 -1
index eb4029660bd9..2eaa6161b227 100644
@@ -11126,7 +11126,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 		goto fail_free_lapic;
 	vcpu->arch.pio_data = page_address(page);
 
-	vcpu->arch.mce_banks = kzalloc(KVM_MAX_MCE_BANKS * sizeof(u64) * 4,
+	vcpu->arch.mce_banks = kcalloc(KVM_MAX_MCE_BANKS * 4, sizeof(u64),
 				       GFP_KERNEL_ACCOUNT);
 	if (!vcpu->arch.mce_banks)
 		goto fail_free_pio_data;
Signature · 1 line
2.36.0.550.gb090851708-goog
author
#7 lore raw

PATCH v3 6/7 KVM: x86: Add emulation for MSR_IA32_MCx_CTL2 MSRs.

In reply to Jue Wang

This series adds the Corrected Machine Check Interrupt (CMCI) and Uncorrectable Error No Action required (UCNA) emulation to KVM. The former is implemented as a LVT CMCI vector. The emulation of UCNA share the MCE emulation infrastructure.

In Machine Check Architecture (MCA), MCG_CMCI_P is the corrected MC error counting/signaling extension present flag, bit 10 of MCG_CAP. When this bit is set, it does not imply CMCI reported corrected MC or UCNA error is supported across all MCA banks. Software should check the availability on a bank by bank basis (i.e. bit 30 in individual IA32_MCi_CTL2 register).

---
 arch/x86/include/asm/kvm_host.h |   1 +
 arch/x86/kvm/x86.c              | 130 ++++++++++++++++++++++----------
 2 files changed, 92 insertions(+), 39 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -0
index ec9830d2aabf..639ef92d01d1 100644
@@ -800,6 +800,7 @@ struct kvm_vcpu_arch {
 	u64 mcg_ctl;
 	u64 mcg_ext_ctl;
 	u64 *mce_banks;
+	u64 *mci_ctl2_banks;
 
 	/* Cache MMIO info */
 	u64 mmio_gva;
arch/x86/kvm/x86.c +91 -39

211 lines not on this page · raw message

Signature · 1 line
2.36.0.550.gb090851708-goog
author
#8 lore raw

PATCH v3 7/7 KVM: x86: Enable MCG_CMCI_P and handle injected UCNAs.

In reply to Jue Wang

This series adds the Corrected Machine Check Interrupt (CMCI) and Uncorrectable Error No Action required (UCNA) emulation to KVM. The former is implemented as a LVT CMCI vector. The emulation of UCNA share the MCE emulation infrastructure.

Both CMCI and UCNA emulation do not depend on hardware. CMCI emulation only depends on vcpu's lapic being available.

---
 arch/x86/kvm/vmx/vmx.c |  1 +
 arch/x86/kvm/x86.c     | 50 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
arch/x86/kvm/vmx/vmx.c +1 -0
index b730d799c26e..63aa2b3d30ca 100644
@@ -8035,6 +8035,7 @@ static __init int hardware_setup(void)
 	}
 
 	kvm_mce_cap_supported |= MCG_LMCE_P;
+	kvm_mce_cap_supported |= MCG_CMCI_P;
 
 	if (pt_mode != PT_MODE_SYSTEM && pt_mode != PT_MODE_HOST_GUEST)
 		return -EINVAL;
arch/x86/kvm/x86.c +50 -0

62 lines not on this page · raw message

Signature · 1 line
2.36.0.550.gb090851708-goog
#9 lore raw
In reply to Jue Wang
Quoted 4 lines · Jue Wang

This patch series implement emulation for Corrected Machine Check Interrupt (CMCI) signaling and UnCorrectable No Action required (UCNA) error injection.

Can you add some selftest or kvm-unit-test coverage for this feature? I imagine selftests would be the best approach so that you can control both the guest and the VMM (e.g. you can inject a CMCI/UCNA error from the test and then make sure it makes it into the guest properly according to how the Local APIC has been programmed).

Quoted 69 lines

UCNA errors signaled via CMCI allow a guest to be notified as soon as uncorrectable memory errors get detected by some background threads, e.g., threads that migrate guest memory across hosts or threads that constantly scan system memory for errors [1].

Upon receiving UCNAs, guest kernel isolates the poisoned pages which may still be free, preventing future accesses that may cause fatal MCEs.

1. https://lore.kernel.org/linux-mm/[email protected]/t/

Patch 1-3 clean up KVM APIC LVT logic.

Patch 4 adds CMCI emulation to lapic.

Patch 5 updates the allocation of mce_array to use array allocation api:
kcalloc.

Patch 6 adds emulation for the per-bank MSR_IA32_MCx_CTL2 MSRs that controls CMCI signaling.

Patch 7 enables MCG_CMCI_P on x86 and handles injected UCNA errors.

v3 changes
- Incorporate feedback from Sean Christopherson <[email protected]>
- Split clean up to KVM APIC LVT logic to 3 patches.
- Put the clean up of mce_array allocation in a separate patch.
- Base the MCi_CTL2 register emulation on Sean's clean up and fix series [2]
- Fix bugs around MCi_CTL2 register offset validation and the free of mci_ctl2_banks array.
- Rewrite the change log with more details in architectural information about CMCI, UCNA and MCG_CMCI_P.
- Fix various comments and wrapping style.

2. https://lore.kernel.org/lkml/[email protected]/T/

v2 chanegs
- Incorporate feedback from Sean Christopherson <[email protected]>
- Split the single patch into 4:
1). clean up KVM APIC LVT logic
2). add CMCI emulation to lapic
3). add emulation of MSR_IA32_MCx_CTL2
4). enable MCG_CMCI_P and handle injected UCNAs
- Fix various style issues.

Jue Wang (7):
KVM: x86: Make APIC_VERSION capture only the magic 0x14UL.
KVM: x86: Fill apic_lvt_mask with enums / explicit entries.
KVM: x86: Add APIC_LVTx() macro.
KVM: x86: Add Corrected Machine Check Interrupt (CMCI) emulation to
lapic.
KVM: x86: Use kcalloc to allocate the mce_banks array.
KVM: x86: Add emulation for MSR_IA32_MCx_CTL2 MSRs.
KVM: x86: Enable MCG_CMCI_P and handle injected UCNAs.

 arch/x86/include/asm/kvm_host.h |   1 +
 arch/x86/kvm/lapic.c            |  58 +++++++---
 arch/x86/kvm/lapic.h            |  15 ++-
 arch/x86/kvm/vmx/vmx.c          |   1 +
 arch/x86/kvm/x86.c              | 182 +++++++++++++++++++++++++-------
 5 files changed, 200 insertions(+), 57 deletions(-)

--
2.36.0.550.gb090851708-goog