Skip to content

Commit 6fbef86

Browse files
jsmattsonjrsean-jc
authored andcommitted
KVM: x86: Replace growing set of *_in_guest bools with a u64
Store each "disabled exit" boolean in a single bit rather than a byte. No functional change intended. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Jim Mattson <jmattson@google.com> Link: https://lore.kernel.org/r/20250530185239.2335185-2-jmattson@google.com Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Link: https://lore.kernel.org/r/20250626001225.744268-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e88cfd5 commit 6fbef86

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,10 +1392,7 @@ struct kvm_arch {
13921392

13931393
gpa_t wall_clock;
13941394

1395-
bool mwait_in_guest;
1396-
bool hlt_in_guest;
1397-
bool pause_in_guest;
1398-
bool cstate_in_guest;
1395+
u64 disabled_exits;
13991396

14001397
unsigned long irq_sources_bitmap;
14011398
s64 kvmclock_offset;

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5012,7 +5012,7 @@ static int svm_vm_init(struct kvm *kvm)
50125012
}
50135013

50145014
if (!pause_filter_count || !pause_filter_thresh)
5015-
kvm->arch.pause_in_guest = true;
5015+
kvm_disable_exits(kvm, KVM_X86_DISABLE_EXITS_PAUSE);
50165016

50175017
if (enable_apicv) {
50185018
int ret = avic_vm_init(kvm);

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7515,7 +7515,7 @@ int vmx_vcpu_create(struct kvm_vcpu *vcpu)
75157515
int vmx_vm_init(struct kvm *kvm)
75167516
{
75177517
if (!ple_gap)
7518-
kvm->arch.pause_in_guest = true;
7518+
kvm_disable_exits(kvm, KVM_X86_DISABLE_EXITS_PAUSE);
75197519

75207520
if (boot_cpu_has(X86_BUG_L1TF) && enable_ept) {
75217521
switch (l1tf_mitigation) {

arch/x86/kvm/x86.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6616,14 +6616,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
66166616
(cap->args[0] & ~KVM_X86_DISABLE_EXITS_PAUSE))
66176617
pr_warn_once(SMT_RSB_MSG);
66186618

6619-
if (cap->args[0] & KVM_X86_DISABLE_EXITS_PAUSE)
6620-
kvm->arch.pause_in_guest = true;
6621-
if (cap->args[0] & KVM_X86_DISABLE_EXITS_MWAIT)
6622-
kvm->arch.mwait_in_guest = true;
6623-
if (cap->args[0] & KVM_X86_DISABLE_EXITS_HLT)
6624-
kvm->arch.hlt_in_guest = true;
6625-
if (cap->args[0] & KVM_X86_DISABLE_EXITS_CSTATE)
6626-
kvm->arch.cstate_in_guest = true;
6619+
kvm_disable_exits(kvm, cap->args[0]);
66276620
r = 0;
66286621
disable_exits_unlock:
66296622
mutex_unlock(&kvm->lock);

arch/x86/kvm/x86.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,24 +499,29 @@ static inline u64 nsec_to_cycles(struct kvm_vcpu *vcpu, u64 nsec)
499499
__rem; \
500500
})
501501

502+
static inline void kvm_disable_exits(struct kvm *kvm, u64 mask)
503+
{
504+
kvm->arch.disabled_exits |= mask;
505+
}
506+
502507
static inline bool kvm_mwait_in_guest(struct kvm *kvm)
503508
{
504-
return kvm->arch.mwait_in_guest;
509+
return kvm->arch.disabled_exits & KVM_X86_DISABLE_EXITS_MWAIT;
505510
}
506511

507512
static inline bool kvm_hlt_in_guest(struct kvm *kvm)
508513
{
509-
return kvm->arch.hlt_in_guest;
514+
return kvm->arch.disabled_exits & KVM_X86_DISABLE_EXITS_HLT;
510515
}
511516

512517
static inline bool kvm_pause_in_guest(struct kvm *kvm)
513518
{
514-
return kvm->arch.pause_in_guest;
519+
return kvm->arch.disabled_exits & KVM_X86_DISABLE_EXITS_PAUSE;
515520
}
516521

517522
static inline bool kvm_cstate_in_guest(struct kvm *kvm)
518523
{
519-
return kvm->arch.cstate_in_guest;
524+
return kvm->arch.disabled_exits & KVM_X86_DISABLE_EXITS_CSTATE;
520525
}
521526

522527
static inline bool kvm_notify_vmexit_enabled(struct kvm *kvm)

0 commit comments

Comments
 (0)