Skip to contentSkip to conversation

Fix MCE not cleared on reset

PATCH Applied Avi Kivity 3 participants 11 messages Jul 7, 2010 – Jul 12, 2010

Subsystems (4)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

cover Fix MCE not cleared on reset

Injecting an MCE will often panic the guest kernel. After reset, however, a new MCE will not be recognized because kvm thinks the first one is still being processed.

Fix by exposing the MCE MSRs to userspace, which will clear them on reset.

Avi Kivity (2):
KVM: Expose MCE control MSRs to userspace
KVM: Document MCE banks non-exposure via KVM_GET_MSR_INDEX_LIST

 Documentation/kvm/api.txt |    4 ++++
 arch/x86/kvm/x86.c        |    2 ++
 2 files changed, 6 insertions(+), 0 deletions(-)
author
#1 lore raw

PATCH 1/2 KVM: Expose MCE control MSRs to userspace

Userspace needs to reset and save/restore these MSRs.

The MCE banks are not exposed since their number varies from vcpu to vcpu.

---
 arch/x86/kvm/x86.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +2 -0
index 7070b41..1e12cc5 100644
@@ -744,6 +744,8 @@ static unsigned num_msrs_to_save;
 
 static u32 emulated_msrs[] = {
 	MSR_IA32_MISC_ENABLE,
+	MSR_IA32_MCG_STATUS,
+	MSR_IA32_MCG_CTL,
 };
 
 static int set_efer(struct kvm_vcpu *vcpu, u64 efer)
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH 1/2] KVM: Expose MCE control MSRs to userspace

Hi, Avi,

Quoted 14 lines · Avi Kivity

Userspace needs to reset and save/restore these MSRs.

The MCE banks are not exposed since their number varies from vcpu to vcpu.

---
 arch/x86/kvm/x86.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +0 -0
index 7070b41..1e12cc5 100644

arch/x86/kvm/x86.c static unsigned num_msrs_to_save; · line 748

Quoted 5 lines
arch/x86/kvm/x86.c +2 -0
@@ -744,6 +744,8 @@ static unsigned num_msrs_to_save;
 
 static u32 emulated_msrs[] = {
 	MSR_IA32_MISC_ENABLE,
+	MSR_IA32_MCG_STATUS,
+	MSR_IA32_MCG_CTL,

We need only clear MSR_IA32_MCG_STATUS during reset, but should not clear MSR_IA32_MCG_CTL.

arch/x86/kvm/x86.c static unsigned num_msrs_to_save; · line 751

Quoted 3 lines
arch/x86/kvm/x86.c +0 -0
 };
 
 static int set_efer(struct kvm_vcpu *vcpu, u64 efer)

Best Regards,
Huang Ying

author
#3 lore raw

Re: [PATCH 1/2] KVM: Expose MCE control MSRs to userspace

Quoted 10 lines · Huang Ying

arch/x86/kvm/x86.c static unsigned num_msrs_to_save; · line 748

