Skip to contentSkip to conversation

MCE: Fix bug of IA32_MCG_STATUS after system reset

BUGFIX Huang Ying 4 participants 8 messages Jan 5, 2010 – Jan 6, 2010 KVM

lore
Share & tools
lore

Huang Ying

author
#0 lore raw

Now, if we inject a fatal MCE into guest OS, for example Linux, Linux will go panic and then reboot. But if we inject another MCE now, system will reset directly instead of go panic firstly, because MCG_STATUS.MCIP is set to 1 and not cleared after reboot. This is does not follow the behavior in real hardware.

This patch fixes this via set IA32_MCG_STATUS to 0 during system reset.

---
 qemu-kvm-x86.c |    1 +
 1 file changed, 1 insertion(+)
qemu-kvm-x86.c +1 -0
@@ -1015,6 +1015,7 @@ void kvm_arch_load_regs(CPUState *env)
 #endif
     set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME,  env->system_time_msr);
     set_msr_entry(&msrs[n++], MSR_KVM_WALL_CLOCK,  env->wall_clock_msr);
+    set_msr_entry(&msrs[n++], MSR_MCG_STATUS, 0);
 
     rc = kvm_set_msrs(env, msrs, n);
     if (rc == -1)
#1 lore raw

qemu-kvm-x86.c void kvm_arch_load_regs(CPUState *env) · line 1018

Quoted 7 lines
qemu-kvm-x86.c +1 -0
@@ -1015,6 +1015,7 @@ void kvm_arch_load_regs(CPUState *env)
 #endif
     set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME,  env->system_time_msr);
     set_msr_entry(&msrs[n++], MSR_KVM_WALL_CLOCK,  env->wall_clock_msr);
+    set_msr_entry(&msrs[n++], MSR_MCG_STATUS, 0);

Still need to keep EIPV and possibly RIPV, don't we?

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
author
#2 lore raw
Quoted 9 lines · Andi Kleen

qemu-kvm-x86.c void kvm_arch_load_regs(CPUState *env) · line 1018

Quoted 7 lines
qemu-kvm-x86.c +1 -0
@@ -1015,6 +1015,7 @@ void kvm_arch_load_regs(CPUState *env)
 #endif
     set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME,  env->system_time_msr);
     set_msr_entry(&msrs[n++], MSR_KVM_WALL_CLOCK,  env->wall_clock_msr);
+    set_msr_entry(&msrs[n++], MSR_MCG_STATUS, 0);

Still need to keep EIPV and possibly RIPV, don't we?

It appears that EIPV and RIPV is meaningless outside of MCE exception handler. But I will try to check the real hardware behavior.

Best Regards,
Huang Ying

#3 lore raw
In reply to Huang Ying
Quoted 16 lines · Huang Ying

Now, if we inject a fatal MCE into guest OS, for example Linux, Linux will go panic and then reboot. But if we inject another MCE now, system will reset directly instead of go panic firstly, because MCG_STATUS.MCIP is set to 1 and not cleared after reboot. This is does not follow the behavior in real hardware.

This patch fixes this via set IA32_MCG_STATUS to 0 during system reset.

---
  qemu-kvm-x86.c |    1 +
  1 file changed, 1 insertion(+)

qemu-kvm-x86.c void kvm_arch_load_regs(CPUState *env) · line 1020

Quoted 6 lines
qemu-kvm-x86.c +1 -0
@@ -1015,6 +1015,7 @@ void kvm_arch_load_regs(CPUState *env)
  #endif
      set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME,  env->system_time_msr);
      set_msr_entry(&msrs[n++], MSR_KVM_WALL_CLOCK,  env->wall_clock_msr);
+    set_msr_entry(&msrs[n++], MSR_MCG_STATUS, 0);
 
 

Not sure why you reset this in kvm_arch_load_regs(). Shouldn't this be in the cpu reset code?

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

Hi, Avi,

Quoted 14 lines · Avi Kivity
Quoted 13 lines · Huang Ying

Now, if we inject a fatal MCE into guest OS, for example Linux, Linux will go panic and then reboot. But if we inject another MCE now, system will reset directly instead of go panic firstly, because MCG_STATUS.MCIP is set to 1 and not cleared after reboot. This is does not follow the behavior in real hardware.

This patch fixes this via set IA32_MCG_STATUS to 0 during system reset.

