Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: perf: Don't register user access sysctl handler multiple times

Commit e2012600810c ("arm64: perf: Add userspace counter access disable
switch") introduced a new 'perf_user_access' sysctl file to enable and
disable direct userspace access to the PMU counters. Sadly, Geert
reports that on his big.LITTLE SoC ('Renesas Salvator-XS w/ R-Car H3'),
the file is created for each PMU type probed, resulting in a splat
during boot:

| hw perfevents: enabled with armv8_cortex_a53 PMU driver, 7 counters available
| sysctl duplicate entry: /kernel//perf_user_access
| CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.16.0-rc3-arm64-renesas-00003-ge2012600810c #1420
| Hardware name: Renesas Salvator-X 2nd version board based on r8a77951 (DT)
| Call trace:
| dump_backtrace+0x0/0x190
| show_stack+0x14/0x20
| dump_stack_lvl+0x88/0xb0
| dump_stack+0x14/0x2c
| __register_sysctl_table+0x384/0x818
| register_sysctl+0x20/0x28
| armv8_pmu_init.constprop.0+0x118/0x150
| armv8_a57_pmu_init+0x1c/0x28
| arm_pmu_device_probe+0x1b4/0x558
| armv8_pmu_device_probe+0x18/0x20
| platform_probe+0x64/0xd0
| hw perfevents: enabled with armv8_cortex_a57 PMU driver, 7 counters available

Introduce a state variable to track creation of the sysctl file and
ensure that it is only created once.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Fixes: e2012600810c ("arm64: perf: Add userspace counter access disable switch")
Link: https://lore.kernel.org/r/CAMuHMdVcDxR9sGzc5pcnORiotonERBgc6dsXZXMd6wTvLGA9iw@mail.gmail.com
Signed-off-by: Will Deacon <will@kernel.org>

+9 -2
+9 -2
arch/arm64/kernel/perf_event.c
··· 1214 1214 { } 1215 1215 }; 1216 1216 1217 + static void armv8_pmu_register_sysctl_table(void) 1218 + { 1219 + static u32 tbl_registered = 0; 1220 + 1221 + if (!cmpxchg_relaxed(&tbl_registered, 0, 1)) 1222 + register_sysctl("kernel", armv8_pmu_sysctl_table); 1223 + } 1224 + 1217 1225 static int armv8_pmu_init(struct arm_pmu *cpu_pmu, char *name, 1218 1226 int (*map_event)(struct perf_event *event), 1219 1227 const struct attribute_group *events, ··· 1256 1248 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_CAPS] = caps ? 1257 1249 caps : &armv8_pmuv3_caps_attr_group; 1258 1250 1259 - register_sysctl("kernel", armv8_pmu_sysctl_table); 1260 - 1251 + armv8_pmu_register_sysctl_table(); 1261 1252 return 0; 1262 1253 } 1263 1254