KVM: x86: do not execute halted vcpus (resend)
Quoted 12 lines · Avi Kivity
Quoted 11 lines · Marcelo Tosatti
Quoted 3 lines
Actually it does reproduce. If you reboot twice, the second reboot will hang during reset (with cs:ip = f000:fff0). Plain Windows XP.
OK, easily reproducible by adding a sleep at the start of
qemu_kvm_system_reset.The problem is that the vcpu HLT's between the KBD ioport write and the actual system reset by the IO thread. By then time there will be no event that takes it out of
STATE_HALTED.
Quoted 7 lines
Quoted 4 lines
The following fixes it, however older userspace will remain borked. Alternative is to special case f000:fff0 in-kernel. What is preferred?
Special-case the
kvm_set_sregsioctl with cs:eip f000:fff0 (and cr0.pe=0 for good measure).
KVM: x86: unhalt vcpu0 on reset
Since "KVM: x86: do not execute halted vcpus", HLT by vcpu0 before system reset by the IO thread will hang the guest.
Mark vcpu as runnable in such case.
arch/x86/kvm/x86.c +5 -0
@@ -3959,6 +3959,11 @@ int kvm_arch_vcpu_ioctl_set_sregs(structkvm_set_segment (vcpu, &sregs->tr,VCPU_SREG_TR );kvm_set_segment (vcpu, &sregs->ldt,VCPU_SREG_LDTR ); +if (vcpu->vcpu_id ==0 &&kvm_rip_read (vcpu) ==0xfff0 && + sregs->cs.selector ==0xf000 && sregs->cs.base ==0xffff0000 && + !(vcpu->arch.cr0 &X86_CR0_PE )) + vcpu->arch.mp_state =KVM_MP_STATE_RUNNABLE ; +vcpu_put (vcpu);return 0 ;
Avi Kivity
AppliedQuoted 7 lines · Marcelo Tosatti
KVM: x86: unhalt vcpu0 on reset
Since "KVM: x86: do not execute halted vcpus", HLT by vcpu0 before system reset by the IO thread will hang the guest.
Mark vcpu as runnable in such case.
Applied, thanks. I still want userspace fixed, so please resend the libkvm patch, changelogged and signoffed.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.