---
  qemu-kvm-x86.c |    1 +
  1 file changed, 1 insertion(+)
Quoted 12 lines

qemu-kvm-x86.c void kvm_arch_load_regs(CPUState *env) · line 1020

Quoted 9 lines
qemu-kvm-x86.c +1 -0
@@ -1015,6 +1015,7 @@ void kvm_arch_load_regs(CPUState *env)
  #endif
      set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME,  env->system_time_msr);
      set_msr_entry(&msrs[n++], MSR_KVM_WALL_CLOCK,  env->wall_clock_msr);
+    set_msr_entry(&msrs[n++], MSR_MCG_STATUS, 0);
 
 

Not sure why you reset this in kvm_arch_load_regs(). Shouldn't this be in the cpu reset code?

I found kvm_arch_load_regs() is called by kvm_arch_cpu_reset(), which is called by qemu_kvm_system_reset(). It is not in cpu reset path?

Best Regards,
Huang Ying

#5 lore raw
Quoted 8 lines · Huang Ying
(quoted diff) +0 -0
@@ -1015,6 +1015,7 @@ void kvm_arch_load_regs(CPUState *env)
Quoted 7 lines
Quoted 7 lines
   #endif
       set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME,  env->system_time_msr);
       set_msr_entry(&msrs[n++], MSR_KVM_WALL_CLOCK,  env->wall_clock_msr);

+ set_msr_entry(&msrs[n++], MSR_MCG_STATUS, 0);

Quoted 6 lines
Quoted 3 lines

Not sure why you reset this in kvm_arch_load_regs(). Shouldn't this be in the cpu reset code?

I found kvm_arch_load_regs() is called by kvm_arch_cpu_reset(), which is called by qemu_kvm_system_reset(). It is not in cpu reset path?

It is, but it is also called from many other places, which could cause this msr to be zeroed.

A better solution is to allocate it a field in CPUState, load and save it in kvm_arch_*_regs, and zero it during reset.

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#6 lore raw
Quoted 16 lines · Avi Kivity
Quoted 8 lines · Huang Ying
(quoted diff) +0 -0
@@ -1015,6 +1015,7 @@ void kvm_arch_load_regs(CPUState *env)
Quoted 7 lines
Quoted 7 lines
   #endif
       set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME,  env->system_time_msr);
       set_msr_entry(&msrs[n++], MSR_KVM_WALL_CLOCK,  env->wall_clock_msr);

+ set_msr_entry(&msrs[n++], MSR_MCG_STATUS, 0);

Quoted 6 lines
Quoted 3 lines

Not sure why you reset this in kvm_arch_load_regs(). Shouldn't this be in the cpu reset code?

I found kvm_arch_load_regs() is called by kvm_arch_cpu_reset(), which is called by qemu_kvm_system_reset(). It is not in cpu reset path?

Quoted 5 lines

It is, but it is also called from many other places, which could cause this msr to be zeroed.

A better solution is to allocate it a field in CPUState, load and save it in kvm_arch_*_regs, and zero it during reset.

Yes. You are right. I will fix this.

Best Regards,
Huang Ying

#7 lore raw
Quoted 17 lines · Huang Ying
Quoted 16 lines · Avi Kivity
Quoted 14 lines · Huang Ying
(quoted diff) +0 -0
@@ -1015,6 +1015,7 @@ void kvm_arch_load_regs(CPUState *env)
Quoted 10 lines
Quoted 7 lines
   #endif
       set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME,  env->system_time_msr);
       set_msr_entry(&msrs[n++], MSR_KVM_WALL_CLOCK,  env->wall_clock_msr);

+ set_msr_entry(&msrs[n++], MSR_MCG_STATUS, 0);

Not sure why you reset this in kvm_arch_load_regs(). Shouldn't this be in the cpu reset code?

I found kvm_arch_load_regs() is called by kvm_arch_cpu_reset(), which is called by qemu_kvm_system_reset(). It is not in cpu reset path?

Quoted 7 lines
Quoted 5 lines

It is, but it is also called from many other places, which could cause this msr to be zeroed.

A better solution is to allocate it a field in CPUState, load and save it in kvm_arch_*_regs, and zero it during reset.

Yes. You are right. I will fix this.

BTW, the MCE MSRs are not being migrated. Perhaps you'd like to fix that while at it.