public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -fixes] riscv: Fix relocatable kernels with early alternatives using -fno-pie
@ 2023-05-26 15:46 Alexandre Ghiti
  2023-05-26 16:24 ` Conor Dooley
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Alexandre Ghiti @ 2023-05-26 15:46 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Andreas Schwab,
	linux-riscv, linux-kernel
  Cc: Alexandre Ghiti

Early alternatives are called with the mmu disabled, and then should not
access any global symbols through the GOT since it requires relocations,
relocations that we do before but *virtually*. So only use medany code
model for this early code.

Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
---

Note that I'm not very happy with this fix, I think we need to put more
effort into "harmonizing" this very early code (ie before the mmu is
enabled) as it is spread between different locations and compiled
differently. I'll work on that later, but for now, this fix does what is
needed to work (from my testing at least). Any Tested-by on the Unmatched
and T-head boards is welcome!

 arch/riscv/errata/Makefile | 4 ++++
 arch/riscv/kernel/Makefile | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/arch/riscv/errata/Makefile b/arch/riscv/errata/Makefile
index a1055965fbee..7b2637c8c332 100644
--- a/arch/riscv/errata/Makefile
+++ b/arch/riscv/errata/Makefile
@@ -1,2 +1,6 @@
+ifdef CONFIG_RELOCATABLE
+KBUILD_CFLAGS += -fno-pie
+endif
+
 obj-$(CONFIG_ERRATA_SIFIVE) += sifive/
 obj-$(CONFIG_ERRATA_THEAD) += thead/
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index fbdccc21418a..153864e4f399 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -23,6 +23,10 @@ ifdef CONFIG_FTRACE
 CFLAGS_REMOVE_alternative.o = $(CC_FLAGS_FTRACE)
 CFLAGS_REMOVE_cpufeature.o = $(CC_FLAGS_FTRACE)
 endif
+ifdef CONFIG_RELOCATABLE
+CFLAGS_alternative.o += -fno-pie
+CFLAGS_cpufeature.o += -fno-pie
+endif
 ifdef CONFIG_KASAN
 KASAN_SANITIZE_alternative.o := n
 KASAN_SANITIZE_cpufeature.o := n
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2023-05-31 15:10 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-26 15:46 [PATCH -fixes] riscv: Fix relocatable kernels with early alternatives using -fno-pie Alexandre Ghiti
2023-05-26 16:24 ` Conor Dooley
2023-05-26 16:35   ` Conor Dooley
2023-05-27  9:13     ` Alexandre Ghiti
2023-05-27 10:02       ` Conor Dooley
2023-05-28 13:00         ` Alexandre Ghiti
2023-05-28 13:12           ` Conor Dooley
2023-05-28 13:42             ` Alexandre Ghiti
2023-05-28 13:56               ` Conor Dooley
2023-05-29 18:51                 ` Alexandre Ghiti
2023-05-29 19:06                   ` Conor Dooley
2023-05-29 19:37                     ` Alexandre Ghiti
2023-05-30 11:27                       ` Conor Dooley
2023-05-30 14:33                         ` Alexandre Ghiti
2023-05-30 17:47                           ` Conor Dooley
2023-05-30 18:04                             ` Alexandre Ghiti
2023-05-30 20:22                               ` Conor Dooley
2023-05-31  7:26                                 ` Alexandre Ghiti
2023-05-31  9:32                                   ` Conor Dooley
2023-05-31 11:03                                     ` Alexandre Ghiti
2023-05-26 16:38   ` Alexandre Ghiti
2023-05-31 15:03 ` Palmer Dabbelt
2023-05-31 15:10 ` patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox