Skip to contentSkip to conversation

VMX: Properly return error to userspace on vmentry failure

PATCH Applied Mohammed Gamal 2 participants 7 messages May 23, 2010 – May 25, 2010

Subsystems (3)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 VMX: Properly return error to userspace on vmentry failure

The vmexit handler returns KVM_EXIT_UNKNOWN since there is no handler for vmentry failures. This intercepts vmentry failures and returns KVM_FAIL_ENTRY to userspace instead.

---
 arch/x86/kvm/vmx.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
arch/x86/kvm/vmx.c +7 -0
index 99ae513..4edcffb 100644
@@ -3665,6 +3665,13 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
 	if (enable_ept && is_paging(vcpu))
 		vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
 
+	if (exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY) {
+		vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
+		vcpu->run->fail_entry.hardware_entry_failure_reason
+			= exit_reason & ~VMX_EXIT_REASONS_FAILED_VMENTRY;
+		return 0;
+	}
+
 	if (unlikely(vmx->fail)) {
 		vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
 		vcpu->run->fail_entry.hardware_entry_failure_reason
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 2/2 VMX: Add constant for invalid guest state exit reason

For the sake of completeness, this patch adds a symbolic constant for VMX exit reason 0x21 (invalid guest state).

---
 arch/x86/include/asm/vmx.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/include/asm/vmx.h +1 -0
index 9e6779f..104cf86 100644
@@ -257,6 +257,7 @@ enum vmcs_field {
 #define EXIT_REASON_IO_INSTRUCTION      30
 #define EXIT_REASON_MSR_READ            31
 #define EXIT_REASON_MSR_WRITE           32
+#define EXIT_REASON_INVALID_STATE	33
 #define EXIT_REASON_MWAIT_INSTRUCTION   36
 #define EXIT_REASON_MONITOR_INSTRUCTION 39
 #define EXIT_REASON_PAUSE_INSTRUCTION   40
Signature · 1 line
1.7.0.4
#3 lore raw
In reply to Mohammed Gamal
Quoted 18 lines · Mohammed Gamal

The vmexit handler returns KVM_EXIT_UNKNOWN since there is no handler for vmentry failures. This intercepts vmentry failures and returns KVM_FAIL_ENTRY to userspace instead.

---
  arch/x86/kvm/vmx.c |    7 +++++++
  1 files changed, 7 insertions(+), 0 deletions(-)
arch/x86/kvm/vmx.c +0 -0
index 99ae513..4edcffb 100644
@@ -3665,6 +3665,13 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
  	if (enable_ept&&  is_paging(vcpu))
  		vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
 

arch/x86/kvm/vmx.c static int vmx_handle_exit(struct kvm_vcpu *vcpu) · line 3677

Quoted 10 lines
arch/x86/kvm/vmx.c +7 -0
+	if (exit_reason&  VMX_EXIT_REASONS_FAILED_VMENTRY) {
+		vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
+		vcpu->run->fail_entry.hardware_entry_failure_reason
+			= exit_reason&  ~VMX_EXIT_REASONS_FAILED_VMENTRY;
+		return 0;
+	}
+
  	if (unlikely(vmx->fail)) {
  		vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
  		vcpu->run->fail_entry.hardware_entry_failure_reason

How does the user distinguish between KVM_EXIT_FAIL_ENTRY due to an exit reason with bit 31 set and vmlauch/vmresume failure (vmx->fail set)? We need separate exit codes (with documentation in api.txt).

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

Re: [PATCH 2/2] VMX: Add constant for invalid guest state exit reason

In reply to Mohammed Gamal
Quoted 3 lines · Mohammed Gamal

For the sake of completeness, this patch adds a symbolic constant for VMX exit reason 0x21 (invalid guest state).

Applied, thanks.

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
In reply to Avi Kivity
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Mohammed Gamal

The vmexit handler returns KVM_EXIT_UNKNOWN since there is no handler for vmentry failures. This intercepts vmentry failures and returns KVM_FAIL_ENTRY to userspace instead.

---
 arch/x86/kvm/vmx.c |    7 +++++++

 1 files changed, 7 insertions(+), 0 deletions(-)
arch/x86/kvm/vmx.c +0 -0
index 99ae513..4edcffb 100644
@@ -3665,6 +3665,13 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
        if (enable_ept&&  is_paging(vcpu))
                vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
 
Quoted 15 lines
Quoted 11 lines
arch/x86/kvm/vmx.c +7 -0
+       if (exit_reason&  VMX_EXIT_REASONS_FAILED_VMENTRY) {
+               vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
+               vcpu->run->fail_entry.hardware_entry_failure_reason
+                       = exit_reason&  ~VMX_EXIT_REASONS_FAILED_VMENTRY;
+               return 0;
+       }
+
        if (unlikely(vmx->fail)) {
                vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;

               vcpu->run->fail_entry.hardware_entry_failure_reason

How does the user distinguish between KVM_EXIT_FAIL_ENTRY due to an exit reason with bit 31 set and vmlauch/vmresume failure (vmx->fail set)?  We need separate exit codes (with documentation in api.txt).

In both cases the vm fails entry, and I don't think the hardware entry failure reason codes would overlap between the vmx->fail case and exit reasons with bit 31 set, so why should there be such distinction between both cases?

Quoted 5 lines

--
error compiling committee.c: too many arguments to function

#5 lore raw
Quoted 10 lines · Mohammed Gamal
Quoted 5 lines

How does the user distinguish between KVM_EXIT_FAIL_ENTRY due to an exit reason with bit 31 set and vmlauch/vmresume failure (vmx->fail set)? We need separate exit codes (with documentation in api.txt).

In both cases the vm fails entry, and I don't think the hardware entry failure reason codes would overlap between the vmx->fail case and exit reasons with bit 31 set, so why should there be such distinction between both cases?

Only 5 more error codes (28->33) and we have overlap.

If you return the new codes with bit 31 still set then we can use the existing KVM_EXIT_FAIL_ENTRY.

Signature · 1 line
error compiling committee.c: too many arguments to function
#6 lore raw
Quoted 13 lines · Avi Kivity
Quoted 11 lines · Mohammed Gamal
Quoted 5 lines

How does the user distinguish between KVM_EXIT_FAIL_ENTRY due to an exit reason with bit 31 set and vmlauch/vmresume failure (vmx->fail set)?  We need separate exit codes (with documentation in api.txt).

In both cases the vm fails entry, and I don't think the hardware entry failure reason codes would overlap between the vmx->fail case and exit reasons with bit 31 set, so why should there be such distinction between both cases?

Quoted 4 lines

Only 5 more error codes (28->33) and we have overlap.

If you return the new codes with bit 31 still set then we can use the existing KVM_EXIT_FAIL_ENTRY.

That'd be a better idea.

Quoted 6 lines

--
error compiling committee.c: too many arguments to function