KVM: x86: APICv inhibition cleanups
Subsystems (4)
Sean Christopherson
maintainercover KVM: x86: APICv inhibition cleanups
Refactor the APICv inhibition code to use small set/clear wrappers instead of passing an impressively ambiguous "activate" boolean. Opportunistically enhance the related tracepoint so that debugging why a VM can't use APICv is slightly less painful.
Sean Christopherson (3):
KVM: x86: Make APICv inihibit reasons an enum and cleanup naming
KVM: x86: Add wrappers for setting/clearing APICv inhibits
KVM: x86: Trace all APICv inhibit changes and capture overall status
arch/x86/include/asm/kvm_host.h | 39 ++++++++++++++++-------- arch/x86/kvm/hyperv.c | 10 ++++-- arch/x86/kvm/i8254.c | 6 ++-- arch/x86/kvm/svm/avic.c | 4 +-- arch/x86/kvm/svm/svm.c | 11 +++---- arch/x86/kvm/svm/svm.h | 2 +- arch/x86/kvm/trace.h | 22 ++++++++------ arch/x86/kvm/vmx/vmx.c | 4 +-- arch/x86/kvm/x86.c | 54 ++++++++++++++++++++------------- 9 files changed, 90 insertions(+), 62 deletions(-)
base-commit: ce41d078aaa9cf15cbbb4a42878cc6160d76525e
Signature · 1 line
2.35.1.723.g4982287a31-goog
Sean Christopherson
maintainerPATCH 1/3 KVM: x86: Make APICv inihibit 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.
--- arch/x86/include/asm/kvm_host.h | 25 +++++++++++++------------ arch/x86/kvm/svm/avic.c | 4 ++-- arch/x86/kvm/svm/svm.h | 2 +- arch/x86/kvm/trace.h | 12 ++++++------ arch/x86/kvm/vmx/vmx.c | 4 ++-- arch/x86/kvm/x86.c | 19 +++++++++++-------- 6 files changed, 35 insertions(+), 31 deletions(-)
arch/x86/include/asm/kvm_host.h +13 -12
@@ -1047,14 +1047,16 @@ struct kvm_x86_msr_filter {struct msr_bitmap_range ranges[16 ]; }; -#define APICV_INHIBIT_REASON_DISABLE 0 -#define APICV_INHIBIT_REASON_HYPERV 1 -#define APICV_INHIBIT_REASON_NESTED 2 -#define APICV_INHIBIT_REASON_IRQWIN 3 -#define APICV_INHIBIT_REASON_PIT_REINJ 4 -#define APICV_INHIBIT_REASON_X2APIC 5 -#define APICV_INHIBIT_REASON_BLOCKIRQ 6 -#define APICV_INHIBIT_REASON_ABSENT 7 +enum kvm_apicv_inhibit { +APICV_INHIBIT_REASON_DISABLE , +APICV_INHIBIT_REASON_HYPERV , +APICV_INHIBIT_REASON_NESTED , +APICV_INHIBIT_REASON_IRQWIN , +APICV_INHIBIT_REASON_PIT_REINJ , +APICV_INHIBIT_REASON_X2APIC , +APICV_INHIBIT_REASON_BLOCKIRQ , +APICV_INHIBIT_REASON_ABSENT , +};struct kvm_arch {unsigned long n_used_mmu_pages;
@@ -1408,7 +1410,7 @@ struct kvm_x86_ops {void (*enable_nmi_window)(struct kvm_vcpu *vcpu);void (*enable_irq_window)(struct kvm_vcpu *vcpu);void (*update_cr8_intercept)(struct kvm_vcpu *vcpu,int tpr,int irr); -bool (*check_apicv_inhibit_reasons)(ulong bit); +bool (*check_apicv_inhibit_reasons)(enum kvm_apicv_inhibit reason);void (*refresh_apicv_exec_ctrl)(struct kvm_vcpu *vcpu);void (*hwapic_irr_update)(struct kvm_vcpu *vcpu,int max_irr);void (*hwapic_isr_update)(struct kvm_vcpu *vcpu,int isr);
@@ -1803,10 +1805,9 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,bool kvm_apicv_activated (struct kvm *kvm);void kvm_vcpu_update_apicv (struct kvm_vcpu *vcpu);void kvm_request_apicv_update (struct kvm *kvm,bool activate, -unsigned long bit); - +enum kvm_apicv_inhibit reason);void __kvm_request_apicv_update (struct kvm *kvm,bool activate, -unsigned long bit); +enum kvm_apicv_inhibit reason);int kvm_emulate_hypercall (struct kvm_vcpu *vcpu);
arch/x86/kvm/svm/avic.c +2 -2
@@ -822,7 +822,7 @@ int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq,return ret; } -bool avic_check_apicv_inhibit_reasons (ulong bit) +bool avic_check_apicv_inhibit_reasons (enum kvm_apicv_inhibit reason) {ulong supported =BIT (APICV_INHIBIT_REASON_DISABLE ) | BIT(APICV_INHIBIT_REASON_ABSENT) |
@@ -833,7 +833,7 @@ bool avic_check_apicv_inhibit_reasons(ulong bit)BIT (APICV_INHIBIT_REASON_X2APIC ) |BIT (APICV_INHIBIT_REASON_BLOCKIRQ ); -return supported &BIT (bit); +return supported &BIT (reason); }
arch/x86/kvm/svm/svm.h +1 -1
@@ -600,7 +600,7 @@ void __avic_vcpu_put(struct kvm_vcpu *vcpu);void avic_apicv_post_state_restore (struct kvm_vcpu *vcpu);void avic_set_virtual_apic_mode (struct kvm_vcpu *vcpu);void avic_refresh_apicv_exec_ctrl (struct kvm_vcpu *vcpu); -bool avic_check_apicv_inhibit_reasons (ulong bit); +bool avic_check_apicv_inhibit_reasons (enum kvm_apicv_inhibit reason);void avic_hwapic_irr_update (struct kvm_vcpu *vcpu,int max_irr);void avic_hwapic_isr_update (struct kvm_vcpu *vcpu,int max_isr);bool avic_dy_apicv_has_pending_interrupt (struct kvm_vcpu *vcpu);
arch/x86/kvm/trace.h +6 -6
@@ -1340,22 +1340,22 @@ TRACE_EVENT(kvm_hv_stimer_cleanup, );TRACE_EVENT (kvm_apicv_update_request, - TP_PROTO(bool activate, unsigned long bit), -TP_ARGS (activate, bit), + TP_PROTO(bool activate, int reason), +TP_ARGS (activate, reason),TP_STRUCT__entry ( __field(bool, activate) - __field(unsigned long, bit) +__field (int, reason) ),TP_fast_assign ( __entry->activate = activate; - __entry->bit = bit; + __entry->reason = reason; ), -TP_printk ("%s bit=%lu" , +TP_printk ("%s reason=%u" , __entry->activate ?"activate" :"deactivate" , - __entry->bit) + __entry->reason) ); TRACE_EVENT(kvm_apicv_accept_irq,
arch/x86/kvm/vmx/vmx.c +2 -2
@@ -7705,14 +7705,14 @@ static void vmx_hardware_unsetup(void)free_kvm_area (); } -static bool vmx_check_apicv_inhibit_reasons (ulong bit) +static bool vmx_check_apicv_inhibit_reasons (enum kvm_apicv_inhibit reason) {ulong supported =BIT (APICV_INHIBIT_REASON_DISABLE ) |BIT (APICV_INHIBIT_REASON_ABSENT ) |BIT (APICV_INHIBIT_REASON_HYPERV ) |BIT (APICV_INHIBIT_REASON_BLOCKIRQ ); -return supported &BIT (bit); +return supported &BIT (reason); }static struct kvm_x86_ops vmx_x86_ops__initdata = {
arch/x86/kvm/x86.c +11 -8
@@ -9735,24 +9735,25 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu) }EXPORT_SYMBOL_GPL (kvm_vcpu_update_apicv); -void __kvm_request_apicv_update (struct kvm *kvm,bool activate,ulong bit) +void __kvm_request_apicv_update (struct kvm *kvm,bool activate, +enum kvm_apicv_inhibit reason) {unsigned long old, new;lockdep_assert_held_write (&kvm->arch.apicv_update_lock); -if (!static_call (kvm_x86_check_apicv_inhibit_reasons)(bit)) +if (!static_call (kvm_x86_check_apicv_inhibit_reasons)(reason))return ; old = new = kvm->arch.apicv_inhibit_reasons;if (activate) -__clear_bit (bit, &new); +__clear_bit (reason, &new);else -__set_bit (bit, &new); +__set_bit (reason, &new);if (!!old != !!new) { -trace_kvm_apicv_update_request (activate, bit); +trace_kvm_apicv_update_request (activate, reason);/* * Kick all vCPUs before setting apicv_inhibit_reasons to avoid * false positives in the sanity check WARN in svm_vcpu_run().
@@ -9771,17 +9772,19 @@ void __kvm_request_apicv_update(struct kvm *kvm, bool activate, ulong bit)unsigned long gfn =gpa_to_gfn (APIC_DEFAULT_PHYS_BASE );kvm_zap_gfn_range (kvm, gfn, gfn+1 ); } - }else + }else { kvm->arch.apicv_inhibit_reasons = new; + } } -void kvm_request_apicv_update (struct kvm *kvm,bool activate,ulong bit) +void kvm_request_apicv_update (struct kvm *kvm,bool activate, +enum kvm_apicv_inhibit reason) {if (!enable_apicv)return ;down_write (&kvm->arch.apicv_update_lock); -__kvm_request_apicv_update (kvm, activate, bit); +__kvm_request_apicv_update (kvm, activate, reason);up_write (&kvm->arch.apicv_update_lock); }EXPORT_SYMBOL_GPL (kvm_request_apicv_update);
Signature · 1 line
2.35.1.723.g4982287a31-goog
Sean Christopherson
maintainerPATCH 2/3 KVM: x86: Add wrappers for setting/clearing APICv inhibits
In reply to Sean ChristophersonAdd set/clear wrappers for toggling APICv inhibits to make the call sites more readable, and opportunistically rename the inner helpers to align with the new wrappers and to make them more readable as well. Invert the flag from "activate" to "set"; activate is painfully ambiguous as it's not obvious if the inhibit is being activated, or if APICv is being activated, in which case the inhibit is being deactivated.
For the functions that take @set, swap the order of the inhibit reason and @set so that the call sites are visually similar to those that bounce through the wrapper.
--- arch/x86/include/asm/kvm_host.h | 20 ++++++++++++++++---- arch/x86/kvm/hyperv.c | 10 +++++++--- arch/x86/kvm/i8254.c | 6 ++---- arch/x86/kvm/svm/svm.c | 11 +++++------ arch/x86/kvm/trace.h | 8 ++++---- arch/x86/kvm/x86.c | 30 +++++++++++++++--------------- 6 files changed, 49 insertions(+), 36 deletions(-)
arch/x86/include/asm/kvm_host.h +16 -4
@@ -1804,10 +1804,22 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,bool kvm_apicv_activated (struct kvm *kvm);void kvm_vcpu_update_apicv (struct kvm_vcpu *vcpu); -void kvm_request_apicv_update (struct kvm *kvm,bool activate, -enum kvm_apicv_inhibit reason); -void __kvm_request_apicv_update (struct kvm *kvm,bool activate, -enum kvm_apicv_inhibit reason); +void __kvm_set_or_clear_apicv_inhibit (struct kvm *kvm, +enum kvm_apicv_inhibit reason,bool set); +void kvm_set_or_clear_apicv_inhibit (struct kvm *kvm, +enum kvm_apicv_inhibit reason,bool set); + +static inline void kvm_set_apicv_inhibit (struct kvm *kvm, +enum kvm_apicv_inhibit reason) +{ +kvm_set_or_clear_apicv_inhibit (kvm, reason, true); +} + +static inline void kvm_clear_apicv_inhibit (struct kvm *kvm, +enum kvm_apicv_inhibit reason) +{ +kvm_set_or_clear_apicv_inhibit (kvm, reason, false); +}int kvm_emulate_hypercall (struct kvm_vcpu *vcpu);
arch/x86/kvm/hyperv.c +7 -3
@@ -122,9 +122,13 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic *synic,else hv->synic_auto_eoi_used--; -__kvm_request_apicv_update (vcpu->kvm, - !hv->synic_auto_eoi_used, -APICV_INHIBIT_REASON_HYPERV ); +/* +* Inhibit APICv if any vCPU is using SynIC's AutoEOI, which relies on +* the hypervisor to manually inject IRQs. +*/ +__kvm_set_or_clear_apicv_inhibit (vcpu->kvm, +APICV_INHIBIT_REASON_HYPERV , + !!hv->synic_auto_eoi_used);up_write (&vcpu->kvm->arch.apicv_update_lock); }
arch/x86/kvm/i8254.c +2 -4
@@ -305,15 +305,13 @@ void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject)* So, deactivate APICv when PIT is in reinject mode. */ if (reinject) { -kvm_request_apicv_update (kvm, false, -APICV_INHIBIT_REASON_PIT_REINJ ); +kvm_set_apicv_inhibit (kvm,APICV_INHIBIT_REASON_PIT_REINJ );/* The initial state is preserved while ps->reinject == 0. */ kvm_pit_reset_reinject (pit);kvm_register_irq_ack_notifier (kvm, &ps->irq_ack_notifier);kvm_register_irq_mask_notifier (kvm,0 , &pit->mask_notifier); }else { -kvm_request_apicv_update (kvm, true, -APICV_INHIBIT_REASON_PIT_REINJ ); +kvm_clear_apicv_inhibit (kvm,APICV_INHIBIT_REASON_PIT_REINJ );kvm_unregister_irq_ack_notifier (kvm, &ps->irq_ack_notifier);kvm_unregister_irq_mask_notifier (kvm,0 , &pit->mask_notifier); }
arch/x86/kvm/svm/svm.c +5 -6
@@ -2923,7 +2923,7 @@ static int interrupt_window_interception(struct kvm_vcpu *vcpu)* In this case AVIC was temporarily disabled for * requesting the IRQ window and we have to re-enable it. */ -kvm_request_apicv_update (vcpu->kvm, true,APICV_INHIBIT_REASON_IRQWIN ); +kvm_clear_apicv_inhibit (vcpu->kvm,APICV_INHIBIT_REASON_IRQWIN ); ++vcpu->stat.irq_window_exits;return 1 ;
@@ -3521,7 +3521,7 @@ static void svm_enable_irq_window(struct kvm_vcpu *vcpu)* via AVIC. In such case, we need to temporarily disable AVIC, * and fallback to injecting IRQ via V_IRQ. */ -kvm_request_apicv_update (vcpu->kvm, false,APICV_INHIBIT_REASON_IRQWIN ); +kvm_set_apicv_inhibit (vcpu->kvm,APICV_INHIBIT_REASON_IRQWIN );svm_set_vintr (svm); } }
@@ -3948,6 +3948,7 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) {struct vcpu_svm *svm =to_svm (vcpu);struct kvm_cpuid_entry2 *best; +struct kvm *kvm = vcpu->kvm; vcpu->arch.xsaves_enabled =guest_cpuid_has (vcpu,X86_FEATURE_XSAVE ) && boot_cpu_has(X86_FEATURE_XSAVE) &&
@@ -3976,16 +3977,14 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)* is exposed to the guest, disable AVIC. */ if (guest_cpuid_has (vcpu,X86_FEATURE_X2APIC )) -kvm_request_apicv_update (vcpu->kvm, false, -APICV_INHIBIT_REASON_X2APIC ); +kvm_set_apicv_inhibit (kvm,APICV_INHIBIT_REASON_X2APIC );/* * Currently, AVIC does not work with nested virtualization. * So, we disable AVIC when cpuid for SVM is set in the L1 guest. */ if (nested &&guest_cpuid_has (vcpu,X86_FEATURE_SVM )) -kvm_request_apicv_update (vcpu->kvm, false, -APICV_INHIBIT_REASON_NESTED ); +kvm_set_apicv_inhibit (kvm,APICV_INHIBIT_REASON_NESTED ); }init_vmcb_after_set_cpuid (vcpu); }
arch/x86/kvm/trace.h +4 -4
@@ -1340,17 +1340,17 @@ TRACE_EVENT(kvm_hv_stimer_cleanup, ); TRACE_EVENT(kvm_apicv_update_request, - TP_PROTO(bool activate, int reason), - TP_ARGS(activate, reason), + TP_PROTO(int reason, bool activate), + TP_ARGS(reason, activate), TP_STRUCT__entry( - __field(bool, activate) __field(int, reason) + __field(bool, activate) ), TP_fast_assign( - __entry->activate = activate; __entry->reason = reason; + __entry->activate = activate; ), TP_printk("%s reason=%u",
arch/x86/kvm/x86.c +15 -15
@@ -5930,7 +5930,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,smp_wmb (); kvm->arch.irqchip_mode =KVM_IRQCHIP_SPLIT ; kvm->arch.nr_reserved_ioapic_pins = cap->args[0 ]; -kvm_request_apicv_update (kvm, true,APICV_INHIBIT_REASON_ABSENT ); +kvm_clear_apicv_inhibit (kvm,APICV_INHIBIT_REASON_ABSENT ); r =0 ; split_irqchip_unlock:mutex_unlock (&kvm->lock);
@@ -6327,7 +6327,7 @@ long kvm_arch_vm_ioctl(struct file *filp,/* Write kvm->irq_routing before enabling irqchip_in_kernel. */ smp_wmb (); kvm->arch.irqchip_mode =KVM_IRQCHIP_KERNEL ; -kvm_request_apicv_update (kvm, true,APICV_INHIBIT_REASON_ABSENT ); +kvm_clear_apicv_inhibit (kvm,APICV_INHIBIT_REASON_ABSENT ); create_irqchip_unlock:mutex_unlock (&kvm->lock);break ;
@@ -9735,8 +9735,8 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu) }EXPORT_SYMBOL_GPL (kvm_vcpu_update_apicv); -void __kvm_request_apicv_update (struct kvm *kvm,bool activate, -enum kvm_apicv_inhibit reason) +void __kvm_set_or_clear_apicv_inhibit (struct kvm *kvm, +enum kvm_apicv_inhibit reason,bool set) {unsigned long old, new;
@@ -9747,13 +9747,13 @@ void __kvm_request_apicv_update(struct kvm *kvm, bool activate, old = new = kvm->arch.apicv_inhibit_reasons; -if (activate) -__clear_bit (reason, &new); -else +if (set)__set_bit (reason, &new); +else +__clear_bit (reason, &new);if (!!old != !!new) { -trace_kvm_apicv_update_request (activate, reason); +trace_kvm_apicv_update_request (reason, !set);/* * Kick all vCPUs before setting apicv_inhibit_reasons to avoid * false positives in the sanity check WARN in svm_vcpu_run().
@@ -9777,17 +9777,17 @@ void __kvm_request_apicv_update(struct kvm *kvm, bool activate, } } -void kvm_request_apicv_update (struct kvm *kvm,bool activate, -enum kvm_apicv_inhibit reason) +void kvm_set_or_clear_apicv_inhibit (struct kvm *kvm, +enum kvm_apicv_inhibit reason,bool set) {if (!enable_apicv)return ;down_write (&kvm->arch.apicv_update_lock); -__kvm_request_apicv_update (kvm, activate, reason); +__kvm_set_or_clear_apicv_inhibit (kvm, reason, set);up_write (&kvm->arch.apicv_update_lock); } -EXPORT_SYMBOL_GPL (kvm_request_apicv_update); +EXPORT_SYMBOL_GPL (kvm_set_or_clear_apicv_inhibit);static void vcpu_scan_ioapic (struct kvm_vcpu *vcpu) {
@@ -10938,7 +10938,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,static void kvm_arch_vcpu_guestdbg_update_apicv_inhibit (struct kvm *kvm) { -bool inhibit = false; +bool set = false;struct kvm_vcpu *vcpu;unsigned long i;
@@ -10946,11 +10946,11 @@ static void kvm_arch_vcpu_guestdbg_update_apicv_inhibit(struct kvm *kvm)kvm_for_each_vcpu (i, vcpu, kvm) {if (vcpu->guest_debug &KVM_GUESTDBG_BLOCKIRQ ) { - inhibit = true; + set = true;break ; } } -__kvm_request_apicv_update (kvm, !inhibit,APICV_INHIBIT_REASON_BLOCKIRQ ); +__kvm_set_or_clear_apicv_inhibit (kvm,APICV_INHIBIT_REASON_BLOCKIRQ , set);up_write (&kvm->arch.apicv_update_lock); }
Signature · 1 line
2.35.1.723.g4982287a31-goog
Sean Christopherson
maintainerPATCH 3/3 KVM: x86: Trace all APICv inhibit changes and capture overall status
In reply to Sean ChristophersonTrace all APICv inhibit changes instead of just those that result in APICv being (un)inhibited, and log the current state. Debugging why APICv isn't working is frustrating as it's hard to see why APICv is still inhibited, and logging only the first inhibition means unnecessary onion peeling.
Opportunistically drop the export of the tracepoint, it is not and should not be used by vendor code due to the need to serialize toggling via apicv_update_lock.
Note, using the common flow means kvm_apicv_init() switched from atomic to non-atomic bitwise operations. The VM is unreachable at init, so non-atomic is perfectly ok.
--- arch/x86/kvm/trace.h | 18 ++++++++++-------- arch/x86/kvm/x86.c | 29 +++++++++++++++++++---------- 2 files changed, 29 insertions(+), 18 deletions(-)
arch/x86/kvm/trace.h +10 -8
@@ -1339,23 +1339,25 @@ TRACE_EVENT(kvm_hv_stimer_cleanup, __entry->vcpu_id, __entry->timer_index) ); -TRACE_EVENT (kvm_apicv_update_request, - TP_PROTO(int reason, bool activate), -TP_ARGS (reason, activate), +TRACE_EVENT (kvm_apicv_inhibit_changed, + TP_PROTO(int reason, bool set, unsigned long inhibits), +TP_ARGS (reason, set, inhibits),TP_STRUCT__entry ( __field(int, reason) -__field (bool, activate) + __field(bool, set) + __field(unsigned long, inhibits) ),TP_fast_assign ( __entry->reason = reason; - __entry->activate = activate; + __entry->set = set; + __entry->inhibits = inhibits; ), -TP_printk ("%s reason=%u" , - __entry->activate ?"activate" :"deactivate" , - __entry->reason) +TP_printk ("%s reason=%u, inhibits=0x%lx" , + __entry->set ?"set" :"cleared" , + __entry->reason, __entry->inhibits) ); TRACE_EVENT(kvm_apicv_accept_irq,
arch/x86/kvm/x86.c +19 -10
@@ -9053,15 +9053,29 @@ bool kvm_apicv_activated(struct kvm *kvm) }EXPORT_SYMBOL_GPL (kvm_apicv_activated); + +static void set_or_clear_apicv_inhibit (unsigned long *inhibits, +enum kvm_apicv_inhibit reason,bool set) +{ +if (set) +__set_bit (reason, inhibits); +else +__clear_bit (reason, inhibits); + +trace_kvm_apicv_inhibit_changed (reason, set, *inhibits); +} +static void kvm_apicv_init (struct kvm *kvm) { +unsigned long *inhibits = &kvm->arch.apicv_inhibit_reasons; +init_rwsem (&kvm->arch.apicv_update_lock); -set_bit (APICV_INHIBIT_REASON_ABSENT , - &kvm->arch.apicv_inhibit_reasons); +set_or_clear_apicv_inhibit (inhibits,APICV_INHIBIT_REASON_ABSENT , true); +if (!enable_apicv) -set_bit (APICV_INHIBIT_REASON_DISABLE , - &kvm->arch.apicv_inhibit_reasons); +set_or_clear_apicv_inhibit (inhibits, +APICV_INHIBIT_REASON_ABSENT , true); }static void kvm_sched_yield (struct kvm_vcpu *vcpu,unsigned long dest_id)
@@ -9747,13 +9761,9 @@ void __kvm_set_or_clear_apicv_inhibit(struct kvm *kvm, old = new = kvm->arch.apicv_inhibit_reasons; -if (set) -__set_bit (reason, &new); -else -__clear_bit (reason, &new); +set_or_clear_apicv_inhibit (&new, reason, set);if (!!old != !!new) { -trace_kvm_apicv_update_request (reason, !set);/* * Kick all vCPUs before setting apicv_inhibit_reasons to avoid * false positives in the sanity check WARN in svm_vcpu_run().
@@ -12939,7 +12949,6 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_pi_irte_update);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_avic_unaccelerated_access);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_avic_incomplete_ipi);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_avic_ga_log); -EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_apicv_update_request);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_apicv_accept_irq);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_vmgexit_enter);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_vmgexit_exit);
Signature · 1 line
2.35.1.723.g4982287a31-goog
Re: [PATCH 3/3] KVM: x86: Trace all APICv inhibit changes and capture overall status
arch/x86/kvm/x86.c bool kvm_apicv_activated(struct kvm *kvm) · line 9056
Quoted 7 lines · Sean Christopherson
arch/x86/kvm/x86.c +1
-0@@ -9053,15 +9053,29 @@ bool kvm_apicv_activated(struct kvm *kvm) }EXPORT_SYMBOL_GPL (kvm_apicv_activated); +
stray newline.
arch/x86/kvm/x86.c bool kvm_apicv_activated(struct kvm *kvm) · line 9065
Quoted 9 lines
arch/x86/kvm/x86.c +9
-0+static void set_or_clear_apicv_inhibit (unsigned long *inhibits, +enum kvm_apicv_inhibit reason,bool set) +{ +if (set) +__set_bit (reason, inhibits); +else +__clear_bit (reason, inhibits); + +trace_kvm_apicv_inhibit_changed (reason, set, *inhibits);
Note that some calls may not toggle any bit. Do you want to log them? I am afraid that a VM with many vCPUs may get a lot of traces that actually doesn't change inhibits.
Anyway, this series looks good to me.
Re: [PATCH 3/3] KVM: x86: Trace all APICv inhibit changes and capture overall status
Quoted 11 lines · Chao Gao
arch/x86/kvm/x86.c bool kvm_apicv_activated(struct kvm *kvm) · line 9056
Quoted 7 lines · Sean Christopherson
arch/x86/kvm/x86.c +1
-0@@ -9053,15 +9053,29 @@ bool kvm_apicv_activated(struct kvm *kvm) }EXPORT_SYMBOL_GPL (kvm_apicv_activated); +stray newline.
Quoted 13 lines
arch/x86/kvm/x86.c bool kvm_apicv_activated(struct kvm *kvm) · line 9065
Quoted 9 lines
arch/x86/kvm/x86.c +9
-0+static void set_or_clear_apicv_inhibit (unsigned long *inhibits, +enum kvm_apicv_inhibit reason,bool set) +{ +if (set) +__set_bit (reason, inhibits); +else +__clear_bit (reason, inhibits); + +trace_kvm_apicv_inhibit_changed (reason, set, *inhibits);Note that some calls may not toggle any bit. Do you want to log them? I am afraid that a VM with many vCPUs may get a lot of traces that actually doesn't change inhibits.
I also think so.
Best regards,
Maxim Levitsky
Quoted 3 lines
Anyway, this series looks good to me.
Paolo Bonzini
maintainerRe: [PATCH 3/3] KVM: x86: Trace all APICv inhibit changes and capture overall status
Quoted 4 lines · Maxim Levitsky
Quoted 3 lines
Note that some calls may not toggle any bit. Do you want to log them? I am afraid that a VM with many vCPUs may get a lot of traces that actually doesn't change inhibits.
I also think so.
Let's keep Sean's version for now, it may also be useful to see the state changes for all vCPU threads (based on the pid field in the trace). We can always change it later if it's too noisy.
Paolo
Queued, thanks.
Paolo