Skip to content

Commit 7491b7b

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86: Make APICv inhibit reasons an enum and cleanup naming
Use an enum for the APICv inhibit reasons, there is no meaning behind their values and they most definitely are not "unsigned longs". Rename the various params to "reason" for consistency and clarity (inhibit may be confused as a command, i.e. inhibit APICv, instead of the reason that is getting toggled/checked). No functional change intended. Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20220311043517.17027-2-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 4f4aa80 commit 7491b7b

6 files changed

Lines changed: 35 additions & 31 deletions

File tree

arch/x86/include/asm/kvm_host.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,14 +1042,16 @@ struct kvm_x86_msr_filter {
10421042
struct msr_bitmap_range ranges[16];
10431043
};
10441044

1045-
#define APICV_INHIBIT_REASON_DISABLE 0
1046-
#define APICV_INHIBIT_REASON_HYPERV 1
1047-
#define APICV_INHIBIT_REASON_NESTED 2
1048-
#define APICV_INHIBIT_REASON_IRQWIN 3
1049-
#define APICV_INHIBIT_REASON_PIT_REINJ 4
1050-
#define APICV_INHIBIT_REASON_X2APIC 5
1051-
#define APICV_INHIBIT_REASON_BLOCKIRQ 6
1052-
#define APICV_INHIBIT_REASON_ABSENT 7
1045+
enum kvm_apicv_inhibit {
1046+
APICV_INHIBIT_REASON_DISABLE,
1047+
APICV_INHIBIT_REASON_HYPERV,
1048+
APICV_INHIBIT_REASON_NESTED,
1049+
APICV_INHIBIT_REASON_IRQWIN,
1050+
APICV_INHIBIT_REASON_PIT_REINJ,
1051+
APICV_INHIBIT_REASON_X2APIC,
1052+
APICV_INHIBIT_REASON_BLOCKIRQ,
1053+
APICV_INHIBIT_REASON_ABSENT,
1054+
};
10531055

10541056
struct kvm_arch {
10551057
unsigned long n_used_mmu_pages;
@@ -1403,7 +1405,7 @@ struct kvm_x86_ops {
14031405
void (*enable_nmi_window)(struct kvm_vcpu *vcpu);
14041406
void (*enable_irq_window)(struct kvm_vcpu *vcpu);
14051407
void (*update_cr8_intercept)(struct kvm_vcpu *vcpu, int tpr, int irr);
1406-
bool (*check_apicv_inhibit_reasons)(ulong bit);
1408+
bool (*check_apicv_inhibit_reasons)(enum kvm_apicv_inhibit reason);
14071409
void (*refresh_apicv_exec_ctrl)(struct kvm_vcpu *vcpu);
14081410
void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr);
14091411
void (*hwapic_isr_update)(struct kvm_vcpu *vcpu, int isr);
@@ -1798,10 +1800,9 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
17981800
bool kvm_apicv_activated(struct kvm *kvm);
17991801
void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu);
18001802
void kvm_request_apicv_update(struct kvm *kvm, bool activate,
1801-
unsigned long bit);
1802-
1803+
enum kvm_apicv_inhibit reason);
18031804
void __kvm_request_apicv_update(struct kvm *kvm, bool activate,
1804-
unsigned long bit);
1805+
enum kvm_apicv_inhibit reason);
18051806

18061807
int kvm_emulate_hypercall(struct kvm_vcpu *vcpu);
18071808

arch/x86/kvm/svm/avic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq,
828828
return ret;
829829
}
830830

831-
bool avic_check_apicv_inhibit_reasons(ulong bit)
831+
bool avic_check_apicv_inhibit_reasons(enum kvm_apicv_inhibit reason)
832832
{
833833
ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
834834
BIT(APICV_INHIBIT_REASON_ABSENT) |
@@ -839,7 +839,7 @@ bool avic_check_apicv_inhibit_reasons(ulong bit)
839839
BIT(APICV_INHIBIT_REASON_X2APIC) |
840840
BIT(APICV_INHIBIT_REASON_BLOCKIRQ);
841841

842-
return supported & BIT(bit);
842+
return supported & BIT(reason);
843843
}
844844

845845

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ void __avic_vcpu_put(struct kvm_vcpu *vcpu);
594594
void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu);
595595
void avic_set_virtual_apic_mode(struct kvm_vcpu *vcpu);
596596
void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu);
597-
bool avic_check_apicv_inhibit_reasons(ulong bit);
597+
bool avic_check_apicv_inhibit_reasons(enum kvm_apicv_inhibit reason);
598598
void avic_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr);
599599
void avic_hwapic_isr_update(struct kvm_vcpu *vcpu, int max_isr);
600600
bool avic_dy_apicv_has_pending_interrupt(struct kvm_vcpu *vcpu);

