[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251208115156.GE3707891@noisy.programming.kicks-ass.net>
Date: Mon, 8 Dec 2025 12:51:56 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Sean Christopherson <seanjc@...gle.com>
Cc: Marc Zyngier <maz@...nel.org>, Oliver Upton <oupton@...nel.org>,
Tianrui Zhao <zhaotianrui@...ngson.cn>,
Bibo Mao <maobibo@...ngson.cn>, Huacai Chen <chenhuacai@...nel.org>,
Anup Patel <anup@...infault.org>, Paul Walmsley <pjw@...nel.org>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>, Xin Li <xin@...or.com>,
"H. Peter Anvin" <hpa@...or.com>, Andy Lutomirski <luto@...nel.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Paolo Bonzini <pbonzini@...hat.com>,
linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.linux.dev,
kvm@...r.kernel.org, loongarch@...ts.linux.dev,
kvm-riscv@...ts.infradead.org, linux-riscv@...ts.infradead.org,
linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org,
Mingwei Zhang <mizhang@...gle.com>,
Xudong Hao <xudong.hao@...el.com>,
Sandipan Das <sandipan.das@....com>,
Dapeng Mi <dapeng1.mi@...ux.intel.com>,
Xiong Zhang <xiong.y.zhang@...ux.intel.com>,
Manali Shukla <manali.shukla@....com>,
Jim Mattson <jmattson@...gle.com>
Subject: Re: [PATCH v6 04/44] perf: Add APIs to create/release mediated guest
vPMUs
On Fri, Dec 05, 2025 at 04:16:40PM -0800, Sean Christopherson wrote:
> +static atomic_t nr_include_guest_events __read_mostly;
> +
> +static atomic_t nr_mediated_pmu_vms __read_mostly;
> +static DEFINE_MUTEX(perf_mediated_pmu_mutex);
> +static int mediated_pmu_account_event(struct perf_event *event)
> +{
> + if (!is_include_guest_event(event))
> + return 0;
> +
> + guard(mutex)(&perf_mediated_pmu_mutex);
> +
> + if (atomic_read(&nr_mediated_pmu_vms))
> + return -EOPNOTSUPP;
> +
> + atomic_inc(&nr_include_guest_events);
> + return 0;
> +}
> +
> +static void mediated_pmu_unaccount_event(struct perf_event *event)
> +{
> + if (!is_include_guest_event(event))
> + return;
> +
> + atomic_dec(&nr_include_guest_events);
> +}
> +int perf_create_mediated_pmu(void)
> +{
> + guard(mutex)(&perf_mediated_pmu_mutex);
> + if (atomic_inc_not_zero(&nr_mediated_pmu_vms))
> + return 0;
> +
> + if (atomic_read(&nr_include_guest_events))
> + return -EBUSY;
> +
> + atomic_inc(&nr_mediated_pmu_vms);
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(perf_create_mediated_pmu);
> +
> +void perf_release_mediated_pmu(void)
> +{
> + if (WARN_ON_ONCE(!atomic_read(&nr_mediated_pmu_vms)))
> + return;
> +
> + atomic_dec(&nr_mediated_pmu_vms);
> +}
> +EXPORT_SYMBOL_GPL(perf_release_mediated_pmu);
These two things are supposed to be symmetric, but are implemented
differently; what gives?
That is, should not both have the general shape:
if (atomic_inc_not_zero(&A))
return 0;
guard(mutex)(&lock);
if (atomic_read(&B))
return -EBUSY;
atomic_inc(&A);
return 0;
Similarly, I would imagine both release variants to have the underflow
warn on like:
if (WARN_ON_ONCE(!atomic_read(&A)))
return;
atomic_dec(&A);
Hmm?
Also, EXPORT_SYMBOL_FOR_KVM() ?
I can make these edits when applying, if/when we get to applying. Let me
continue reading.
Powered by blists - more mailing lists