Re: [PATCH v5 16/44] KVM: Add a simplified wrapper for registering perf callbacks

Anup Patel
2025-08-22T10:33:01Z

On Thu, Aug 7, 2025 at 1:27 AM Sean Christopherson <seanjc@google.com> wrote:
>
> Add a parameter-less API for registering perf callbacks in anticipation of
> introducing another x86-only parameter for handling mediated PMU PMIs.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

For KVM RISC-V:
Acked-by: Anup Patel <anup@brainfault.org>

Regards,
Anup

> ---
> arch/arm64/kvm/arm.c | 2 +-
> arch/loongarch/kvm/main.c | 2 +-
> arch/riscv/kvm/main.c | 2 +-
> arch/x86/kvm/x86.c | 2 +-
> include/linux/kvm_host.h | 11 +++++++++--
> virt/kvm/kvm_main.c | 5 +++--
> 6 files changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index 888f7c7abf54..6c604b5214f2 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -2328,7 +2328,7 @@ static int __init init_subsystems(void)
> if (err)
> goto out;
>
> - kvm_register_perf_callbacks(NULL);
> + kvm_register_perf_callbacks();
>
> out:
> if (err)
> diff --git a/arch/loongarch/kvm/main.c b/arch/loongarch/kvm/main.c
> index 80ea63d465b8..f62326fe29fa 100644
> --- a/arch/loongarch/kvm/main.c
> +++ b/arch/loongarch/kvm/main.c
> @@ -394,7 +394,7 @@ static int kvm_loongarch_env_init(void)
> }
>
> kvm_init_gcsr_flag();
> - kvm_register_perf_callbacks(NULL);
> + kvm_register_perf_callbacks();
>
> /* Register LoongArch IPI interrupt controller interface. */
> ret = kvm_loongarch_register_ipi_device();
> diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c
> index 67c876de74ef..cbe842c2f615 100644
> --- a/arch/riscv/kvm/main.c
> +++ b/arch/riscv/kvm/main.c
> @@ -159,7 +159,7 @@ static int __init riscv_kvm_init(void)
> kvm_info("AIA available with %d guest external interrupts\n",
> kvm_riscv_aia_nr_hgei);
>
> - kvm_register_perf_callbacks(NULL);
> + kvm_register_perf_callbacks();
>
> rc = kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
> if (rc) {
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 5af2c5aed0f2..d80bbd5e0859 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9689,7 +9689,7 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
> set_hv_tscchange_cb(kvm_hyperv_tsc_notifier);
> #endif
>
> - kvm_register_perf_callbacks(ops->handle_intel_pt_intr);
> + __kvm_register_perf_callbacks(ops->handle_intel_pt_intr, NULL);
>
> if (IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_mmu_enabled)
> kvm_caps.supported_vm_types |= BIT(KVM_X86_SW_PROTECTED_VM);
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 15656b7fba6c..20c50eaa0089 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -1731,10 +1731,17 @@ static inline bool kvm_arch_intc_initialized(struct kvm *kvm)
> #ifdef CONFIG_GUEST_PERF_EVENTS
> unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu);
>
> -void kvm_register_perf_callbacks(unsigned int (*pt_intr_handler)(void));
> +void __kvm_register_perf_callbacks(unsigned int (*pt_intr_handler)(void),
> + void (*mediated_pmi_handler)(void));
> +
> +static inline void kvm_register_perf_callbacks(void)
> +{
> + __kvm_register_perf_callbacks(NULL, NULL);
> +}
> +
> void kvm_unregister_perf_callbacks(void);
> #else
> -static inline void kvm_register_perf_callbacks(void *ign) {}
> +static inline void kvm_register_perf_callbacks(void) {}
> static inline void kvm_unregister_perf_callbacks(void) {}
> #endif /* CONFIG_GUEST_PERF_EVENTS */
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index ecafab2e17d9..d477a7fda0ae 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -6429,10 +6429,11 @@ static struct perf_guest_info_callbacks kvm_guest_cbs = {
> .handle_mediated_pmi = NULL,
> };
>
> -void kvm_register_perf_callbacks(unsigned int (*pt_intr_handler)(void))
> +void __kvm_register_perf_callbacks(unsigned int (*pt_intr_handler)(void),
> + void (*mediated_pmi_handler)(void))
> {
> kvm_guest_cbs.handle_intel_pt_intr = pt_intr_handler;
> - kvm_guest_cbs.handle_mediated_pmi = NULL;
> + kvm_guest_cbs.handle_mediated_pmi = mediated_pmi_handler;
>
> perf_register_guest_info_callbacks(&kvm_guest_cbs);
> }
> --
> 2.50.1.565.gc32cd1483b-goog
>