KVM/x86: Enhancements to static calls
Subsystems (5)
v4 cover KVM/x86: Enhancements to static calls
This patchset introduces the kvm_x86_call() and kvm_pmu_call() macros to streamline the usage of static calls of kvm_x86_ops and kvm_pmu_ops. The current static_call() usage is a bit verbose and can lead to code alignment challenges, and the addition of kvm_x86_ prefix to hooks at the static_call() sites hinders code readability and navigation. The use of static_call_cond() is essentially the same as static_call() on x86, so it is replaced by static_call() to simplify the code. The changes have gone through my tests (guest launch, a few vPMU tests, live migration tests) without an issue.
v3->v4 change:
- Rename KVM_X86_CALL() to kvm_x86_call() and KVM_PMU_CALL() to kvm_pmu_call() as they resemble functions, so the lower-case style looks more readable.
v2->v3 changes:
- Change the KVM_X86_CALL() definition to have the parameters in their owen paratheses.
- Update the .get_cpl() hook in pmu.c to use KVM_X86_CALL(). (it was omitted in v2)
v1->v2 changes:
- Replace static_call_cond() with static_call()
- Rename KVM_X86_SC to KVM_X86_CALL, and updated all the call sites
- Add KVM_PMU_CALL()
- Add patch 4 and 5 to review the idea of removing KVM_X86_OP_OPTIONAL
Wei Wang (3):
KVM: x86: Replace static_call_cond() with static_call()
KVM: x86: Introduce kvm_x86_call() to simplify static calls of
kvm_x86_ops
KVM: x86/pmu: Add kvm_pmu_call() to simplify static calls of
kvm_pmu_ops
arch/x86/include/asm/kvm_host.h | 11 +- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/hyperv.c | 6 +- arch/x86/kvm/irq.c | 2 +- arch/x86/kvm/kvm_cache_regs.h | 10 +- arch/x86/kvm/lapic.c | 42 +++-- arch/x86/kvm/lapic.h | 2 +- arch/x86/kvm/mmu.h | 6 +- arch/x86/kvm/mmu/mmu.c | 4 +- arch/x86/kvm/mmu/spte.c | 4 +- arch/x86/kvm/pmu.c | 29 +-- arch/x86/kvm/smm.c | 44 ++--- arch/x86/kvm/trace.h | 15 +- arch/x86/kvm/x86.c | 322 ++++++++++++++++---------------- arch/x86/kvm/x86.h | 2 +- arch/x86/kvm/xen.c | 4 +- 16 files changed, 259 insertions(+), 246 deletions(-)
base-commit: aec147c18856fa7115e14b9ad6a91c3ed2cf2e19
Signature · 1 line
2.27.0
PATCH v4 1/3 KVM: x86: Replace static_call_cond() with static_call()
The use of static_call_cond() is essentially the same as static_call() on x86 (e.g. static_call() now handles a NULL pointer as a NOP), so replace it with static_call() to simplify the code.
--- arch/x86/include/asm/kvm_host.h | 4 ++-- arch/x86/kvm/irq.c | 2 +- arch/x86/kvm/lapic.c | 24 ++++++++++++------------ arch/x86/kvm/pmu.c | 6 +++--- arch/x86/kvm/x86.c | 24 ++++++++++++------------ 5 files changed, 30 insertions(+), 30 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -2
@@ -2280,12 +2280,12 @@ static inline bool kvm_irq_is_postable(struct kvm_lapic_irq *irq)static inline void kvm_arch_vcpu_blocking (struct kvm_vcpu *vcpu) { -static_call_cond (kvm_x86_vcpu_blocking)(vcpu); +static_call (kvm_x86_vcpu_blocking)(vcpu); }static inline void kvm_arch_vcpu_unblocking (struct kvm_vcpu *vcpu) { -static_call_cond (kvm_x86_vcpu_unblocking)(vcpu); +static_call (kvm_x86_vcpu_unblocking)(vcpu); }static inline int kvm_cpu_get_apicid (int mps_cpu)
arch/x86/kvm/irq.c +1 -1
@@ -157,7 +157,7 @@ void __kvm_migrate_timers(struct kvm_vcpu *vcpu) {__kvm_migrate_apic_timer (vcpu);__kvm_migrate_pit_timer (vcpu); -static_call_cond (kvm_x86_migrate_timers)(vcpu); +static_call (kvm_x86_migrate_timers)(vcpu); }bool kvm_arch_irqfd_allowed (struct kvm *kvm,struct kvm_irqfd *args)
arch/x86/kvm/lapic.c +12 -12
@@ -728,7 +728,7 @@ static inline void apic_clear_irr(int vec, struct kvm_lapic *apic)if (unlikely (apic->apicv_active)) {/* need to update RVI */ kvm_lapic_clear_vector (vec, apic->regs +APIC_IRR ); -static_call_cond (kvm_x86_hwapic_irr_update)(apic->vcpu, +static_call (kvm_x86_hwapic_irr_update)(apic->vcpu,apic_find_highest_irr (apic)); }else { apic->irr_pending = false;
@@ -755,7 +755,7 @@ static inline void apic_set_isr(int vec, struct kvm_lapic *apic)* just set SVI. */ if (unlikely (apic->apicv_active)) -static_call_cond (kvm_x86_hwapic_isr_update)(vec); +static_call (kvm_x86_hwapic_isr_update)(vec);else { ++apic->isr_count;BUG_ON (apic->isr_count >MAX_APIC_VECTOR );
@@ -800,7 +800,7 @@ static inline void apic_clear_isr(int vec, struct kvm_lapic *apic)* and must be left alone. */ if (unlikely (apic->apicv_active)) -static_call_cond (kvm_x86_hwapic_isr_update)(apic_find_highest_isr (apic)); +static_call (kvm_x86_hwapic_isr_update)(apic_find_highest_isr (apic));else { --apic->isr_count;BUG_ON (apic->isr_count <0 );
@@ -2567,7 +2567,7 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value)if ((old_value ^ value) & (MSR_IA32_APICBASE_ENABLE |X2APIC_ENABLE )) {kvm_make_request (KVM_REQ_APICV_UPDATE , vcpu); -static_call_cond (kvm_x86_set_virtual_apic_mode)(vcpu); +static_call (kvm_x86_set_virtual_apic_mode)(vcpu); } apic->base_address = apic->vcpu->arch.apic_base &
@@ -2677,7 +2677,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)u64 msr_val;int i; -static_call_cond (kvm_x86_apicv_pre_state_restore)(vcpu); +static_call (kvm_x86_apicv_pre_state_restore)(vcpu);if (!init_event) { msr_val =APIC_DEFAULT_PHYS_BASE |MSR_IA32_APICBASE_ENABLE ;
@@ -2732,9 +2732,9 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event) vcpu->arch.pv_eoi.msr_val =0 ;apic_update_ppr (apic);if (apic->apicv_active) { -static_call_cond (kvm_x86_apicv_post_state_restore)(vcpu); -static_call_cond (kvm_x86_hwapic_irr_update)(vcpu,-1 ); -static_call_cond (kvm_x86_hwapic_isr_update)(-1 ); +static_call (kvm_x86_apicv_post_state_restore)(vcpu); +static_call (kvm_x86_hwapic_irr_update)(vcpu,-1 ); +static_call (kvm_x86_hwapic_isr_update)(-1 ); } vcpu->arch.apic_arb_prio =0 ;
@@ -3014,7 +3014,7 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s)struct kvm_lapic *apic = vcpu->arch.apic;int r; -static_call_cond (kvm_x86_apicv_pre_state_restore)(vcpu); +static_call (kvm_x86_apicv_pre_state_restore)(vcpu);kvm_lapic_set_base (vcpu, vcpu->arch.apic_base);/* set SPIV separately to get count of SW disabled APICs right */
@@ -3041,9 +3041,9 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s)kvm_lapic_set_reg (apic,APIC_TMCCT ,0 );kvm_apic_update_apicv (vcpu);if (apic->apicv_active) { -static_call_cond (kvm_x86_apicv_post_state_restore)(vcpu); -static_call_cond (kvm_x86_hwapic_irr_update)(vcpu,apic_find_highest_irr (apic)); -static_call_cond (kvm_x86_hwapic_isr_update)(apic_find_highest_isr (apic)); +static_call (kvm_x86_apicv_post_state_restore)(vcpu); +static_call (kvm_x86_hwapic_irr_update)(vcpu,apic_find_highest_irr (apic)); +static_call (kvm_x86_hwapic_isr_update)(apic_find_highest_isr (apic)); }kvm_make_request (KVM_REQ_EVENT , vcpu);if (ioapic_in_kernel (vcpu->kvm))
arch/x86/kvm/pmu.c +3 -3
@@ -607,7 +607,7 @@ int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)void kvm_pmu_deliver_pmi (struct kvm_vcpu *vcpu) {if (lapic_in_kernel (vcpu)) { -static_call_cond (kvm_x86_pmu_deliver_pmi)(vcpu); +static_call (kvm_x86_pmu_deliver_pmi)(vcpu);kvm_apic_local_deliver (vcpu->arch.apic,APIC_LVTPC ); } }
@@ -740,7 +740,7 @@ static void kvm_pmu_reset(struct kvm_vcpu *vcpu) pmu->fixed_ctr_ctrl = pmu->global_ctrl = pmu->global_status =0 ; -static_call_cond (kvm_x86_pmu_reset)(vcpu); +static_call (kvm_x86_pmu_reset)(vcpu); }
@@ -818,7 +818,7 @@ void kvm_pmu_cleanup(struct kvm_vcpu *vcpu)pmc_stop_counter (pmc); } -static_call_cond (kvm_x86_pmu_cleanup)(vcpu); +static_call (kvm_x86_pmu_cleanup)(vcpu);bitmap_zero (pmu->pmc_in_use,X86_PMC_IDX_MAX ); }
arch/x86/kvm/x86.c +12 -12
@@ -5134,7 +5134,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)static int kvm_vcpu_ioctl_get_lapic (struct kvm_vcpu *vcpu,struct kvm_lapic_state *s) { -static_call_cond (kvm_x86_sync_pir_to_irr)(vcpu); +static_call (kvm_x86_sync_pir_to_irr)(vcpu);return kvm_apic_get_state (vcpu, s); }
@@ -9285,7 +9285,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,kvm_rip_write (vcpu, ctxt->eip);if (r && (ctxt->tf || (vcpu->guest_debug &KVM_GUESTDBG_SINGLESTEP ))) r =kvm_vcpu_do_singlestep (vcpu); -static_call_cond (kvm_x86_update_emulated_instruction)(vcpu); +static_call (kvm_x86_update_emulated_instruction)(vcpu);__kvm_set_rflags (vcpu, ctxt->eflags); }
@@ -10680,7 +10680,7 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)if (irqchip_split (vcpu->kvm))kvm_scan_ioapic_routes (vcpu, vcpu->arch.ioapic_handled_vectors);else { -static_call_cond (kvm_x86_sync_pir_to_irr)(vcpu); +static_call (kvm_x86_sync_pir_to_irr)(vcpu);if (ioapic_in_kernel (vcpu->kvm))kvm_ioapic_scan_entry (vcpu, vcpu->arch.ioapic_handled_vectors); }
@@ -10703,17 +10703,17 @@ static void vcpu_load_eoi_exitmap(struct kvm_vcpu *vcpu)bitmap_or ((ulong *)eoi_exit_bitmap, vcpu->arch.ioapic_handled_vectors,to_hv_synic (vcpu)->vec_bitmap,256 ); -static_call_cond (kvm_x86_load_eoi_exitmap)(vcpu, eoi_exit_bitmap); +static_call (kvm_x86_load_eoi_exitmap)(vcpu, eoi_exit_bitmap); return; }#endif -static_call_cond (kvm_x86_load_eoi_exitmap)( +static_call (kvm_x86_load_eoi_exitmap)( vcpu, (u64 *)vcpu->arch.ioapic_handled_vectors); }void kvm_arch_guest_memory_reclaimed (struct kvm *kvm) { -static_call_cond (kvm_x86_guest_memory_reclaimed)(kvm); +static_call (kvm_x86_guest_memory_reclaimed)(kvm); }static void kvm_vcpu_reload_apic_access_page (struct kvm_vcpu *vcpu)
@@ -10721,7 +10721,7 @@ static void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu)if (!lapic_in_kernel (vcpu))return ; -static_call_cond (kvm_x86_set_apic_access_page_addr)(vcpu); +static_call (kvm_x86_set_apic_access_page_addr)(vcpu); }/*
@@ -10961,7 +10961,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)* i.e. they can post interrupts even if APICv is temporarily disabled. */ if (kvm_lapic_enabled (vcpu)) -static_call_cond (kvm_x86_sync_pir_to_irr)(vcpu); +static_call (kvm_x86_sync_pir_to_irr)(vcpu);if (kvm_vcpu_exit_request (vcpu)) { vcpu->mode =OUTSIDE_GUEST_MODE ;
@@ -11010,7 +11010,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)break ;if (kvm_lapic_enabled (vcpu)) -static_call_cond (kvm_x86_sync_pir_to_irr)(vcpu); +static_call (kvm_x86_sync_pir_to_irr)(vcpu);if (unlikely (kvm_vcpu_exit_request (vcpu))) { exit_fastpath =EXIT_FASTPATH_EXIT_HANDLED ;
@@ -11758,7 +11758,7 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs, *mmu_reset_needed |=kvm_read_cr3 (vcpu) != sregs->cr3; vcpu->arch.cr3 = sregs->cr3;kvm_register_mark_dirty (vcpu,VCPU_EXREG_CR3 ); -static_call_cond (kvm_x86_post_set_cr3)(vcpu, sregs->cr3); +static_call (kvm_x86_post_set_cr3)(vcpu, sregs->cr3);kvm_set_cr8 (vcpu, sregs->cr8);
@@ -12713,7 +12713,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)mutex_unlock (&kvm->slots_lock); }kvm_unload_vcpu_mmus (kvm); -static_call_cond (kvm_x86_vm_destroy)(kvm); +static_call (kvm_x86_vm_destroy)(kvm);kvm_free_msr_filter (srcu_dereference_check (kvm->arch.msr_filter, &kvm->srcu,1 ));kvm_pic_destroy (kvm);kvm_ioapic_destroy (kvm);
@@ -13409,7 +13409,7 @@ bool kvm_arch_can_dequeue_async_page_present(struct kvm_vcpu *vcpu)void kvm_arch_start_assignment (struct kvm *kvm) {if (atomic_inc_return (&kvm->arch.assigned_device_count) ==1 ) -static_call_cond (kvm_x86_pi_start_assignment)(kvm); +static_call (kvm_x86_pi_start_assignment)(kvm); }EXPORT_SYMBOL_GPL (kvm_arch_start_assignment);
Signature · 1 line
2.27.0
PATCH v4 2/3 KVM: x86: Introduce kvm_x86_call() to simplify static calls of kvm_x86_ops
In reply to Wei WangIntroduces kvm_x86_call(), to streamline the usage of static calls of kvm_x86_ops. The current implementation of these calls is verbose and could lead to alignment challenges. This makes the code susceptible to exceeding the "80 columns per single line of code" limit as defined in the coding-style document. Another issue with the existing implementation is that the addition of kvm_x86_ prefix to hooks at the static_call sites hinders code readability and navigation. kvm_x86_call() is added to improve code readability and maintainability, while adhering to the coding style guidelines.
--- arch/x86/include/asm/kvm_host.h | 10 +- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/hyperv.c | 6 +- arch/x86/kvm/irq.c | 2 +- arch/x86/kvm/kvm_cache_regs.h | 10 +- arch/x86/kvm/lapic.c | 42 +++-- arch/x86/kvm/lapic.h | 2 +- arch/x86/kvm/mmu.h | 6 +- arch/x86/kvm/mmu/mmu.c | 4 +- arch/x86/kvm/mmu/spte.c | 4 +- arch/x86/kvm/pmu.c | 5 +- arch/x86/kvm/smm.c | 44 ++--- arch/x86/kvm/trace.h | 15 +- arch/x86/kvm/x86.c | 322 ++++++++++++++++---------------- arch/x86/kvm/x86.h | 2 +- arch/x86/kvm/xen.c | 4 +- 16 files changed, 246 insertions(+), 234 deletions(-)
arch/x86/include/asm/kvm_host.h +6 -4
@@ -1852,6 +1852,8 @@ extern bool __read_mostly allow_smaller_maxphyaddr;extern bool __read_mostly enable_apicv;extern struct kvm_x86_ops kvm_x86_ops; +#define kvm_x86_call (func) static_call(kvm_x86_##func) +#define KVM_X86_OP (func) \ DECLARE_STATIC_CALL(kvm_x86_##func, *(((struct kvm_x86_ops *)0)->func));#define KVM_X86_OP_OPTIONAL KVM_X86_OP
@@ -1875,7 +1877,7 @@ void kvm_arch_free_vm(struct kvm *kvm);static inline int kvm_arch_flush_remote_tlbs (struct kvm *kvm) {if (kvm_x86_ops.flush_remote_tlbs && - !static_call (kvm_x86_flush_remote_tlbs)(kvm)) + !kvm_x86_call (flush_remote_tlbs)(kvm))return 0 ;else return -ENOTSUPP ;
@@ -1888,7 +1890,7 @@ static inline int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn,if (!kvm_x86_ops.flush_remote_tlbs_range)return -EOPNOTSUPP ; - return static_call(kvm_x86_flush_remote_tlbs_range)(kvm, gfn, nr_pages); + return kvm_x86_call(flush_remote_tlbs_range)(kvm, gfn, nr_pages); }#endif /* CONFIG_HYPERV */
@@ -2280,12 +2282,12 @@ static inline bool kvm_irq_is_postable(struct kvm_lapic_irq *irq)static inline void kvm_arch_vcpu_blocking (struct kvm_vcpu *vcpu) { -static_call (kvm_x86_vcpu_blocking)(vcpu); +kvm_x86_call (vcpu_blocking)(vcpu); }static inline void kvm_arch_vcpu_unblocking (struct kvm_vcpu *vcpu) { -static_call (kvm_x86_vcpu_unblocking)(vcpu); +kvm_x86_call (vcpu_unblocking)(vcpu); }static inline int kvm_cpu_get_apicid (int mps_cpu)
arch/x86/kvm/cpuid.c +1 -1
@@ -388,7 +388,7 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) vcpu->arch.cpuid_nent));/* Invoke the vendor callback only after the above state is updated. */ -static_call (kvm_x86_vcpu_after_set_cpuid)(vcpu); +kvm_x86_call (vcpu_after_set_cpuid)(vcpu);/* * Except for the MMU, which needs to do its thing any vendor specific
arch/x86/kvm/hyperv.c +3 -3
@@ -1417,7 +1417,7 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data, }/* vmcall/vmmcall */ -static_call (kvm_x86_patch_hypercall)(vcpu, instructions + i); +kvm_x86_call (patch_hypercall)(vcpu, instructions + i); i +=3 ;/* ret */
@@ -1985,7 +1985,7 @@ int kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu)*/ gva = entries[i] &PAGE_MASK ;for (j =0 ; j < (entries[i] & ~PAGE_MASK ) +1 ; j++) -static_call (kvm_x86_flush_tlb_gva)(vcpu, gva + j *PAGE_SIZE ); +kvm_x86_call (flush_tlb_gva)(vcpu, gva + j *PAGE_SIZE ); ++vcpu->stat.tlb_flush; }
@@ -2526,7 +2526,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)* hypercall generates UD from non zero cpl and real mode * per HYPER-V spec */ -if (static_call (kvm_x86_get_cpl)(vcpu) !=0 || !is_protmode (vcpu)) { +if (kvm_x86_call (get_cpl)(vcpu) !=0 || !is_protmode (vcpu)) {kvm_queue_exception (vcpu,UD_VECTOR );return 1 ; }
arch/x86/kvm/irq.c +1 -1
@@ -157,7 +157,7 @@ void __kvm_migrate_timers(struct kvm_vcpu *vcpu) {__kvm_migrate_apic_timer (vcpu);__kvm_migrate_pit_timer (vcpu); -static_call (kvm_x86_migrate_timers)(vcpu); +kvm_x86_call (migrate_timers)(vcpu); }bool kvm_arch_irqfd_allowed (struct kvm *kvm,struct kvm_irqfd *args)
arch/x86/kvm/kvm_cache_regs.h +5 -5
@@ -98,7 +98,7 @@ static inline unsigned long kvm_register_read_raw(struct kvm_vcpu *vcpu, int regreturn 0 ;if (!kvm_register_is_available (vcpu, reg)) -static_call (kvm_x86_cache_reg)(vcpu, reg); +kvm_x86_call (cache_reg)(vcpu, reg);return vcpu->arch.regs[reg]; }
@@ -138,7 +138,7 @@ static inline u64 kvm_pdptr_read(struct kvm_vcpu *vcpu, int index)might_sleep ();/* on svm */ if (!kvm_register_is_available (vcpu,VCPU_EXREG_PDPTR )) -static_call (kvm_x86_cache_reg)(vcpu,VCPU_EXREG_PDPTR ); +kvm_x86_call (cache_reg)(vcpu,VCPU_EXREG_PDPTR );return vcpu->arch.walk_mmu->pdptrs[index]; }
@@ -153,7 +153,7 @@ static inline ulong kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask)ulong tmask = mask &KVM_POSSIBLE_CR0_GUEST_BITS ;if ((tmask & vcpu->arch.cr0_guest_owned_bits) && !kvm_register_is_available (vcpu,VCPU_EXREG_CR0 )) -static_call (kvm_x86_cache_reg)(vcpu,VCPU_EXREG_CR0 ); +kvm_x86_call (cache_reg)(vcpu,VCPU_EXREG_CR0 );return vcpu->arch.cr0 & mask; }
@@ -175,7 +175,7 @@ static inline ulong kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask)ulong tmask = mask &KVM_POSSIBLE_CR4_GUEST_BITS ;if ((tmask & vcpu->arch.cr4_guest_owned_bits) && !kvm_register_is_available (vcpu,VCPU_EXREG_CR4 )) -static_call (kvm_x86_cache_reg)(vcpu,VCPU_EXREG_CR4 ); +kvm_x86_call (cache_reg)(vcpu,VCPU_EXREG_CR4 );return vcpu->arch.cr4 & mask; }
@@ -190,7 +190,7 @@ static __always_inline bool kvm_is_cr4_bit_set(struct kvm_vcpu *vcpu,static inline ulong kvm_read_cr3 (struct kvm_vcpu *vcpu) {if (!kvm_register_is_available (vcpu,VCPU_EXREG_CR3 )) -static_call (kvm_x86_cache_reg)(vcpu,VCPU_EXREG_CR3 ); +kvm_x86_call (cache_reg)(vcpu,VCPU_EXREG_CR3 );return vcpu->arch.cr3; }
arch/x86/kvm/lapic.c +22 -20
126 lines not on this page · raw message
arch/x86/kvm/lapic.h +1 -1
@@ -236,7 +236,7 @@ static inline bool kvm_apic_has_pending_init_or_sipi(struct kvm_vcpu *vcpu)static inline bool kvm_apic_init_sipi_allowed (struct kvm_vcpu *vcpu) {return !is_smm (vcpu) && - !static_call (kvm_x86_apic_init_signal_blocked)(vcpu); + !kvm_x86_call (apic_init_signal_blocked)(vcpu); }static inline bool kvm_lowest_prio_delivery (struct kvm_lapic_irq *irq)
arch/x86/kvm/mmu.h +3 -3
@@ -161,8 +161,8 @@ static inline void kvm_mmu_load_pgd(struct kvm_vcpu *vcpu)if (!VALID_PAGE (root_hpa))return ; -static_call (kvm_x86_load_mmu_pgd)(vcpu, root_hpa, - vcpu->arch.mmu->root_role.level); +kvm_x86_call (load_mmu_pgd)(vcpu, root_hpa, + vcpu->arch.mmu->root_role.level); } static inline void kvm_mmu_refresh_passthrough_bits(struct kvm_vcpu *vcpu,
@@ -197,7 +197,7 @@ static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, {/* strip nested paging fault error codes */ unsigned int pfec = access; -unsigned long rflags =static_call (kvm_x86_get_rflags)(vcpu); +unsigned long rflags =kvm_x86_call (get_rflags)(vcpu);/* * For explicit supervisor accesses, SMAP is disabled if EFLAGS.AC = 1.
arch/x86/kvm/mmu/mmu.c +2 -2
@@ -5626,7 +5626,7 @@ int kvm_mmu_load(struct kvm_vcpu *vcpu)* stale entries. Flushing on alloc also allows KVM to skip the TLB * flush when freeing a root (see kvm_tdp_mmu_put_root()). */ -static_call (kvm_x86_flush_tlb_current)(vcpu); +kvm_x86_call (flush_tlb_current)(vcpu); out:return r; }
@@ -5962,7 +5962,7 @@ void kvm_mmu_invalidate_addr(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,if (is_noncanonical_address (addr, vcpu))return ; -static_call (kvm_x86_flush_tlb_gva)(vcpu, addr); +kvm_x86_call (flush_tlb_gva)(vcpu, addr); }if (!mmu->sync_spte)
arch/x86/kvm/mmu/spte.c +2 -2
@@ -190,8 +190,8 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, spte |=PT_PAGE_SIZE_MASK ;if (shadow_memtype_mask) - spte |=static_call (kvm_x86_get_mt_mask)(vcpu, gfn, -kvm_is_mmio_pfn (pfn)); + spte |=kvm_x86_call (get_mt_mask)(vcpu, gfn, +kvm_is_mmio_pfn (pfn));if (host_writable) spte |= shadow_host_writable_mask;else
arch/x86/kvm/pmu.c +3 -2
@@ -596,7 +596,7 @@ int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)return 1 ;if (!kvm_is_cr4_bit_set (vcpu,X86_CR4_PCE ) && - (static_call (kvm_x86_get_cpl)(vcpu) !=0 ) && + (kvm_x86_call (get_cpl)(vcpu) !=0 ) &&kvm_is_cr0_bit_set (vcpu,X86_CR0_PE ))return 1 ;
@@ -857,7 +857,8 @@ static inline bool cpl_is_matched(struct kvm_pmc *pmc)if (select_os == select_user)return select_os; -return (static_call (kvm_x86_get_cpl)(pmc->vcpu) ==0 ) ? select_os : select_user; +return (kvm_x86_call (get_cpl)(pmc->vcpu) ==0 ) ? select_os : + select_user; }void kvm_pmu_trigger_event (struct kvm_vcpu *vcpu,u64 eventsel)
arch/x86/kvm/smm.c +22 -22
150 lines not on this page · raw message
arch/x86/kvm/trace.h +8 -7
@@ -314,12 +314,12 @@ TRACE_EVENT(name, \ __entry->guest_rip =kvm_rip_read (vcpu); \ __entry->isa = isa; \ __entry->vcpu_id = vcpu->vcpu_id; \ -static_call (kvm_x86_get_exit_info)(vcpu, \ - &__entry->exit_reason, \ - &__entry->info1, \ - &__entry->info2, \ - &__entry->intr_info, \ - &__entry->error_code); \ +kvm_x86_call (get_exit_info)(vcpu, \ + &__entry->exit_reason, \ + &__entry->info1, \ + &__entry->info2, \ + &__entry->intr_info, \ + &__entry->error_code); \ ), \ \ TP_printk("vcpu %u reason %s%s%s rip 0x%lx info1 0x%016llx " \
@@ -828,7 +828,8 @@ TRACE_EVENT(kvm_emulate_insn, ),TP_fast_assign ( - __entry->csbase = static_call(kvm_x86_get_segment_base)(vcpu, VCPU_SREG_CS); + __entry->csbase =kvm_x86_call (get_segment_base)(vcpu, + VCPU_SREG_CS); __entry->len = vcpu->arch.emulate_ctxt->fetch.ptr - vcpu->arch.emulate_ctxt->fetch.data; __entry->rip = vcpu->arch.emulate_ctxt->_eip - __entry->len;
arch/x86/kvm/x86.c +164 -158
1,117 lines not on this page · raw message
arch/x86/kvm/x86.h +1 -1
@@ -157,7 +157,7 @@ static inline bool is_64_bit_mode(struct kvm_vcpu *vcpu)if (!is_long_mode (vcpu))return false; -static_call (kvm_x86_get_cs_db_l_bits)(vcpu, &cs_db, &cs_l); +kvm_x86_call (get_cs_db_l_bits)(vcpu, &cs_db, &cs_l);return cs_l; }
arch/x86/kvm/xen.c +2 -2
@@ -1270,7 +1270,7 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data) instructions[0 ] =0xb8 ;/* vmcall / vmmcall */ -static_call (kvm_x86_patch_hypercall)(vcpu, instructions +5 ); +kvm_x86_call (patch_hypercall)(vcpu, instructions +5 );/* ret */ instructions[8 ] =0xc3 ;
@@ -1650,7 +1650,7 @@ int kvm_xen_hypercall(struct kvm_vcpu *vcpu) params[5] = (u64)kvm_r9_read(vcpu); }#endif - cpl =static_call (kvm_x86_get_cpl)(vcpu); + cpl =kvm_x86_call (get_cpl)(vcpu);trace_kvm_xen_hypercall (cpl, input, params[0 ], params[1 ], params[2 ], params[3 ], params[4 ], params[5 ]);
Signature · 1 line
2.27.0
PATCH v4 3/3 KVM: x86/pmu: Add kvm_pmu_call() to simplify static calls of kvm_pmu_ops
In reply to Wei WangSimilar to kvm_x86_call(), kvm_pmu_call() is added to streamline the usage of static calls of kvm_pmu_ops, which improves code readability.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/pmu.c | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1853,6 +1853,7 @@ extern bool __read_mostly enable_apicv;extern struct kvm_x86_ops kvm_x86_ops;#define kvm_x86_call (func) static_call(kvm_x86_##func) +#define kvm_pmu_call (func) static_call(kvm_x86_pmu_##func)#define KVM_X86_OP (func) \ DECLARE_STATIC_CALL(kvm_x86_##func, *(((struct kvm_x86_ops *)0)->func));
arch/x86/kvm/pmu.c +12 -12
@@ -542,7 +542,7 @@ int kvm_pmu_check_rdpmc_early(struct kvm_vcpu *vcpu, unsigned int idx)if (!kvm_pmu_ops.check_rdpmc_early)return 0 ; -return static_call (kvm_x86_pmu_check_rdpmc_early)(vcpu, idx); +return kvm_pmu_call (check_rdpmc_early)(vcpu, idx); }bool is_vmware_backdoor_pmc (u32 pmc_idx)
@@ -591,7 +591,7 @@ int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)if (is_vmware_backdoor_pmc (idx))return kvm_pmu_rdpmc_vmware (vcpu, idx, data); - pmc =static_call (kvm_x86_pmu_rdpmc_ecx_to_pmc)(vcpu, idx, &mask); + pmc =kvm_pmu_call (rdpmc_ecx_to_pmc)(vcpu, idx, &mask);if (!pmc)return 1 ;
@@ -607,7 +607,7 @@ int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)void kvm_pmu_deliver_pmi (struct kvm_vcpu *vcpu) {if (lapic_in_kernel (vcpu)) { -static_call (kvm_x86_pmu_deliver_pmi)(vcpu); +kvm_pmu_call (deliver_pmi)(vcpu);kvm_apic_local_deliver (vcpu->arch.apic,APIC_LVTPC ); } }
@@ -622,14 +622,14 @@ bool kvm_pmu_is_valid_msr(struct kvm_vcpu *vcpu, u32 msr)default :break ; } -return static_call (kvm_x86_pmu_msr_idx_to_pmc)(vcpu, msr) || -static_call (kvm_x86_pmu_is_valid_msr)(vcpu, msr); +return kvm_pmu_call (msr_idx_to_pmc)(vcpu, msr) || +kvm_pmu_call (is_valid_msr)(vcpu, msr); }static void kvm_pmu_mark_pmc_in_use (struct kvm_vcpu *vcpu,u32 msr) {struct kvm_pmu *pmu =vcpu_to_pmu (vcpu); -struct kvm_pmc *pmc =static_call (kvm_x86_pmu_msr_idx_to_pmc)(vcpu, msr); +struct kvm_pmc *pmc =kvm_pmu_call (msr_idx_to_pmc)(vcpu, msr);if (pmc)__set_bit (pmc->idx, pmu->pmc_in_use);
@@ -654,7 +654,7 @@ int kvm_pmu_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) msr_info->data =0 ;break ;default : -return static_call (kvm_x86_pmu_get_msr)(vcpu, msr_info); +return kvm_pmu_call (get_msr)(vcpu, msr_info); }return 0 ;
@@ -713,7 +713,7 @@ int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)break ;default :kvm_pmu_mark_pmc_in_use (vcpu, msr_info->index); -return static_call (kvm_x86_pmu_set_msr)(vcpu, msr_info); +return kvm_pmu_call (set_msr)(vcpu, msr_info); }return 0 ;
@@ -740,7 +740,7 @@ static void kvm_pmu_reset(struct kvm_vcpu *vcpu) pmu->fixed_ctr_ctrl = pmu->global_ctrl = pmu->global_status =0 ; -static_call (kvm_x86_pmu_reset)(vcpu); +kvm_pmu_call (reset)(vcpu); }
@@ -778,7 +778,7 @@ void kvm_pmu_refresh(struct kvm_vcpu *vcpu)if (!vcpu->kvm->arch.enable_pmu)return ; -static_call (kvm_x86_pmu_refresh)(vcpu); +kvm_pmu_call (refresh)(vcpu);/* * At RESET, both Intel and AMD CPUs set all enable bits for general
@@ -796,7 +796,7 @@ void kvm_pmu_init(struct kvm_vcpu *vcpu)struct kvm_pmu *pmu =vcpu_to_pmu (vcpu);memset (pmu,0 ,sizeof (*pmu)); -static_call (kvm_x86_pmu_init)(vcpu); +kvm_pmu_call (init)(vcpu);kvm_pmu_refresh (vcpu); }
@@ -818,7 +818,7 @@ void kvm_pmu_cleanup(struct kvm_vcpu *vcpu)pmc_stop_counter (pmc); } -static_call (kvm_x86_pmu_cleanup)(vcpu); +kvm_pmu_call (cleanup)(vcpu);bitmap_zero (pmu->pmc_in_use,X86_PMC_IDX_MAX ); }
Signature · 1 line
2.27.0
Quoted 11 lines · Wei Wang
This patchset introduces the
kvm_x86_call()andkvm_pmu_call()macros to streamline the usage of static calls ofkvm_x86_opsandkvm_pmu_ops. The currentstatic_call()usage is a bit verbose and can lead to code alignment challenges, and the addition ofkvm_x86_prefix to hooks at thestatic_call()sites hinders code readability and navigation. The use ofstatic_call_cond()is essentially the same asstatic_call()on x86, so it is replaced bystatic_call()to simplify the code. The changes have gone through my tests (guest launch, a few vPMU tests, live migration tests) without an issue.[...]
Applied to kvm-x86 static_calls. I may or may not rebase these commits depending on what all gets queued for 6.10. There are already three conflicts that I know of, but they aren't _that_ annoying. Yet. :-)
Thanks!
[1/3] KVM: x86: Replace static_call_cond() with static_call()
https://github.com/kvm-x86/linux/commit/161827082760 [2/3] KVM: x86: Introduce kvm_x86_call() to simplify static calls of kvm_x86_ops https://github.com/kvm-x86/linux/commit/aebed32e4985 [3/3] KVM: x86/pmu: Add kvm_pmu_call() to simplify static calls of kvm_pmu_ops https://github.com/kvm-x86/linux/commit/4dbd1f66c5bf
Quoted 13 lines · Sean Christopherson
Quoted 12 lines · Wei Wang
This patchset introduces the
kvm_x86_call()andkvm_pmu_call()macros to streamline the usage of static calls ofkvm_x86_opsandkvm_pmu_ops. The currentstatic_call()usage is a bit verbose and can lead to code alignment challenges, and the addition ofkvm_x86_prefix to hooks at thestatic_call()sites hinders code readability and navigation. The use ofstatic_call_cond()is essentially the same asstatic_call()on x86, so it is replaced bystatic_call()to simplify the code. The changes have gone through my tests (guest launch, a few vPMU tests, live migration tests) without an issue.
Quoted 6 lines
Quoted 1 line
[...]
Applied to kvm-x86
static_calls. I may or may not rebase these commits depending on what all gets queued for 6.10. There are already three conflicts that I know of, but they aren't _that_ annoying. Yet. :-)
OK, thanks. Just let me know whenever you need help with rebasing.
Paolo Bonzini
maintainerQuoted 12 lines · Sean Christopherson
Quoted 10 lines · Wei Wang
This patchset introduces the
kvm_x86_call()andkvm_pmu_call()macros to streamline the usage of static calls ofkvm_x86_opsandkvm_pmu_ops. The currentstatic_call()usage is a bit verbose and can lead to code alignment challenges, and the addition ofkvm_x86_prefix to hooks at thestatic_call()sites hinders code readability and navigation. The use ofstatic_call_cond()is essentially the same asstatic_call()on x86, so it is replaced bystatic_call()to simplify the code. The changes have gone through my tests (guest launch, a few vPMU tests, live migration tests) without an issue.
Quoted 5 lines
Quoted 1 line
[...]
Applied to kvm-x86
static_calls. I may or may not rebase these commits depending on what all gets queued for 6.10. There are already three conflicts that I know of, but they aren't _that_ annoying. Yet. :-)
I think it's best if we apply them directly (i.e. not through a pull request), on top of everything else in 6.11.
Paolo
Sean Christopherson
maintainerQuoted 13 lines · Paolo Bonzini
Quoted 12 lines · Sean Christopherson
Quoted 10 lines · Wei Wang
This patchset introduces the
kvm_x86_call()andkvm_pmu_call()macros to streamline the usage of static calls ofkvm_x86_opsandkvm_pmu_ops. The currentstatic_call()usage is a bit verbose and can lead to code alignment challenges, and the addition ofkvm_x86_prefix to hooks at thestatic_call()sites hinders code readability and navigation. The use ofstatic_call_cond()is essentially the same asstatic_call()on x86, so it is replaced bystatic_call()to simplify the code. The changes have gone through my tests (guest launch, a few vPMU tests, live migration tests) without an issue.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
[...]
Applied to kvm-x86
static_calls. I may or may not rebase these commits depending on what all gets queued for 6.10. There are already three conflicts that I know of, but they aren't _that_ annoying. Yet. :-)I think it's best if we apply them directly (i.e. not through a pull request), on top of everything else in 6.11.
Works for me. I'll maintain the branch so that the code stays in -next, and so that patches that are destined for 6.12+ are built on the new world, and then post the rebased patches when the time comes.