Skip to content

Commit 905e8c5

Browse files
committed
arm64: errata: add workaround for cortex-a53 erratum #845719
When running a compat (AArch32) userspace on Cortex-A53, a load at EL0 from a virtual address that matches the bottom 32 bits of the virtual address used by a recent load at (AArch64) EL1 might return incorrect data. This patch works around the issue by writing to the contextidr_el1 register on the exception return path when returning to a 32-bit task. This workaround is patched in at runtime based on the MIDR value of the processor. Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Tested-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent cc3979b commit 905e8c5

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎arch/arm64/Kconfig‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,27 @@ config ARM64_ERRATUM_832075
361361

362362
If unsure, say Y.
363363

364+
config ARM64_ERRATUM_845719
365+
bool "Cortex-A53: 845719: a load might read incorrect data"
366+
depends on COMPAT
367+
default y
368+
help
369+
This option adds an alternative code sequence to work around ARM
370+
erratum 845719 on Cortex-A53 parts up to r0p4.
371+
372+
When running a compat (AArch32) userspace on an affected Cortex-A53
373+
part, a load at EL0 from a virtual address that matches the bottom 32
374+
bits of the virtual address used by a recent load at (AArch64) EL1
375+
might return incorrect data.
376+
377+
The workaround is to write the contextidr_el1 register on exception
378+
return to a 32-bit task.
379+
Please note that this does not necessarily enable the workaround,
380+
as it depends on the alternative framework, which will only patch
381+
the kernel if an affected CPU is detected.
382+
383+
If unsure, say Y.
384+
364385
endmenu
365386

366387

‎arch/arm64/include/asm/cpufeature.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323

2424
#define ARM64_WORKAROUND_CLEAN_CACHE 0
2525
#define ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE 1
26+
#define ARM64_WORKAROUND_845719 2
2627

27-
#define ARM64_NCAPS 2
28+
#define ARM64_NCAPS 3
2829

2930
#ifndef __ASSEMBLY__
3031

‎arch/arm64/kernel/cpu_errata.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
7272
.capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE,
7373
MIDR_RANGE(MIDR_CORTEX_A57, 0x00, 0x12),
7474
},
75+
#endif
76+
#ifdef CONFIG_ARM64_ERRATUM_845719
77+
{
78+
/* Cortex-A53 r0p[01234] */
79+
.desc = "ARM erratum 845719",
80+
.capability = ARM64_WORKAROUND_845719,
81+
MIDR_RANGE(MIDR_CORTEX_A53, 0x00, 0x04),
82+
},
7583
#endif
7684
{
7785
}

‎arch/arm64/kernel/entry.S‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
#include <linux/init.h>
2222
#include <linux/linkage.h>
2323

24+
#include <asm/alternative-asm.h>
2425
#include <asm/assembler.h>
2526
#include <asm/asm-offsets.h>
27+
#include <asm/cpufeature.h>
2628
#include <asm/errno.h>
2729
#include <asm/esr.h>
2830
#include <asm/thread_info.h>
@@ -120,6 +122,24 @@
120122
ct_user_enter
121123
ldr x23, [sp, #S_SP] // load return stack pointer
122124
msr sp_el0, x23
125+
126+
#ifdef CONFIG_ARM64_ERRATUM_845719
127+
alternative_insn \
128+
"nop", \
129+
"tbz x22, #4, 1f", \
130+
ARM64_WORKAROUND_845719
131+
#ifdef CONFIG_PID_IN_CONTEXTIDR
132+
alternative_insn \
133+
"nop; nop", \
134+
"mrs x29, contextidr_el1; msr contextidr_el1, x29; 1:", \
135+
ARM64_WORKAROUND_845719
136+
#else
137+
alternative_insn \
138+
"nop", \
139+
"msr contextidr_el1, xzr; 1:", \
140+
ARM64_WORKAROUND_845719
141+
#endif
142+
#endif
123143
.endif
124144
msr elr_el1, x21 // set up the return data
125145
msr spsr_el1, x22

0 commit comments

Comments
 (0)