Quoted 6 lines
  static u32 emulated_msrs[] = {
  	MSR_IA32_MISC_ENABLE,
arch/x86/kvm/x86.c +2 -0
+	MSR_IA32_MCG_STATUS,
+	MSR_IA32_MCG_CTL,

We need only clear MSR_IA32_MCG_STATUS during reset, but should not clear MSR_IA32_MCG_CTL.

Why not?

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw

Re: [PATCH 1/2] KVM: Expose MCE control MSRs to userspace

Quoted 12 lines · Avi Kivity
Quoted 10 lines · Huang Ying

arch/x86/kvm/x86.c static unsigned num_msrs_to_save; · line 748

Quoted 6 lines
  static u32 emulated_msrs[] = {
  	MSR_IA32_MISC_ENABLE,
arch/x86/kvm/x86.c +2 -0
+	MSR_IA32_MCG_STATUS,
+	MSR_IA32_MCG_CTL,

We need only clear MSR_IA32_MCG_STATUS during reset, but should not clear MSR_IA32_MCG_CTL.

Quoted 1 line

Why not?

According to Intel 64 and IA32 Architectures Software Developer's Manual (SDM) Vol 3A (Table 9-1), machine check MSRs should be sticky across reset. Except we need some special processing for MSR_IA32_MCG_STATUS.

And if we clear MSR_IA32_MCG_CTL, the machine check reporting is disabled according to SDM Vol 3A, section 15.3.1.3

Best Regards,
Huang Ying

author
#5 lore raw

Re: [PATCH 1/2] KVM: Expose MCE control MSRs to userspace

Quoted 16 lines · Huang Ying
Quoted 14 lines · Avi Kivity
Quoted 12 lines · Huang Ying

arch/x86/kvm/x86.c static unsigned num_msrs_to_save; · line 748

Quoted 7 lines
       
   static u32 emulated_msrs[] = {
   	MSR_IA32_MISC_ENABLE,
arch/x86/kvm/x86.c +2 -0
+	MSR_IA32_MCG_STATUS,
+	MSR_IA32_MCG_CTL,

We need only clear MSR_IA32_MCG_STATUS during reset, but should not clear MSR_IA32_MCG_CTL.

Quoted 5 lines
Quoted 2 lines

Why not?

According to Intel 64 and IA32 Architectures Software Developer's Manual (SDM) Vol 3A (Table 9-1), machine check MSRs should be sticky across reset.

Well, my copy says:

Machine-Check Architecture Pwr up or Reset: Undefined
INIT: Unchanged

So it seems we're free to clear it. But probably the best thing would be to have the bios initialize it to disabled state?

Note, in any case we have to expose the MSRs for live migration.

Quoted 2 lines

Except we need some special processing for MSR_IA32_MCG_STATUS.

What do you have in mind?

Quoted 3 lines

And if we clear MSR_IA32_MCG_CTL, the machine check reporting is disabled according to SDM Vol 3A, section 15.3.1.3

Won't the kernel reenable MCE? In my testing, the sequence MCE-reset-MCE worked after the patch (whereas it would fail without it).

Signature · 1 line
error compiling committee.c: too many arguments to function
#6 lore raw

Re: [PATCH 1/2] KVM: Expose MCE control MSRs to userspace

Quoted 24 lines · Avi Kivity
Quoted 16 lines · Huang Ying
Quoted 14 lines · Avi Kivity
Quoted 12 lines · Huang Ying

arch/x86/kvm/x86.c static unsigned num_msrs_to_save; · line 748

Quoted 7 lines
       
   static u32 emulated_msrs[] = {
   	MSR_IA32_MISC_ENABLE,
arch/x86/kvm/x86.c +2 -0
+	MSR_IA32_MCG_STATUS,
+	MSR_IA32_MCG_CTL,

We need only clear MSR_IA32_MCG_STATUS during reset, but should not clear MSR_IA32_MCG_CTL.

Quoted 5 lines
Quoted 2 lines

Why not?

According to Intel 64 and IA32 Architectures Software Developer's Manual (SDM) Vol 3A (Table 9-1), machine check MSRs should be sticky across reset.

Quoted 4 lines

Well, my copy says:

Machine-Check Architecture Pwr up or Reset: Undefined
INIT: Unchanged

If my understanding is correct. Pwr up or Reset is cold reboot and INIT is warm reboot. So MCE can be logged after the warm reboot.

Quoted 9 lines

So it seems we're free to clear it. But probably the best thing would be to have the bios initialize it to disabled state?

Note, in any case we have to expose the MSRs for live migration.

Quoted 2 lines

Except we need some special processing for MSR_IA32_MCG_STATUS.

What do you have in mind?

MSR_IA32_MCG_STATUS need to be cleared across reboot.

Quoted 6 lines
Quoted 3 lines

And if we clear MSR_IA32_MCG_CTL, the machine check reporting is disabled according to SDM Vol 3A, section 15.3.1.3

Won't the kernel reenable MCE? In my testing, the sequence MCE-reset-MCE worked after the patch (whereas it would fail without it).

Yes. Because kernel will reenable it. But if we only clear MSR_IA32_MCG_STATUS only, MCE-reset-MCE should work too.

Best Regards,
Huang Ying

author
#7 lore raw

Re: [PATCH 1/2] KVM: Expose MCE control MSRs to userspace

Quoted 33 lines · Huang Ying
Quoted 31 lines · Avi Kivity
Quoted 28 lines · Huang Ying
Quoted 18 lines · Avi Kivity
Quoted 15 lines · Huang Ying

arch/x86/kvm/x86.c static unsigned num_msrs_to_save; · line 748

Quoted 9 lines
           
    static u32 emulated_msrs[] = {
    	MSR_IA32_MISC_ENABLE,
arch/x86/kvm/x86.c +2 -0
+	MSR_IA32_MCG_STATUS,
+	MSR_IA32_MCG_CTL,

We need only clear MSR_IA32_MCG_STATUS during reset, but should not clear MSR_IA32_MCG_CTL.

Quoted 3 lines

Why not?

According to Intel 64 and IA32 Architectures Software Developer's Manual (SDM) Vol 3A (Table 9-1), machine check MSRs should be sticky across reset.

Quoted 8 lines
Quoted 5 lines

Well, my copy says:

Machine-Check Architecture Pwr up or Reset: Undefined
INIT: Unchanged

If my understanding is correct. Pwr up or Reset is cold reboot and INIT is warm reboot. So MCE can be logged after the warm reboot.

Yes. But we're allowed to clear it on a real RESET, just not on INIT.

Our INIT handing is probably broken in this area.

Quoted 6 lines
Quoted 6 lines

So it seems we're free to clear it. But probably the best thing would be to have the bios initialize it to disabled state?

Note, in any case we have to expose the MSRs for live migration.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Except we need some special processing for MSR_IA32_MCG_STATUS.

What do you have in mind?

MSR_IA32_MCG_STATUS need to be cleared across reboot.

Ok.

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

And if we clear MSR_IA32_MCG_CTL, the machine check reporting is disabled according to SDM Vol 3A, section 15.3.1.3

Won't the kernel reenable MCE? In my testing, the sequence MCE-reset-MCE worked after the patch (whereas it would fail without it).

Yes. Because kernel will reenable it. But if we only clear MSR_IA32_MCG_STATUS only, MCE-reset-MCE should work too.

What happens if we reboot into a kernel that doesn't enable MCE?

I guess it doesn't matter: the new kernel will keep cr4.mce cleared and thus MCE will be blocked.

I'd like to keep the patch as is, so live migration works for MCE (we'll need to add bank support). I think there's no problem clearing _CTL on reset. If there is, we can patch qemu not to clear the MSR. Is that acceptable?

Signature · 1 line
error compiling committee.c: too many arguments to function
#8 lore raw

Re: [PATCH 1/2] KVM: Expose MCE control MSRs to userspace

Sorry for late.

On Thu, 2010-07-08 at 17:12 +0800, Avi Kivity wrote:
[..snip..]

Quoted 13 lines
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

And if we clear MSR_IA32_MCG_CTL, the machine check reporting is disabled according to SDM Vol 3A, section 15.3.1.3

Won't the kernel reenable MCE? In my testing, the sequence MCE-reset-MCE worked after the patch (whereas it would fail without it).

Yes. Because kernel will reenable it. But if we only clear MSR_IA32_MCG_STATUS only, MCE-reset-MCE should work too.

What happens if we reboot into a kernel that doesn't enable MCE?

Quoted 7 lines

I guess it doesn't matter: the new kernel will keep cr4.mce cleared and thus MCE will be blocked.

I'd like to keep the patch as is, so live migration works for MCE (we'll need to add bank support). I think there's no problem clearing _CTL on reset. If there is, we can patch qemu not to clear the MSR. Is that acceptable?

Yes. At least for Linux that is OK. Don't know whether Windows will set _CTL during boot.

Best Regards,
Huang Ying

author
#9 lore raw

PATCH 2/2 KVM: Document MCE banks non-exposure via KVM_GET_MSR_INDEX_LIST

In reply to Avi Kivity
---
 Documentation/kvm/api.txt |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Documentation/kvm/api.txt +4 -0
index d9b00f1..179cc51 100644
@@ -126,6 +126,10 @@ user fills in the size of the indices array in nmsrs, and in return
 kvm adjusts nmsrs to reflect the actual number of msrs and fills in
 the indices array with their numbers.
 
+Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
+not returned in the MSR list, as different vcpus can have a different number
+of banks, as set via the KVM_X86_SETUP_MCE ioctl.
+
 4.4 KVM_CHECK_EXTENSION
 
 Capability: basic
Signature · 1 line
1.7.1
#10 lore raw
In reply to Avi Kivity
Quoted 6 lines · Avi Kivity

Injecting an MCE will often panic the guest kernel. After reset, however, a new MCE will not be recognized because kvm thinks the first one is still being processed.

Fix by exposing the MCE MSRs to userspace, which will clear them on reset.

Quoted 7 lines

Avi Kivity (2):
KVM: Expose MCE control MSRs to userspace
KVM: Document MCE banks non-exposure via KVM_GET_MSR_INDEX_LIST

 Documentation/kvm/api.txt |    4 ++++
 arch/x86/kvm/x86.c        |    2 ++
 2 files changed, 6 insertions(+), 0 deletions(-)

Applied, thanks.