Skip to content

Commit 6356ee0

Browse files
Marian Rotariubonzini
authored andcommitted
x86: Delay skip of emulated hypercall instruction
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. Signed-off-by: Marian Rotariu <[email protected]> [Hyper-V hypercalls also need kvm_skip_emulated_instruction() - Paolo] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent ddc9cfb commit 6356ee0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

arch/x86/kvm/hyperv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ static int kvm_hv_hypercall_complete_userspace(struct kvm_vcpu *vcpu)
12651265
struct kvm_run *run = vcpu->run;
12661266

12671267
kvm_hv_hypercall_set_result(vcpu, run->hyperv.u.hcall.result);
1268-
return 1;
1268+
return kvm_skip_emulated_instruction(vcpu);
12691269
}
12701270

12711271
static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, bool fast, u64 param)

arch/x86/kvm/x86.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6671,12 +6671,13 @@ void kvm_vcpu_deactivate_apicv(struct kvm_vcpu *vcpu)
66716671
int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
66726672
{
66736673
unsigned long nr, a0, a1, a2, a3, ret;
6674-
int op_64_bit, r;
6674+
int op_64_bit;
66756675

6676-
r = kvm_skip_emulated_instruction(vcpu);
6677-
6678-
if (kvm_hv_hypercall_enabled(vcpu->kvm))
6679-
return kvm_hv_hypercall(vcpu);
6676+
if (kvm_hv_hypercall_enabled(vcpu->kvm)) {
6677+
if (!kvm_hv_hypercall(vcpu))
6678+
return 0;
6679+
goto out;
6680+
}
66806681

66816682
nr = kvm_register_read(vcpu, VCPU_REGS_RAX);
66826683
a0 = kvm_register_read(vcpu, VCPU_REGS_RBX);
@@ -6697,7 +6698,7 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
66976698

66986699
if (kvm_x86_ops->get_cpl(vcpu) != 0) {
66996700
ret = -KVM_EPERM;
6700-
goto out;
6701+
goto out_error;
67016702
}
67026703

67036704
switch (nr) {
@@ -6717,12 +6718,14 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
67176718
ret = -KVM_ENOSYS;
67186719
break;
67196720
}
6720-
out:
6721+
out_error:
67216722
if (!op_64_bit)
67226723
ret = (u32)ret;
67236724
kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
6725+
6726+
out:
67246727
++vcpu->stat.hypercalls;
6725-
return r;
6728+
return kvm_skip_emulated_instruction(vcpu);
67266729
}
67276730
EXPORT_SYMBOL_GPL(kvm_emulate_hypercall);
67286731

0 commit comments

Comments
 (0)