From: "Dixit, Ashutosh" <ashutosh.dixit@intel.com>
To: John Hubbard <jhubbard@nvidia.com>
Cc: "Matthew Brost" <matthew.brost@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Arnaldo Carvalho de Melo" <acme@kernel.org>,
"Namhyung Kim" <namhyung@kernel.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
"Jiri Olsa" <jolsa@kernel.org>, "Ian Rogers" <irogers@google.com>,
"Adrian Hunter" <adrian.hunter@intel.com>,
"James Clark" <james.clark@linaro.org>,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-perf-users@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] perf/core: out-of-line and export perf_allow_cpu/tracepoint()
Date: Tue, 26 May 2026 20:34:14 -0700 [thread overview]
Message-ID: <87fr3dv83t.wl-ashutosh.dixit@intel.com> (raw)
In-Reply-To: <20260523013326.129491-2-jhubbard@nvidia.com>
On Fri, 22 May 2026 18:33:25 -0700, John Hubbard wrote:
>
> These helpers are static inline in <linux/perf_event.h> and reach
> into sysctl_perf_event_paranoid and security_perf_event_open(),
> neither of which is itself exported. The perf_allow_* trio is
> therefore asymmetric: built-in callers can use any of the three, but
> modular code can only call perf_allow_kernel().
>
> Move both bodies into kernel/events/core.c next to perf_allow_kernel()
> and export them with EXPORT_SYMBOL_GPL, following the shape of
> commit 5e9629d0ae97 ("drivers/perf: arm_spe: Use perf_allow_kernel()
> for permissions"). Existing in-tree callers live in built-in arch and
> tracing code, so the change is invisible to them.
>
> Provide !CONFIG_PERF_EVENTS stubs that fall back to perfmon_capable(),
> so the helpers stay callable when perf is compiled out.
>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
> ---
> include/linux/perf_event.h | 31 +++++++++++++++----------------
> kernel/events/core.c | 18 ++++++++++++++++++
> 2 files changed, 33 insertions(+), 16 deletions(-)
>
> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index 48d851fbd8ea..5842552294c1 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -1791,22 +1791,8 @@ static inline int perf_is_paranoid(void)
> }
>
> extern int perf_allow_kernel(void);
> -
> -static inline int perf_allow_cpu(void)
> -{
> - if (sysctl_perf_event_paranoid > 0 && !perfmon_capable())
> - return -EACCES;
> -
> - return security_perf_event_open(PERF_SECURITY_CPU);
> -}
> -
> -static inline int perf_allow_tracepoint(void)
> -{
> - if (sysctl_perf_event_paranoid > -1 && !perfmon_capable())
> - return -EPERM;
> -
> - return security_perf_event_open(PERF_SECURITY_TRACEPOINT);
> -}
> +extern int perf_allow_cpu(void);
> +extern int perf_allow_tracepoint(void);
>
> extern int perf_exclude_event(struct perf_event *event, struct pt_regs *regs);
>
> @@ -2023,6 +2009,19 @@ perf_event_pause(struct perf_event *event, bool reset) { return 0; }
> static inline int
> perf_exclude_event(struct perf_event *event, struct pt_regs *regs) { return 0; }
>
> +static inline int perf_allow_kernel(void)
> +{
> + return perfmon_capable() ? 0 : -EACCES;
> +}
> +static inline int perf_allow_cpu(void)
> +{
> + return perfmon_capable() ? 0 : -EACCES;
> +}
> +static inline int perf_allow_tracepoint(void)
> +{
> + return perfmon_capable() ? 0 : -EPERM;
> +}
> +
> #endif /* !CONFIG_PERF_EVENTS */
>
> #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL)
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 7935d5663944..cb13f3ad11a3 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -14731,6 +14731,24 @@ int perf_allow_kernel(void)
> }
> EXPORT_SYMBOL_GPL(perf_allow_kernel);
>
> +int perf_allow_cpu(void)
> +{
> + if (sysctl_perf_event_paranoid > 0 && !perfmon_capable())
> + return -EACCES;
> +
> + return security_perf_event_open(PERF_SECURITY_CPU);
> +}
> +EXPORT_SYMBOL_GPL(perf_allow_cpu);
> +
> +int perf_allow_tracepoint(void)
> +{
> + if (sysctl_perf_event_paranoid > -1 && !perfmon_capable())
> + return -EPERM;
> +
> + return security_perf_event_open(PERF_SECURITY_TRACEPOINT);
> +}
> +EXPORT_SYMBOL_GPL(perf_allow_tracepoint);
> +
> /*
> * Inherit an event from parent task to child task.
> *
> --
> 2.54.0
>
next prev parent reply other threads:[~2026-05-27 3:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-23 1:33 [PATCH v2 0/2] complete perf_allow_* trio and use in drm/xe John Hubbard
2026-05-23 1:33 ` [PATCH v2 1/2] perf/core: out-of-line and export perf_allow_cpu/tracepoint() John Hubbard
2026-05-23 1:51 ` sashiko-bot
2026-05-23 2:07 ` John Hubbard
2026-05-27 3:34 ` Dixit, Ashutosh [this message]
2026-05-23 1:33 ` [PATCH v2 2/2] drm/xe: gate observation streams with perf_allow_cpu() John Hubbard
2026-05-23 2:20 ` sashiko-bot
2026-05-23 2:24 ` John Hubbard
2026-05-27 3:34 ` Dixit, Ashutosh
2026-05-23 8:40 ` [PATCH v2 0/2] complete perf_allow_* trio and use in drm/xe Peter Zijlstra
2026-05-23 17:52 ` John Hubbard
2026-05-27 3:34 ` Dixit, Ashutosh
2026-05-27 15:42 ` Rodrigo Vivi
2026-05-27 16:30 ` Peter Zijlstra
2026-05-27 23:00 ` Dixit, Ashutosh
2026-05-28 0:24 ` John Hubbard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fr3dv83t.wl-ashutosh.dixit@intel.com \
--to=ashutosh.dixit@intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=airlied@gmail.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jhubbard@nvidia.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=matthew.brost@intel.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox