[PATCH 19/19] perf: Garbage-collect event_init checks
Robin Murphy
robin.murphy at arm.com
Wed Aug 20 03:49:08 AEST 2025
On 19/08/2025 3:44 am, kernel test robot wrote:
>
>
> Hello,
>
> kernel test robot noticed "BUG:unable_to_handle_page_fault_for_address" on:
>
> commit: 1ba20479196e5af3ebbedf9321de6b26f2a0cdd3 ("[PATCH 19/19] perf: Garbage-collect event_init checks")
> url: https://github.com/intel-lab-lkp/linux/commits/Robin-Murphy/perf-arm-cmn-Fix-event-validation/20250814-010626
> base: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git 91325f31afc1026de28665cf1a7b6e157fa4d39d
> patch link: https://lore.kernel.org/all/ace3532a8a438a96338bf349a27636d8294c7111.1755096883.git.robin.murphy@arm.com/
> patch subject: [PATCH 19/19] perf: Garbage-collect event_init checks
OK, after looking a bit more deeply at x86 and PowerPC, I think it
probably is nicest to solve this commonly too. Below is what I've cooked
up for a v2 (I'll save reposting the whole series this soon...)
Thanks,
Robin.
----->8-----
Subject: [PATCH 18.5/19] perf: Add common uncore-CPU check
Many uncore drivers depend on event->cpu being valid in order to look
up various data in their event_init call. Since we've now factored out
common PMU identification, we can factor out this check in the correct
order too. While it might technically be possible to hoist the general
task/cgroup check up here now, that would be horribly messy, so for
clarity let's keep these as distinct (albeit related) concerns.
Reported-by: kernel test robot <oliver.sang at intel.com>
Closes: https://lore.kernel.org/oe-lkp/202508190403.33c83ece-lkp@intel.com
Signed-off-by: Robin Murphy <robin.murphy at arm.com>
---
kernel/events/core.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 5f7eb526d87c..ddf045ad4d83 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -12562,6 +12562,11 @@ static bool is_raw_pmu(const struct pmu *pmu)
pmu->capabilities & PERF_PMU_CAP_RAW_EVENTS;
}
+static bool is_uncore_pmu(const struct pmu *pmu)
+{
+ return pmu->task_ctx_nr == perf_invalid_context;
+}
+
static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)
{
struct perf_event_context *ctx = NULL;
@@ -12571,11 +12576,16 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)
* Before touching anything, we can safely skip:
* - any event for a specific PMU which is not this one
* - any common event if this PMU doesn't support them
+ * - non-CPU-bound uncore events (so drivers can assume event->cpu is
+ * valid; we'll check the actual task/cgroup attach state later)
*/
if (event->attr.type != pmu->type &&
(event->attr.type >= PERF_TYPE_MAX || !is_raw_pmu(pmu)))
return -ENOENT;
+ if (is_uncore_pmu(pmu) && event->cpu < 0)
+ return -EINVAL;
+
if (!try_module_get(pmu->module))
return -ENODEV;
@@ -12990,7 +13000,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
* events (they don't make sense as the cgroup will be different
* on other CPUs in the uncore mask).
*/
- if (pmu->task_ctx_nr == perf_invalid_context && (task || cgroup_fd != -1))
+ if (is_uncore_pmu(pmu) && (task || cgroup_fd != -1))
return ERR_PTR(-EINVAL);
if (event->attr.aux_output &&
--
More information about the Linuxppc-dev
mailing list