Skip to content

Commit 33d1c29

Browse files
Marian Rotariugregkh
authored andcommitted
x86: Delay skip of emulated hypercall instruction
[ Upstream commit 6356ee0 ] 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 <mrotariu@bitdefender.com> [Hyper-V hypercalls also need kvm_skip_emulated_instruction() - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ce44a4d commit 33d1c29

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

arch/x86/kvm/hyperv.c

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

12251225
kvm_hv_hypercall_set_result(vcpu, run->hyperv.u.hcall.result);
1226-
return 1;
1226+
return kvm_skip_emulated_instruction(vcpu);
12271227
}
12281228

12291229
int kvm_hv_hypercall(struct kvm_vcpu *vcpu)

arch/x86/kvm/x86.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6297,12 +6297,13 @@ void kvm_vcpu_deactivate_apicv(struct kvm_vcpu *vcpu)
62976297
int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
62986298
{
62996299
unsigned long nr, a0, a1, a2, a3, ret;
6300-
int op_64_bit, r;
6300+
int op_64_bit;
63016301

6302-
r = kvm_skip_emulated_instruction(vcpu);
6303-
6304-
if (kvm_hv_hypercall_enabled(vcpu->kvm))
6305-
return kvm_hv_hypercall(vcpu);
6302+
if (kvm_hv_hypercall_enabled(vcpu->kvm)) {
6303+
if (!kvm_hv_hypercall(vcpu))
6304+
return 0;
6305+
goto out;
6306+
}
63066307

63076308
nr = kvm_register_read(vcpu, VCPU_REGS_RAX);
63086309
a0 = kvm_register_read(vcpu, VCPU_REGS_RBX);
@@ -6323,7 +6324,7 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
63236324

63246325
if (kvm_x86_ops->get_cpl(vcpu) != 0) {
63256326
ret = -KVM_EPERM;
6326-
goto out;
6327+
goto out_error;
63276328
}
63286329

63296330
switch (nr) {
@@ -6343,12 +6344,14 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
63436344
ret = -KVM_ENOSYS;
63446345
break;
63456346
}
6346-
out:
6347+
out_error:
63476348
if (!op_64_bit)
63486349
ret = (u32)ret;
63496350
kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
6351+
6352+
out:
63506353
++vcpu->stat.hypercalls;
6351-
return r;
6354+
return kvm_skip_emulated_instruction(vcpu);
63526355
}
63536356
EXPORT_SYMBOL_GPL(kvm_emulate_hypercall);
63546357

0 commit comments

Comments
 (0)