Skip to content

Commit 05a518b

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86: Bump hypercall stat prior to fully completing hypercall
Increment the "hypercalls" stat for KVM hypercalls as soon as KVM knows it will skip the guest instruction, i.e. once KVM is committed to emulating the hypercall. Waiting until completion adds no known value, and creates a discrepancy where the stat will be bumped if KVM exits to userspace as a result of trying to skip the instruction, but not if the hypercall itself exits. Handling the stat in common code will also avoid the need for another helper to dedup code when TDX comes along (TDX needs a separate completion path due to GPR usage differences). Signed-off-by: Sean Christopherson <[email protected]> Reviewed-by: Binbin Wu <[email protected]> Reviewed-by: Kai Huang <[email protected]> Reviewed-by: Tom Lendacky <[email protected]> Reviewed-by: Xiaoyao Li <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 13b64ce commit 05a518b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

arch/x86/kvm/x86.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9979,7 +9979,6 @@ static int complete_hypercall_exit(struct kvm_vcpu *vcpu)
99799979
if (!is_64_bit_hypercall(vcpu))
99809980
ret = (u32)ret;
99819981
kvm_rax_write(vcpu, ret);
9982-
++vcpu->stat.hypercalls;
99839982
return kvm_skip_emulated_instruction(vcpu);
99849983
}
99859984

@@ -9990,6 +9989,8 @@ unsigned long __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr,
99909989
{
99919990
unsigned long ret;
99929991

9992+
++vcpu->stat.hypercalls;
9993+
99939994
trace_kvm_hypercall(nr, a0, a1, a2, a3);
99949995

99959996
if (!op_64_bit) {
@@ -10068,7 +10069,6 @@ unsigned long __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr,
1006810069

1006910070
WARN_ON_ONCE(vcpu->run->hypercall.flags & KVM_EXIT_HYPERCALL_MBZ);
1007010071
vcpu->arch.complete_userspace_io = complete_hypercall_exit;
10071-
/* stat is incremented on completion. */
1007210072
return 0;
1007310073
}
1007410074
default:
@@ -10077,7 +10077,6 @@ unsigned long __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr,
1007710077
}
1007810078

1007910079
out:
10080-
++vcpu->stat.hypercalls;
1008110080
return ret;
1008210081
}
1008310082
EXPORT_SYMBOL_GPL(__kvm_emulate_hypercall);

0 commit comments

Comments
 (0)