Skip to content

Commit f50c290

Browse files
Lorenzo Pieralisigregkh
authored andcommitted
arm64: kernel: enforce pmuserenr_el0 initialization and restore
commit 60792ad349f3c6dc5735aafefe5dc9121c79e320 upstream. The pmuserenr_el0 register value is architecturally UNKNOWN on reset. Current kernel code resets that register value iff the core pmu device is correctly probed in the kernel. On platforms with missing DT pmu nodes (or disabled perf events in the kernel), the pmu is not probed, therefore the pmuserenr_el0 register is not reset in the kernel, which means that its value retains the reset value that is architecturally UNKNOWN (system may run with eg pmuserenr_el0 == 0x1, which means that PMU counters access is available at EL0, which must be disallowed). This patch adds code that resets pmuserenr_el0 on cold boot and restores it on core resume from shutdown, so that the pmuserenr_el0 setup is always enforced in the kernel. Cc: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8182d4c commit f50c290

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

arch/arm64/kernel/perf_event.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,6 @@ static void armv8pmu_reset(void *info)
574574

575575
/* Initialize & Reset PMNC: C and P bits. */
576576
armv8pmu_pmcr_write(ARMV8_PMCR_P | ARMV8_PMCR_C);
577-
578-
/* Disable access from userspace. */
579-
asm volatile("msr pmuserenr_el0, %0" :: "r" (0));
580577
}
581578

582579
static int armv8_pmuv3_map_event(struct perf_event *event)

arch/arm64/mm/proc.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ ENTRY(cpu_do_resume)
117117
*/
118118
ubfx x11, x11, #1, #1
119119
msr oslar_el1, x11
120+
msr pmuserenr_el0, xzr // Disable PMU access from EL0
120121
mov x0, x12
121122
dsb nsh // Make sure local tlb invalidation completed
122123
isb
@@ -155,6 +156,7 @@ ENTRY(__cpu_setup)
155156
msr cpacr_el1, x0 // Enable FP/ASIMD
156157
mov x0, #1 << 12 // Reset mdscr_el1 and disable
157158
msr mdscr_el1, x0 // access to the DCC from EL0
159+
msr pmuserenr_el0, xzr // Disable PMU access from EL0
158160
/*
159161
* Memory region attributes for LPAE:
160162
*

0 commit comments

Comments
 (0)