diff mbox

VMX: Return to userspace on invalid state emulation failure

Message ID 1251086875-21412-1-git-send-email-m.gamal005@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mohammed Gamal Aug. 24, 2009, 4:07 a.m. UTC
Return to userspace instead of repeatedly trying to emulate
instructions that have already failed

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
---
 arch/x86/kvm/vmx.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

Comments

Avi Kivity Aug. 24, 2009, 7:40 a.m. UTC | #1
On 08/24/2009 07:07 AM, Mohammed Gamal wrote:
> Return to userspace instead of repeatedly trying to emulate
> instructions that have already failed
>
> Signed-off-by: Mohammed Gamal<m.gamal005@gmail.com>
> ---
>   arch/x86/kvm/vmx.c |    5 ++++-
>   1 files changed, 4 insertions(+), 1 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 1ee811c..6030671 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -3341,6 +3341,8 @@ static void handle_invalid_guest_state(struct kvm_vcpu *vcpu,
>
>   		if (err != EMULATE_DONE) {
>   			kvm_report_emulation_failure(vcpu, "emulation failure");
> +			kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> +			kvm_run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
>   			break;
>   		}
>
> @@ -3612,7 +3614,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
>   		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
> +		&&  kvm_run->internal.suberror != KVM_INTERNAL_ERROR_EMULATION) {
>   		handle_invalid_guest_state(vcpu, kvm_run);
>   		return;
>   	}
>    

kvm_run->internal.suberror is an uninitialized variable and can contain 
any value.  You need a different communication channel here.
diff mbox

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 1ee811c..6030671 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3341,6 +3341,8 @@  static void handle_invalid_guest_state(struct kvm_vcpu *vcpu,
 
 		if (err != EMULATE_DONE) {
 			kvm_report_emulation_failure(vcpu, "emulation failure");
+			kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+			kvm_run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
 			break;
 		}
 
@@ -3612,7 +3614,8 @@  static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		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
+		&& kvm_run->internal.suberror != KVM_INTERNAL_ERROR_EMULATION) {
 		handle_invalid_guest_state(vcpu, kvm_run);
 		return;
 	}