VMX: Properly return error to userspace on vmentry failure
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
@@ -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
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
@@ -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
Quoted 18 lines · Mohammed Gamal
The vmexit handler returns
KVM_EXIT_UNKNOWNsince there is no handler for vmentry failures. This intercepts vmentry failures and returnsKVM_FAIL_ENTRYto userspace instead.Signed-off-by Mohammed Gamal<[email protected]>--- arch/x86/kvm/vmx.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)arch/x86/kvm/vmx.c +0
-0@@ -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
Avi Kivity
AppliedRe: [PATCH 2/2] VMX: Add constant for invalid guest state exit reason
In reply to Mohammed GamalQuoted 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
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Mohammed Gamal
The vmexit handler returns
KVM_EXIT_UNKNOWNsince there is no handler for vmentry failures. This intercepts vmentry failures and returnsKVM_FAIL_ENTRYto userspace instead.Signed-off-by Mohammed Gamal<[email protected]>---
arch/x86/kvm/vmx.c | 7 +++++++1 files changed, 7 insertions(+), 0 deletions(-)arch/x86/kvm/vmx.c +0
-0@@ -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_ENTRYdue to an exit reason with bit 31 set and vmlauch/vmresume failure (vmx->failset)? 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 compilingcommittee.c: too many arguments to function
Quoted 10 lines · Mohammed Gamal
Quoted 5 lines
How does the user distinguish between
KVM_EXIT_FAIL_ENTRYdue to an exit reason with bit 31 set and vmlauch/vmresume failure (vmx->failset)? 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->failcase 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
Quoted 13 lines · Avi Kivity
Quoted 11 lines · Mohammed Gamal
Quoted 5 lines
How does the user distinguish between
KVM_EXIT_FAIL_ENTRYdue to an exit reason with bit 31 set and vmlauch/vmresume failure (vmx->failset)? 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->failcase 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 compilingcommittee.c: too many arguments to function