VMX: Return to userspace on invalid state emulation failure
PATCH 1/1 VMX: Return to userspace on invalid state emulation failure
Return to userspace instead of repeatedly trying to emulate instructions that have already failed
--- arch/x86/kvm/vmx.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
arch/x86/kvm/vmx.c +5 -1
@@ -3337,6 +3337,8 @@ static void handle_invalid_guest_state(struct kvm_vcpu *vcpu)if (err !=EMULATE_DONE ) {kvm_report_emulation_failure (vcpu,"emulation failure" ); + vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; + vcpu->run->internal.suberror =KVM_INTERNAL_ERROR_EMULATION ;break ; }
@@ -3607,7 +3609,9 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) vmx->entry_time =ktime_get ();/* Handle invalid guest state instead of entering VMX */ -if (vmx->emulation_required && emulate_invalid_guest_state) { +if (vmx->emulation_required && emulate_invalid_guest_state + && !(vcpu->run->exit_reason ==KVM_EXIT_INTERNAL_ERROR && + vcpu->run->internal.suberror ==KVM_INTERNAL_ERROR_EMULATION )) {handle_invalid_guest_state (vcpu);return ; }
Signature · 1 line
1.6.0.4
Quoted 23 lines · Mohammed Gamal
Return to userspace instead of repeatedly trying to emulate instructions that have already failed
Signed-off-by Mohammed Gamal<[email protected]>--- arch/x86/kvm/vmx.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)arch/x86/kvm/vmx.c +2
-0@@ -3337,6 +3337,8 @@ static void handle_invalid_guest_state(struct kvm_vcpu *vcpu)if (err !=EMULATE_DONE ) {kvm_report_emulation_failure (vcpu,"emulation failure" ); + vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; + vcpu->run->internal.suberror =KVM_INTERNAL_ERROR_EMULATION ;break ; }
arch/x86/kvm/vmx.c static void vmx_vcpu_run(struct kvm_vcpu *vcpu) · line 3617
Quoted 10 lines
arch/x86/kvm/vmx.c +3
-1@@ -3607,7 +3609,9 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) vmx->entry_time =ktime_get ();/* Handle invalid guest state instead of entering VMX */ -if (vmx->emulation_required&& emulate_invalid_guest_state) { +if (vmx->emulation_required&& emulate_invalid_guest_state + && !(vcpu->run->exit_reason ==KVM_EXIT_INTERNAL_ERROR && + vcpu->run->internal.suberror ==KVM_INTERNAL_ERROR_EMULATION )) {handle_invalid_guest_state (vcpu);return ; }
Still suffers from the same problem. You don't always update vcpu->run->exit_reason, so you can't test it. Best to return a value from handle_invalid_guest_state() (the standard return codes for exit handlers are 1 for return-to-guest, 0 for return-to-host, and -errno to return with an error).
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 29 lines · Avi Kivity
Quoted 28 lines · Mohammed Gamal
Return to userspace instead of repeatedly trying to emulate instructions that have already failed
Signed-off-by Mohammed Gamal<[email protected]>---
arch/x86/kvm/vmx.c | 6 +++++-1 files changed, 5 insertions(+), 1 deletions(-)arch/x86/kvm/vmx.c +0
-0@@ -3337,6 +3337,8 @@ static void handle_invalid_guest_state(struct kvm_vcpu *vcpu) if (err != EMULATE_DONE) {kvm_report_emulation_failure(vcpu, "emulation failure");
+vcpu->run->exit_reason=KVM_EXIT_INTERNAL_ERROR;
+vcpu->run->internal.suberror=KVM_INTERNAL_ERROR_EMULATION;
break;
}arch/x86/kvm/vmx.c +0
-0@@ -3607,7 +3609,9 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) vmx->entry_time = ktime_get();
Quoted 17 lines
Quoted 10 lines
arch/x86/kvm/vmx.c +3
-1/* Handle invalid guest state instead of entering VMX */ - if (vmx->emulation_required&& emulate_invalid_guest_state) { + if (vmx->emulation_required&& emulate_invalid_guest_state + && !(vcpu->run->exit_reason == KVM_EXIT_INTERNAL_ERROR&& + vcpu->run->internal.suberror ==KVM_INTERNAL_ERROR_EMULATION )) { handle_invalid_guest_state(vcpu); return;}
Still suffers from the same problem. You don't always update
vcpu->run->exit_reason, so you can't test it. Best to return a value fromhandle_invalid_guest_state()(the standard return codes for exit handlers are 1 for return-to-guest, 0 for return-to-host, and -errno to return with an error).
I was thinking of the same idea since I was also concerned about vcpu->run->exit_reason not being updated. But how can we interpret the return values of handle_invalid_guest_state() inside vmx_vcpu_run() since it doesn't have a return value. Or would it be better to move handle_invalid_guest_state() to the standard vmx exit handlers?
Quoted 49 lines · Mohammed Gamal
Quoted 29 lines · Avi Kivity
Quoted 27 lines · Mohammed Gamal
Return to userspace instead of repeatedly trying to emulate instructions that have already failed
Signed-off-by Mohammed Gamal<[email protected]>--- arch/x86/kvm/vmx.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)arch/x86/kvm/vmx.c +2
-0@@ -3337,6 +3337,8 @@ static void handle_invalid_guest_state(struct kvm_vcpu *vcpu)if (err !=EMULATE_DONE ) {kvm_report_emulation_failure (vcpu,"emulation failure"); + vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; + vcpu->run->internal.suberror =KVM_INTERNAL_ERROR_EMULATION ;break; }arch/x86/kvm/vmx.c +0
-0@@ -3607,7 +3609,9 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) vmx->entry_time =ktime_get ();Quoted 18 lines
Quoted 11 lines
arch/x86/kvm/vmx.c +3
-1/* Handle invalid guest state instead of entering VMX */ -if (vmx->emulation_required&& emulate_invalid_guest_state) { +if (vmx->emulation_required&& emulate_invalid_guest_state +&& !(vcpu->run->exit_reason ==KVM_EXIT_INTERNAL_ERROR && + vcpu->run->internal.suberror ==KVM_INTERNAL_ERROR_EMULATION )) {handle_invalid_guest_state (vcpu);return ;}Still suffers from the same problem. You don't always update
vcpu->run->exit_reason, so you can't test it. Best to return a value fromhandle_invalid_guest_state()(the standard return codes for exit handlers are 1 for return-to-guest, 0 for return-to-host, and -errno to return with an error).
Quoted 6 lines
I was thinking of the same idea since I was also concerned about
vcpu->run->exit_reasonnot being updated. But how can we interpret the return values ofhandle_invalid_guest_state()insidevmx_vcpu_run()since it doesn't have a return value. Or would it be better to movehandle_invalid_guest_state()to the standard vmx exit handlers?
We can move the call to vmx_handle_exit(). We have a check for emulate_invalid_guest_state there anyway. I don't think it should be a standard exit handler since there is no exit_reason for it.
Signature · 1 line
error compiling committee.c: too many arguments to function