Linux Perf Users
 help / color / mirror / Atom feed
* [RFC PATCH v2 11/43] perf/core: Handle a boot-time PAGE_SIZE in format attrs and mlock
       [not found] <20261201015240.1017259-1-ericcurtin17@gmail.com>
@ 2026-12-01  1:51 ` Eric Curtin
  0 siblings, 0 replies; only message in thread
From: Eric Curtin @ 2026-12-01  1:51 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Ryan Roberts, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
	James Clark, linux-perf-users, linux-kernel

From: Ryan Roberts <ryan.roberts@arm.com>

With boot-time page size selection PAGE_SIZE is not a compile-time
constant.

In the PMU_FORMAT_ATTR() show function, compare sizeof(_format) against
PAGE_SIZE_MIN in BUILD_BUG_ON(). The format string does not depend on
the page size, so checking it fits the smallest page is sufficient.

Define sysctl_perf_event_mlock, whose default is derived from PAGE_SIZE,
with DEFINE_GLOBAL_PAGE_SIZE_VAR_ATTR() so that it is initialised at
boot for boot-time page size builds.

No functional change for compile-time page sizes.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 6e83c7d00396aa8d86ae2a50b6f7ce156c01d7cc)
---
 include/linux/perf_event.h | 2 +-
 kernel/events/core.c       | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index b52348eca6ef..e09498c9379e 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -2098,7 +2098,7 @@ _name##_show(struct device *dev,					\
 			       struct device_attribute *attr,		\
 			       char *page)				\
 {									\
-	BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE);			\
+	BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE_MIN);			\
 	return sprintf(page, _format "\n");				\
 }									\
 
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4ab3919ac78e..41c372980e0c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -496,7 +496,8 @@ static __always_inline bool is_guest_mediated_pmu_loaded(void)
 int sysctl_perf_event_paranoid __read_mostly = 2;
 
 /* Minimum for 512 kiB + 1 user control page. 'free' kiB per user. */
-static int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024);
+static DEFINE_GLOBAL_PAGE_SIZE_VAR_ATTR(int, sysctl_perf_event_mlock, __read_mostly,
+					512 + (PAGE_SIZE / 1024));
 
 /*
  * max perf event sample rate

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-01  1:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261201015240.1017259-1-ericcurtin17@gmail.com>
2026-12-01  1:51 ` [RFC PATCH v2 11/43] perf/core: Handle a boot-time PAGE_SIZE in format attrs and mlock Eric Curtin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox