Skip to content

Commit 5430a02

Browse files
wildea01sashalevin
authored andcommitted
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> Cc: <stable@vger.kernel.org> # v3.18.y (cherry picked from commit 905e8c5) Signed-off-by: Kevin Hilman <khilman@linaro.org> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
1 parent 62ef31e commit 5430a02

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
@@ -298,6 +298,27 @@ config ARM64_ERRATUM_832075
298298

299299
If unsure, say Y.
300300

301+
config ARM64_ERRATUM_845719
302+
bool "Cortex-A53: 845719: a load might read incorrect data"
303+
depends on COMPAT
304+
default y
305+
help
306+
This option adds an alternative code sequence to work around ARM
307+
erratum 845719 on Cortex-A53 parts up to r0p4.
308+
309+
When running a compat (AArch32) userspace on an affected Cortex-A53
310+
part, a load at EL0 from a virtual address that matches the bottom 32
311+
bits of the virtual address used by a recent load at (AArch64) EL1
312+
might return incorrect data.
313+
314+
The workaround is to write the contextidr_el1 register on exception
315+
return to a 32-bit task.
316+
Please note that this does not necessarily enable the workaround,
317+
as it depends on the alternative framework, which will only patch
318+
the kernel if an affected CPU is detected.
319+
320+
If unsure, say Y.
321+
301322
endmenu
302323

303324

‎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 NCAPS 2
28+
#define 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
@@ -90,6 +90,14 @@ struct arm64_cpu_capabilities arm64_errata[] = {
9090
.capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE,
9191
MIDR_RANGE(MIDR_CORTEX_A57, 0x00, 0x12),
9292
},
93+
#endif
94+
#ifdef CONFIG_ARM64_ERRATUM_845719
95+
{
96+
/* Cortex-A53 r0p[01234] */
97+
.desc = "ARM erratum 845719",
98+
.capability = ARM64_WORKAROUND_845719,
99+
MIDR_RANGE(MIDR_CORTEX_A53, 0x00, 0x04),
100+
},
93101
#endif
94102
{
95103
}

‎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>
@@ -118,6 +120,24 @@
118120
.if \el == 0
119121
ct_user_enter
120122
ldr x23, [sp, #S_SP] // load return stack pointer
123+
124+
#ifdef CONFIG_ARM64_ERRATUM_845719
125+
alternative_insn \
126+
"nop", \
127+
"tbz x22, #4, 1f", \
128+
ARM64_WORKAROUND_845719
129+
#ifdef CONFIG_PID_IN_CONTEXTIDR
130+
alternative_insn \
131+
"nop; nop", \
132+
"mrs x29, contextidr_el1; msr contextidr_el1, x29; 1:", \
133+
ARM64_WORKAROUND_845719
134+
#else
135+
alternative_insn \
136+
"nop", \
137+
"msr contextidr_el1, xzr; 1:", \
138+
ARM64_WORKAROUND_845719
139+
#endif
140+
#endif
121141
.endif
122142
.if \ret
123143
ldr x1, [sp, #S_X1] // preserve x0 (syscall return)

0 commit comments

Comments
 (0)