]> git.hungrycats.org Git - linux/commitdiff
perf/core: out-of-line and export perf_allow_cpu/tracepoint()
authorJohn Hubbard <jhubbard@nvidia.com>
Wed, 27 May 2026 22:55:06 +0000 (15:55 -0700)
committerAshutosh Dixit <ashutosh.dixit@intel.com>
Thu, 28 May 2026 15:19:36 +0000 (08:19 -0700)
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>
Link: https://patch.msgid.link/20260527225507.2044027-2-ashutosh.dixit@intel.com
Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
include/linux/perf_event.h
kernel/events/core.c

index 48d851fbd8ea583c4737672005e24e3ee31d70b6..5842552294c195241df0153ab830a26e487b5a95 100644 (file)
@@ -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)
index 6d1f8bad7e1c521023bd151fdf941871bf10890a..735e502beb9664482872797778311e18fcdd3cd6 100644 (file)
@@ -14691,6 +14691,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.
  *