Print Guest VMCS state on vmexit failure
PATCH 1/1 Print Guest VMCS state on vmexit failure
If we fail to handle a VMEXIT for some reason, print out a lot more debugging information about the state of the GUEST VMCS area. This does not fix a bug, but helps a lot when trying to track down the cause of a VMEXIT/VMENTRY failure.
--- arch/x86/kvm/vmx.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-)
arch/x86/kvm/vmx.c +38 -0
@@ -3452,6 +3452,14 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {static const int kvm_vmx_max_exit_handlers =ARRAY_SIZE (kvm_vmx_exit_handlers); +#define PRINT_GUEST_SEGMENT (seg) do { \ + printk(KERN_DEBUG #seg ": SELECTOR 0x%lx, BASE 0x%lx, LIMIT 0x%lx, AR 0x%lx\n", \ + vmcs_readl(GUEST_##seg##_SELECTOR), \ + vmcs_readl(GUEST_##seg##_BASE), \ + vmcs_readl(GUEST_##seg##_LIMIT), \ + vmcs_readl(GUEST_##seg##_AR_BYTES)); \ + while(0) +/* * The guest has exited. See if we can fix it or if we need userspace * assistance.
@@ -3512,6 +3520,36 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)else { vcpu->run->exit_reason =KVM_EXIT_UNKNOWN ; vcpu->run->hw.hardware_exit_reason = exit_reason; + +printk (KERN_DEBUG "GUEST STATE:\n" ); +printk (KERN_DEBUG "CR0: 0x%lx\n" ,vmcs_readl (GUEST_CR0 )); +printk (KERN_DEBUG "CR3: 0x%lx\n" ,vmcs_readl (GUEST_CR3 )); +printk (KERN_DEBUG "CR4: 0x%lx\n" ,vmcs_readl (GUEST_CR4 )); +printk (KERN_DEBUG "VMENTRY CONTROL: 0x%lx\n" , +vmcs_readl (VM_ENTRY_CONTROLS )); +printk (KERN_DEBUG "DR7: 0x%lx\n" ,vmcs_readl (GUEST_DR7 )); +printk (KERN_DEBUG "SYSENTER ESP: 0x%lx\n" , +vmcs_readl (GUEST_SYSENTER_ESP )); +printk (KERN_DEBUG "SYSENTER EIP: 0x%lx\n" , +vmcs_readl (GUEST_SYSENTER_EIP )); + +PRINT_GUEST_SEGMENT (CS ); +PRINT_GUEST_SEGMENT (SS ); +PRINT_GUEST_SEGMENT (DS ); +PRINT_GUEST_SEGMENT (ES ); +PRINT_GUEST_SEGMENT (FS ); +PRINT_GUEST_SEGMENT (GS ); +PRINT_GUEST_SEGMENT (TR ); +PRINT_GUEST_SEGMENT (LDTR ); + +printk (KERN_DEBUG "GDTR: BASE 0x%lx, LIMIT 0x%lx" , +vmcs_readl (GUEST_GDTR_BASE ), +vmcs_readl (GUEST_GDTR_LIMIT )); +printk (KERN_DEBUG "IDTR: BASE 0x%lx, LIMIT 0x%lx" , +vmcs_readl (GUEST_IDTR_BASE ), +vmcs_readl (GUEST_IDTR_LIMIT )); +printk (KERN_DEBUG "RIP: 0x%lx\n" ,vmcs_readl (GUEST_RIP )); +printk (KERN_DEBUG "RFLAGS: 0x%lx\n" ,vmcs_readl (GUEST_RFLAGS )); }return 0 ; }
Signature · 1 line
1.6.0.6
Quoted 55 lines · Chris Lalancette
If we fail to handle a VMEXIT for some reason, print out a lot more debugging information about the state of the GUEST VMCS area. This does not fix a bug, but helps a lot when trying to track down the cause of a VMEXIT/VMENTRY failure.
Signed-off-by Chris Lalancette <[email protected]>--- arch/x86/kvm/vmx.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-)arch/x86/kvm/vmx.c +30
-0@@ -3452,6 +3452,14 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {static const int kvm_vmx_max_exit_handlers =ARRAY_SIZE (kvm_vmx_exit_handlers); +#define PRINT_GUEST_SEGMENT (seg) do { \ + printk(KERN_DEBUG #seg ": SELECTOR 0x%lx, BASE 0x%lx, LIMIT 0x%lx, AR 0x%lx\n", \ + vmcs_readl(GUEST_##seg##_SELECTOR), \ + vmcs_readl(GUEST_##seg##_BASE), \ + vmcs_readl(GUEST_##seg##_LIMIT), \ + vmcs_readl(GUEST_##seg##_AR_BYTES)); \ + while(0) +/* * The guest has exited. See if we can fix it or if we need userspace * assistance. @@ -3512,6 +3520,36 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)else { vcpu->run->exit_reason =KVM_EXIT_UNKNOWN ; vcpu->run->hw.hardware_exit_reason = exit_reason; + +printk (KERN_DEBUG "GUEST STATE:\n" ); +printk (KERN_DEBUG "CR0: 0x%lx\n" ,vmcs_readl (GUEST_CR0 )); +printk (KERN_DEBUG "CR3: 0x%lx\n" ,vmcs_readl (GUEST_CR3 )); +printk (KERN_DEBUG "CR4: 0x%lx\n" ,vmcs_readl (GUEST_CR4 )); +printk (KERN_DEBUG "VMENTRY CONTROL: 0x%lx\n" , +vmcs_readl (VM_ENTRY_CONTROLS )); +printk (KERN_DEBUG "DR7: 0x%lx\n" ,vmcs_readl (GUEST_DR7 )); +printk (KERN_DEBUG "SYSENTER ESP: 0x%lx\n" , +vmcs_readl (GUEST_SYSENTER_ESP )); +printk (KERN_DEBUG "SYSENTER EIP: 0x%lx\n" , +vmcs_readl (GUEST_SYSENTER_EIP )); + +PRINT_GUEST_SEGMENT (CS ); +PRINT_GUEST_SEGMENT (SS ); +PRINT_GUEST_SEGMENT (DS ); +PRINT_GUEST_SEGMENT (ES ); +PRINT_GUEST_SEGMENT (FS ); +PRINT_GUEST_SEGMENT (GS ); +PRINT_GUEST_SEGMENT (TR ); +PRINT_GUEST_SEGMENT (LDTR ); +
arch/x86/kvm/vmx.c static int vmx_handle_exit(struct kvm_vcpu *vcpu) · line 3554
Quoted 10 lines
arch/x86/kvm/vmx.c +8
-0+printk (KERN_DEBUG "GDTR: BASE 0x%lx, LIMIT 0x%lx" , +vmcs_readl (GUEST_GDTR_BASE ), +vmcs_readl (GUEST_GDTR_LIMIT )); +printk (KERN_DEBUG "IDTR: BASE 0x%lx, LIMIT 0x%lx" , +vmcs_readl (GUEST_IDTR_BASE ), +vmcs_readl (GUEST_IDTR_LIMIT )); +printk (KERN_DEBUG "RIP: 0x%lx\n" ,vmcs_readl (GUEST_RIP )); +printk (KERN_DEBUG "RFLAGS: 0x%lx\n" ,vmcs_readl (GUEST_RFLAGS )); }return 0 ;
Move this to separate function may be? vmx_handle_exit() will be hard to read with this blob in the middle.
--
Gleb.
Quoted 60 lines · Gleb Natapov
Quoted 59 lines · Chris Lalancette
If we fail to handle a VMEXIT for some reason, print out a lot more debugging information about the state of the GUEST VMCS area. This does not fix a bug, but helps a lot when trying to track down the cause of a VMEXIT/VMENTRY failure.
Signed-off-by Chris Lalancette <[email protected]>--- arch/x86/kvm/vmx.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-)arch/x86/kvm/vmx.c +34
-0@@ -3452,6 +3452,14 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {static const int kvm_vmx_max_exit_handlers =ARRAY_SIZE (kvm_vmx_exit_handlers); +#define PRINT_GUEST_SEGMENT (seg) do { \ + printk(KERN_DEBUG #seg ": SELECTOR 0x%lx, BASE 0x%lx, LIMIT 0x%lx, AR 0x%lx\n", \ + vmcs_readl(GUEST_##seg##_SELECTOR), \ + vmcs_readl(GUEST_##seg##_BASE), \ + vmcs_readl(GUEST_##seg##_LIMIT), \ + vmcs_readl(GUEST_##seg##_AR_BYTES)); \ + while(0) +/* * The guest has exited. See if we can fix it or if we need userspace * assistance. @@ -3512,6 +3520,36 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)else { vcpu->run->exit_reason =KVM_EXIT_UNKNOWN ; vcpu->run->hw.hardware_exit_reason = exit_reason; + +printk (KERN_DEBUG "GUEST STATE:\n" ); +printk (KERN_DEBUG "CR0: 0x%lx\n" ,vmcs_readl (GUEST_CR0 )); +printk (KERN_DEBUG "CR3: 0x%lx\n" ,vmcs_readl (GUEST_CR3 )); +printk (KERN_DEBUG "CR4: 0x%lx\n" ,vmcs_readl (GUEST_CR4 )); +printk (KERN_DEBUG "VMENTRY CONTROL: 0x%lx\n" , +vmcs_readl (VM_ENTRY_CONTROLS )); +printk (KERN_DEBUG "DR7: 0x%lx\n" ,vmcs_readl (GUEST_DR7 )); +printk (KERN_DEBUG "SYSENTER ESP: 0x%lx\n" , +vmcs_readl (GUEST_SYSENTER_ESP )); +printk (KERN_DEBUG "SYSENTER EIP: 0x%lx\n" , +vmcs_readl (GUEST_SYSENTER_EIP )); + +PRINT_GUEST_SEGMENT (CS ); +PRINT_GUEST_SEGMENT (SS ); +PRINT_GUEST_SEGMENT (DS ); +PRINT_GUEST_SEGMENT (ES ); +PRINT_GUEST_SEGMENT (FS ); +PRINT_GUEST_SEGMENT (GS ); +PRINT_GUEST_SEGMENT (TR ); +PRINT_GUEST_SEGMENT (LDTR ); + +printk (KERN_DEBUG "GDTR: BASE 0x%lx, LIMIT 0x%lx" , +vmcs_readl (GUEST_GDTR_BASE ), +vmcs_readl (GUEST_GDTR_LIMIT )); + printk(KERN_DEBUG "IDTR: BASE 0x%lx, LIMIT 0x%lx",
Quoted 8 lines
arch/x86/kvm/vmx.c static int vmx_handle_exit(struct kvm_vcpu *vcpu) · line 3554
Quoted 6 lines
arch/x86/kvm/vmx.c +4
-0+vmcs_readl (GUEST_IDTR_BASE ), + vmcs_readl(GUEST_IDTR_LIMIT)); +printk (KERN_DEBUG "RIP: 0x%lx\n" ,vmcs_readl (GUEST_RIP )); +printk (KERN_DEBUG "RFLAGS: 0x%lx\n" ,vmcs_readl (GUEST_RFLAGS )); }return 0 ;Move this to separate function may be?
vmx_handle_exit()will be hard to read with this blob in the middle.
The blob is at the end, so I don't think it is terrible, but I see what you mean. I'm happy to move it to a function; I'll repost with that change after seeing if there are other comments.
Thanks,
Signature · 1 line
Chris Lalancette
Quoted 5 lines · Chris Lalancette
If we fail to handle a VMEXIT for some reason, print out a lot more debugging information about the state of the GUEST VMCS area. This does not fix a bug, but helps a lot when trying to track down the cause of a VMEXIT/VMENTRY failure.
register state can just as easily be examined in the qemu monitor.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Chris Lalancette
If we fail to handle a VMEXIT for some reason, print out a lot more debugging information about the state of the GUEST VMCS area. This does not fix a bug, but helps a lot when trying to track down the cause of a VMEXIT/VMENTRY failure.
register state can just as easily be examined in the qemu monitor.
Ah, true. OK, forget this patch.
Signature · 1 line
Chris Lalancette
Hi,
maybe it's stupid question, but is this available also when qemu/kvm is started using libvirt & stuff? I think it uses monitor so it's inaccessible for user no?
n.
Quoted 20 lines · Chris Lalancette
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Chris Lalancette
If we fail to handle a VMEXIT for some reason, print out a lot more debugging information about the state of the GUEST VMCS area. This does not fix a bug, but helps a lot when trying to track down the cause of a VMEXIT/VMENTRY failure.
register state can just as easily be examined in the qemu monitor.
Ah, true. OK, forget this patch.
Signature · 5 lines
Chris Lalancette -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 13 lines
------------------------------------- Nikola CIPRICH LinuxBox.cz, s.r.o. 28. rijna 168, 709 01 Ostrava tel.: +420 596 603 142 fax: +420 596 621 273 mobil: +420 777 093 799 www.linuxbox.cz mobil servis: +420 737 238 656 email servis: [email protected] -------------------------------------
Quoted 4 lines · Nikola Ciprich
Hi,
maybe it's stupid question, but is this available also when qemu/kvm is started using libvirt & stuff? I think it uses monitor so it's inaccessible for user no?
Yes and no. The monitor is inaccessible when using libvirt, but I totally forgot that qemu dumps the register state to stderr before abort()'ing on an unknown vm exit. Libvirt takes the output from stderr and stores it in /var/log/libvirt/qemu/<guestname>. So you would still be able to see this output when using libvirt.
Signature · 1 line
Chris Lalancette
Quoted 7 lines · Chris Lalancette
Quoted 5 lines · Nikola Ciprich
Hi,
maybe it's stupid question, but is this available also when qemu/kvm is started using libvirt& stuff? I think it uses monitor so it's inaccessible for user no?
Quoted 6 lines
Yes and no. The monitor is inaccessible when using libvirt, but I totally forgot that qemu dumps the register state to stderr before abort()'ing on an unknown vm exit. Libvirt takes the output from stderr and stores it in /var/log/libvirt/qemu/<guestname>. So you would still be able to see this output when using libvirt.
We've dropped the stderr part (IIRC), but nothing prevents libvirt from accessing the register state and providing it to the user.
There's also the multiple monitor support which can be used for debugging. Finally, you can connect with gdb (need to dynamically start the gdb server via the monitor, again needs libvirt support).
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.