Skip to content

Commit e201260

Browse files
robherringwilldeacon
authored andcommitted
arm64: perf: Add userspace counter access disable switch
Like x86, some users may want to disable userspace PMU counter altogether. Add a sysctl 'perf_user_access' file to control userspace counter access. The default is '0' which is disabled. Writing '1' enables access. Note that x86 supports globally enabling user access by writing '2' to /sys/bus/event_source/devices/cpu/rdpmc. As there's not existing userspace support to worry about, this shouldn't be necessary for Arm. It could be added later if the need arises. Cc: Peter Zijlstra <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: [email protected] Acked-by: Will Deacon <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Signed-off-by: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 82ff0c0 commit e201260

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Documentation/admin-guide/sysctl/kernel.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,17 @@ enabled, otherwise writing to this file will return ``-EBUSY``.
905905
The default value is 8.
906906

907907

908+
perf_user_access (arm64 only)
909+
=================================
910+
911+
Controls user space access for reading perf event counters. When set to 1,
912+
user space can read performance monitor counter registers directly.
913+
914+
The default value is 0 (access disabled).
915+
916+
See Documentation/arm64/perf.rst for more information.
917+
918+
908919
pid_max
909920
=======
910921

arch/arm64/kernel/perf_event.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ static const struct attribute_group armv8_pmuv3_events_attr_group = {
286286
PMU_FORMAT_ATTR(event, "config:0-15");
287287
PMU_FORMAT_ATTR(long, "config1:0");
288288

289+
static int sysctl_perf_user_access __read_mostly;
290+
289291
static inline bool armv8pmu_event_is_64bit(struct perf_event *event)
290292
{
291293
return event->attr.config1 & 0x1;
@@ -1104,6 +1106,19 @@ static int armv8pmu_probe_pmu(struct arm_pmu *cpu_pmu)
11041106
return probe.present ? 0 : -ENODEV;
11051107
}
11061108

1109+
static struct ctl_table armv8_pmu_sysctl_table[] = {
1110+
{
1111+
.procname = "perf_user_access",
1112+
.data = &sysctl_perf_user_access,
1113+
.maxlen = sizeof(unsigned int),
1114+
.mode = 0644,
1115+
.proc_handler = proc_dointvec_minmax,
1116+
.extra1 = SYSCTL_ZERO,
1117+
.extra2 = SYSCTL_ONE,
1118+
},
1119+
{ }
1120+
};
1121+
11071122
static int armv8_pmu_init(struct arm_pmu *cpu_pmu, char *name,
11081123
int (*map_event)(struct perf_event *event),
11091124
const struct attribute_group *events,
@@ -1136,6 +1151,8 @@ static int armv8_pmu_init(struct arm_pmu *cpu_pmu, char *name,
11361151
cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_CAPS] = caps ?
11371152
caps : &armv8_pmuv3_caps_attr_group;
11381153

1154+
register_sysctl("kernel", armv8_pmu_sysctl_table);
1155+
11391156
return 0;
11401157
}
11411158

0 commit comments

Comments
 (0)