Skip to content

Commit df057cc

Browse files
committed
arm64: errata: add module build workaround for erratum #843419
Cortex-A53 processors <= r0p4 are affected by erratum #843419 which can lead to a memory access using an incorrect address in certain sequences headed by an ADRP instruction. There is a linker fix to generate veneers for ADRP instructions, but this doesn't work for kernel modules which are built as unlinked ELF objects. This patch adds a new config option for the erratum which, when enabled, builds kernel modules with the mcmodel=large flag. This uses absolute addressing for all kernel symbols, thereby removing the use of ADRP as a PC-relative form of addressing. The ADRP relocs are removed from the module loader so that we fail to load any potentially affected modules. Cc: <stable@vger.kernel.org> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent bdec97a commit df057cc

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

arch/arm64/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,22 @@ config ARM64_ERRATUM_845719
332332

333333
If unsure, say Y.
334334

335+
config ARM64_ERRATUM_843419
336+
bool "Cortex-A53: 843419: A load or store might access an incorrect address"
337+
depends on MODULES
338+
default y
339+
help
340+
This option builds kernel modules using the large memory model in
341+
order to avoid the use of the ADRP instruction, which can cause
342+
a subsequent memory access to use an incorrect address on Cortex-A53
343+
parts up to r0p4.
344+
345+
Note that the kernel itself must be linked with a version of ld
346+
which fixes potentially affected ADRP instructions through the
347+
use of veneers.
348+
349+
If unsure, say Y.
350+
335351
endmenu
336352

337353

arch/arm64/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ endif
4141

4242
CHECKFLAGS += -D__aarch64__
4343

44+
ifeq ($(CONFIG_ARM64_ERRATUM_843419), y)
45+
CFLAGS_MODULE += -mcmodel=large
46+
endif
47+
4448
# Default value
4549
head-y := arch/arm64/kernel/head.o
4650

arch/arm64/kernel/module.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,14 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
332332
ovf = reloc_insn_imm(RELOC_OP_PREL, loc, val, 0, 21,
333333
AARCH64_INSN_IMM_ADR);
334334
break;
335+
#ifndef CONFIG_ARM64_ERRATUM_843419
335336
case R_AARCH64_ADR_PREL_PG_HI21_NC:
336337
overflow_check = false;
337338
case R_AARCH64_ADR_PREL_PG_HI21:
338339
ovf = reloc_insn_imm(RELOC_OP_PAGE, loc, val, 12, 21,
339340
AARCH64_INSN_IMM_ADR);
340341
break;
342+
#endif
341343
case R_AARCH64_ADD_ABS_LO12_NC:
342344
case R_AARCH64_LDST8_ABS_LO12_NC:
343345
overflow_check = false;

0 commit comments

Comments
 (0)