diff mbox

x86: Delay skip of emulated hypercall instruction

Message ID 551759d3-cc62-950e-dc5d-8ee8f252c74e@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Paolo Bonzini May 7, 2018, 4:36 p.m. UTC
On 30/04/2018 11:23, Marian Rotariu wrote:
> The IP increment should be done after the hypercall emulation, after
> calling the various handlers. In this way, these handlers can accurately
> identify the the IP of the VMCALL if they need it.
> 
> This patch keeps the same functionality for the Hyper-V handler which does
> not use the return code of the standard kvm_skip_emulated_instruction()
> call.

That is actually a bug.  Let's squash this in the patch (pending testing
of course):
diff mbox

Patch

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 98618e397342..a41cb6d61ca2 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -1265,7 +1265,7 @@  static int kvm_hv_hypercall_complete_userspace(struct kvm_vcpu *vcpu)
 	struct kvm_run *run = vcpu->run;
 
 	kvm_hv_hypercall_set_result(vcpu, run->hyperv.u.hcall.result);
-	return 1;
+	return kvm_skip_emulated_instruction(vcpu);
 }
 
 static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, bool fast, u64 param)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 98deda7694a2..37dd9a9d050a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6677,8 +6677,9 @@  int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
 	int op_64_bit;
 
 	if (kvm_hv_hypercall_enabled(vcpu->kvm)) {
-		kvm_skip_emulated_instruction(vcpu);
-		return kvm_hv_hypercall(vcpu);
+		if (!kvm_hv_hypercall(vcpu))
+			return 0;
+		goto out;
 	}
 
 	nr = kvm_register_read(vcpu, VCPU_REGS_RAX);
@@ -6700,7 +6701,7 @@  int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
 
 	if (kvm_x86_ops->get_cpl(vcpu) != 0) {
 		ret = -KVM_EPERM;
-		goto out;
+		goto out_error;
 	}
 
 	switch (nr) {
@@ -6720,10 +6721,12 @@  int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
 		ret = -KVM_ENOSYS;
 		break;
 	}
-out:
+out_error:
 	if (!op_64_bit)
 		ret = (u32)ret;
 	kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
+
+out:
 	++vcpu->stat.hypercalls;
 	return kvm_skip_emulated_instruction(vcpu);
 }