arch/x86/kvm/trace.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,22 +1340,22 @@ TRACE_EVENT(kvm_hv_stimer_cleanup,
13401340
);
13411341

13421342
TRACE_EVENT(kvm_apicv_update_request,
1343-
TP_PROTO(bool activate, unsigned long bit),
1344-
TP_ARGS(activate, bit),
1343+
TP_PROTO(bool activate, int reason),
1344+
TP_ARGS(activate, reason),
13451345

13461346
TP_STRUCT__entry(
13471347
__field(bool, activate)
1348-
__field(unsigned long, bit)
1348+
__field(int, reason)
13491349
),
13501350

13511351
TP_fast_assign(
13521352
__entry->activate = activate;
1353-
__entry->bit = bit;
1353+
__entry->reason = reason;
13541354
),
13551355

1356-
TP_printk("%s bit=%lu",
1356+
TP_printk("%s reason=%u",
13571357
__entry->activate ? "activate" : "deactivate",
1358-
__entry->bit)
1358+
__entry->reason)
13591359
);
13601360

13611361
TRACE_EVENT(kvm_apicv_accept_irq,

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7705,14 +7705,14 @@ static void vmx_hardware_unsetup(void)
77057705
free_kvm_area();
77067706
}
77077707

7708-
static bool vmx_check_apicv_inhibit_reasons(ulong bit)
7708+
static bool vmx_check_apicv_inhibit_reasons(enum kvm_apicv_inhibit reason)
77097709
{
77107710
ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
77117711
BIT(APICV_INHIBIT_REASON_ABSENT) |
77127712
BIT(APICV_INHIBIT_REASON_HYPERV) |
77137713
BIT(APICV_INHIBIT_REASON_BLOCKIRQ);
77147714

7715-
return supported & BIT(bit);
7715+
return supported & BIT(reason);
77167716
}
77177717

77187718
static struct kvm_x86_ops vmx_x86_ops __initdata = {

arch/x86/kvm/x86.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9744,24 +9744,25 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu)
97449744
}
97459745
EXPORT_SYMBOL_GPL(kvm_vcpu_update_apicv);
97469746

9747-
void __kvm_request_apicv_update(struct kvm *kvm, bool activate, ulong bit)
9747+
void __kvm_request_apicv_update(struct kvm *kvm, bool activate,
9748+
enum kvm_apicv_inhibit reason)
97489749
{
97499750
unsigned long old, new;
97509751

97519752
lockdep_assert_held_write(&kvm->arch.apicv_update_lock);
97529753

9753-
if (!static_call(kvm_x86_check_apicv_inhibit_reasons)(bit))
9754+
if (!static_call(kvm_x86_check_apicv_inhibit_reasons)(reason))
97549755
return;
97559756

97569757
old = new = kvm->arch.apicv_inhibit_reasons;
97579758

97589759
if (activate)
9759-
__clear_bit(bit, &new);
9760+
__clear_bit(reason, &new);
97609761
else
9761-
__set_bit(bit, &new);
9762+
__set_bit(reason, &new);
97629763

97639764
if (!!old != !!new) {
9764-
trace_kvm_apicv_update_request(activate, bit);
9765+
trace_kvm_apicv_update_request(activate, reason);
97659766
/*
97669767
* Kick all vCPUs before setting apicv_inhibit_reasons to avoid
97679768
* false positives in the sanity check WARN in svm_vcpu_run().
@@ -9780,17 +9781,19 @@ void __kvm_request_apicv_update(struct kvm *kvm, bool activate, ulong bit)
97809781
unsigned long gfn = gpa_to_gfn(APIC_DEFAULT_PHYS_BASE);
97819782
kvm_zap_gfn_range(kvm, gfn, gfn+1);
97829783
}
9783-
} else
9784+
} else {
97849785
kvm->arch.apicv_inhibit_reasons = new;
9786+
}
97859787
}
97869788

9787-
void kvm_request_apicv_update(struct kvm *kvm, bool activate, ulong bit)
9789+
void kvm_request_apicv_update(struct kvm *kvm, bool activate,
9790+
enum kvm_apicv_inhibit reason)
97889791
{
97899792
if (!enable_apicv)
97909793
return;
97919794

97929795
down_write(&kvm->arch.apicv_update_lock);
9793-
__kvm_request_apicv_update(kvm, activate, bit);
9796+
__kvm_request_apicv_update(kvm, activate, reason);
97949797
up_write(&kvm->arch.apicv_update_lock);
97959798
}
97969799
EXPORT_SYMBOL_GPL(kvm_request_apicv_update);

0 commit comments

Comments
 (0)