Commit 5729ab06 authored by Lorenzo Pieralisi's avatar Lorenzo Pieralisi Committed by Luis Henriques

arm64: kernel: enforce pmuserenr_el0 initialization and restore

commit 60792ad3 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: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 7cd61241
...@@ -1215,9 +1215,6 @@ static void armv8pmu_reset(void *info) ...@@ -1215,9 +1215,6 @@ static void armv8pmu_reset(void *info)
/* Initialize & Reset PMNC: C and P bits. */ /* Initialize & Reset PMNC: C and P bits. */
armv8pmu_pmcr_write(ARMV8_PMCR_P | ARMV8_PMCR_C); armv8pmu_pmcr_write(ARMV8_PMCR_P | ARMV8_PMCR_C);
/* Disable access from userspace. */
asm volatile("msr pmuserenr_el0, %0" :: "r" (0));
} }
static int armv8_pmuv3_map_event(struct perf_event *event) static int armv8_pmuv3_map_event(struct perf_event *event)
......
...@@ -149,6 +149,7 @@ ENTRY(cpu_do_resume) ...@@ -149,6 +149,7 @@ ENTRY(cpu_do_resume)
*/ */
ubfx x11, x11, #1, #1 ubfx x11, x11, #1, #1
msr oslar_el1, x11 msr oslar_el1, x11
msr pmuserenr_el0, xzr // Disable PMU access from EL0
mov x0, x12 mov x0, x12
dsb nsh // Make sure local tlb invalidation completed dsb nsh // Make sure local tlb invalidation completed
isb isb
...@@ -188,6 +189,7 @@ ENTRY(__cpu_setup) ...@@ -188,6 +189,7 @@ ENTRY(__cpu_setup)
msr cpacr_el1, x0 // Enable FP/ASIMD msr cpacr_el1, x0 // Enable FP/ASIMD
mov x0, #1 << 12 // Reset mdscr_el1 and disable mov x0, #1 << 12 // Reset mdscr_el1 and disable
msr mdscr_el1, x0 // access to the DCC from EL0 msr mdscr_el1, x0 // access to the DCC from EL0
msr pmuserenr_el0, xzr // Disable PMU access from EL0
/* /*
* Memory region attributes for LPAE: * Memory region attributes for LPAE:
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment