summaryrefslogtreecommitdiffstats
path: root/arch/riscv
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-10-20 15:15:10 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-10-24 11:02:55 +0200
commit184f1b3ccdacc119104d1b401c6e33f78c44ed3d (patch)
tree826876596b2882952e84b09dce1187640fd2a0e5 /arch/riscv
parentf36c980fd6e5112cc72b53c4d665f2b44dd71cc5 (diff)
downloadbarebox-184f1b3ccdacc119104d1b401c6e33f78c44ed3d.tar.gz
barebox-184f1b3ccdacc119104d1b401c6e33f78c44ed3d.tar.xz
RISC-V: add compiler barriers around unrelocated accesses
We observed on ARM miscompilation because get_runtime_offset() was cached before relocation, while address computation of symbol happened after, effectively adding the base address twice to the symbol offset. New runtime_address() hides origin of the symbol going into the address calculation and thereby thwarts this optimization. Employ it in RISC-V code as well to avoid such issues as experienced on ARM. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221020131510.3734338-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/riscv')
-rw-r--r--arch/riscv/boot/uncompress.c4
-rw-r--r--arch/riscv/include/asm/sections.h3
-rw-r--r--arch/riscv/lib/reloc.c10
3 files changed, 11 insertions, 6 deletions
diff --git a/arch/riscv/boot/uncompress.c b/arch/riscv/boot/uncompress.c
index ee24f81e01..84142acf9c 100644
--- a/arch/riscv/boot/uncompress.c
+++ b/arch/riscv/boot/uncompress.c
@@ -36,8 +36,8 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
irq_init_vector(riscv_mode());
/* piggy data is not relocated, so determine the bounds now */
- pg_start = input_data + get_runtime_offset();
- pg_end = input_data_end + get_runtime_offset();
+ pg_start = runtime_address(input_data);
+ pg_end = runtime_address(input_data_end);
pg_len = pg_end - pg_start;
uncompressed_len = input_data_len();
diff --git a/arch/riscv/include/asm/sections.h b/arch/riscv/include/asm/sections.h
index 6673648bcd..cea039cc5e 100644
--- a/arch/riscv/include/asm/sections.h
+++ b/arch/riscv/include/asm/sections.h
@@ -6,6 +6,7 @@
#include <asm-generic/sections.h>
#include <linux/types.h>
#include <asm/unaligned.h>
+#include <asm/reloc.h>
extern char __rel_dyn_start[];
extern char __rel_dyn_end[];
@@ -19,7 +20,7 @@ unsigned long get_runtime_offset(void);
static inline unsigned int input_data_len(void)
{
- return get_unaligned((const u32 *)(input_data_end + get_runtime_offset() - 4));
+ return get_unaligned((const u32 *)runtime_address(input_data_end) - 1);
}
#endif
diff --git a/arch/riscv/lib/reloc.c b/arch/riscv/lib/reloc.c
index 13118a9ac5..0c1ec8b488 100644
--- a/arch/riscv/lib/reloc.c
+++ b/arch/riscv/lib/reloc.c
@@ -42,9 +42,13 @@ void relocate_to_current_adr(void)
if (!offset)
return;
- dstart = __rel_dyn_start + offset;
- dend = __rel_dyn_end + offset;
- dynsym = (void *)__dynsym_start + offset;
+ /*
+ * We have yet to relocate, so using runtime_address
+ * to compute the relocated address
+ */
+ dstart = runtime_address(__rel_dyn_start);
+ dend = runtime_address(__rel_dyn_end);
+ dynsym = runtime_address(__dynsym_start);
for (rela = dstart; (void *)rela < dend; rela++) {
unsigned long *fixup;