[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 06/15] KVM: x86: Register perf callbacks only when actively handling interrupt
- To: Sean Christopherson <seanjc@xxxxxxxxxx>
- From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
- Date: Fri, 27 Aug 2021 09:21:43 +0200
- Cc: Will Deacon <will@xxxxxxxxxx>, Mark Rutland <mark.rutland@xxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>, Catalin Marinas <catalin.marinas@xxxxxxx>, Marc Zyngier <maz@xxxxxxxxxx>, Guo Ren <guoren@xxxxxxxxxx>, Nick Hu <nickhu@xxxxxxxxxxxxx>, Greentime Hu <green.hu@xxxxxxxxx>, Vincent Chen <deanbo422@xxxxxxxxx>, Paul Walmsley <paul.walmsley@xxxxxxxxxx>, Palmer Dabbelt <palmer@xxxxxxxxxxx>, Albert Ou <aou@xxxxxxxxxxxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, x86@xxxxxxxxxx, Paolo Bonzini <pbonzini@xxxxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>, Jiri Olsa <jolsa@xxxxxxxxxx>, Namhyung Kim <namhyung@xxxxxxxxxx>, James Morse <james.morse@xxxxxxx>, Alexandru Elisei <alexandru.elisei@xxxxxxx>, Suzuki K Poulose <suzuki.poulose@xxxxxxx>, "H. Peter Anvin" <hpa@xxxxxxxxx>, Vitaly Kuznetsov <vkuznets@xxxxxxxxxx>, Wanpeng Li <wanpengli@xxxxxxxxxxx>, Jim Mattson <jmattson@xxxxxxxxxx>, Joerg Roedel <joro@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, linux-perf-users@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, kvmarm@xxxxxxxxxxxxxxxxxxxxx, linux-csky@xxxxxxxxxxxxxxx, linux-riscv@xxxxxxxxxxxxxxxxxxx, kvm@xxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, Artem Kashkanov <artem.kashkanov@xxxxxxxxx>, Like Xu <like.xu.linux@xxxxxxxxx>, Zhu Lingshan <lingshan.zhu@xxxxxxxxx>
- Delivery-date: Fri, 27 Aug 2021 07:25:20 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On Thu, Aug 26, 2021 at 05:57:09PM -0700, Sean Christopherson wrote:
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 9bc1375d6ed9..2f28d9d8dc94 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -6485,6 +6485,18 @@ static void perf_pending_event(struct irq_work *entry)
> #ifdef CONFIG_HAVE_GUEST_PERF_EVENTS
> DEFINE_PER_CPU(struct perf_guest_info_callbacks *, perf_guest_cbs);
>
> +void __perf_register_guest_info_callbacks(struct perf_guest_info_callbacks
> *cbs)
> +{
> + __this_cpu_write(perf_guest_cbs, cbs);
> +}
> +EXPORT_SYMBOL_GPL(__perf_register_guest_info_callbacks);
> +
> +void __perf_unregister_guest_info_callbacks(void)
> +{
> + __this_cpu_write(perf_guest_cbs, NULL);
> +}
> +EXPORT_SYMBOL_GPL(__perf_unregister_guest_info_callbacks);
This is 100% broken, and a prime example of why I hate modules.
It provides an interface for all modules, and completely fails to
validate even the most basic usage.
By using __this_cpu*() it omits the preemption checks, so you can call
this with preemption enabled, no problem.
By not checking the previous state, multiple modules can call this
interleaved without issue.
Basically assume any EXPORTed function is hostile, binary modules and
out-of-tree modules *are* just that. It's a cesspit out there.
|