Linux Perf Users
 help / color / mirror / Atom feed
From: Eric Curtin <ericcurtin17@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Ryan Roberts <ryan.roberts@arm.com>,
	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>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH v2 11/43] perf/core: Handle a boot-time PAGE_SIZE in format attrs and mlock
Date: Tue,  1 Dec 2026 01:51:43 +0000	[thread overview]
Message-ID: <20261201015240.1017259-12-ericcurtin17@gmail.com> (raw)
In-Reply-To: <20261201015240.1017259-1-ericcurtin17@gmail.com>

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

           reply	other threads:[~2026-12-01  1:53 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20261201015240.1017259-1-ericcurtin17@gmail.com>]

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=20261201015240.1017259-12-ericcurtin17@gmail.com \
    --to=ericcurtin17@gmail.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ryan.roberts@arm.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