Commit fb3146b4 authored by Sean Christopherson's avatar Sean Christopherson

KVM: x86: Add a helper to query whether or not a vCPU has ever run

Add a helper to query if a vCPU has run so that KVM doesn't have to open
code the check on last_vmentry_cpu being set to a magic value.

No functional change intended.
Suggested-by: default avatarXiaoyao Li <xiaoyao.li@intel.com>
Cc: Like Xu <like.xu.linux@gmail.com>
Reviewed-by: default avatarXiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20230311004618.920745-3-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
parent b1932c5c
...@@ -420,7 +420,7 @@ static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2, ...@@ -420,7 +420,7 @@ static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2,
* KVM_SET_CPUID{,2} again. To support this legacy behavior, check * KVM_SET_CPUID{,2} again. To support this legacy behavior, check
* whether the supplied CPUID data is equal to what's already set. * whether the supplied CPUID data is equal to what's already set.
*/ */
if (vcpu->arch.last_vmentry_cpu != -1) { if (kvm_vcpu_has_run(vcpu)) {
r = kvm_cpuid_check_equal(vcpu, e2, nent); r = kvm_cpuid_check_equal(vcpu, e2, nent);
if (r) if (r)
return r; return r;
......
...@@ -5393,7 +5393,7 @@ void kvm_mmu_after_set_cpuid(struct kvm_vcpu *vcpu) ...@@ -5393,7 +5393,7 @@ void kvm_mmu_after_set_cpuid(struct kvm_vcpu *vcpu)
* Changing guest CPUID after KVM_RUN is forbidden, see the comment in * Changing guest CPUID after KVM_RUN is forbidden, see the comment in
* kvm_arch_vcpu_ioctl(). * kvm_arch_vcpu_ioctl().
*/ */
KVM_BUG_ON(vcpu->arch.last_vmentry_cpu != -1, vcpu->kvm); KVM_BUG_ON(kvm_vcpu_has_run(vcpu), vcpu->kvm);
} }
void kvm_mmu_reset_context(struct kvm_vcpu *vcpu) void kvm_mmu_reset_context(struct kvm_vcpu *vcpu)
......
...@@ -83,6 +83,11 @@ static inline unsigned int __shrink_ple_window(unsigned int val, ...@@ -83,6 +83,11 @@ static inline unsigned int __shrink_ple_window(unsigned int val,
void kvm_service_local_tlb_flush_requests(struct kvm_vcpu *vcpu); void kvm_service_local_tlb_flush_requests(struct kvm_vcpu *vcpu);
int kvm_check_nested_events(struct kvm_vcpu *vcpu); int kvm_check_nested_events(struct kvm_vcpu *vcpu);
static inline bool kvm_vcpu_has_run(struct kvm_vcpu *vcpu)
{
return vcpu->arch.last_vmentry_cpu != -1;
}
static inline bool kvm_is_exception_pending(struct kvm_vcpu *vcpu) static inline bool kvm_is_exception_pending(struct kvm_vcpu *vcpu)
{ {
return vcpu->arch.exception.pending || return vcpu->arch.exception.pending ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment