* [PATCH] riscv/kexec_file: Handle R_RISCV_64 in purgatory relocator
@ 2025-03-26 5:14 Yao Zi
2025-03-26 17:04 ` Björn Töpel
2025-04-03 16:20 ` patchwork-bot+linux-riscv
0 siblings, 2 replies; 4+ messages in thread
From: Yao Zi @ 2025-03-26 5:14 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Pasha Tatashin, Kent Overstreet, Petr Tesarik, Ying Sun,
Samuel Holland
Cc: linux-riscv, linux-kernel, Han Gao, Yao Zi
Commit 58ff537109ac ("riscv: Omit optimized string routines when
using KASAN") introduced calls to EXPORT_SYMBOL() in assembly string
routines, which result in R_RISCV_64 relocations against
.export_symbol section. As these rountines are reused by RISC-V
purgatory and our relocator doesn't recognize these relocations, this
fails kexec-file-load with dmesg like
[ 11.344251] kexec_image: Unknown rela relocation: 2
[ 11.345972] kexec_image: Error loading purgatory ret=-8
Let's support R_RISCV_64 relocation to fix kexec on 64-bit RISC-V.
32-bit variant isn't covered since KEXEC_FILE and KEXEC_PURGATORY isn't
available.
Fixes: 58ff537109ac ("riscv: Omit optimized string routines when using KASAN")
Signed-off-by: Yao Zi <ziyao@disroot.org>
---
I noticed RISC-V support hasn't been merged into kexec-tools, so this
patch is tested with this dowmstream branch[1].
Thanks for your time and review.
[1]: https://github.com/ziyao233/kexec-tools/tree/rv-Image
arch/riscv/kernel/elf_kexec.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
index 3c37661801f9..e783a72d051f 100644
--- a/arch/riscv/kernel/elf_kexec.c
+++ b/arch/riscv/kernel/elf_kexec.c
@@ -468,6 +468,9 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
case R_RISCV_ALIGN:
case R_RISCV_RELAX:
break;
+ case R_RISCV_64:
+ *(u64 *)loc = val;
+ break;
default:
pr_err("Unknown rela relocation: %d\n", r_type);
return -ENOEXEC;
--
2.49.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] riscv/kexec_file: Handle R_RISCV_64 in purgatory relocator
2025-03-26 5:14 [PATCH] riscv/kexec_file: Handle R_RISCV_64 in purgatory relocator Yao Zi
@ 2025-03-26 17:04 ` Björn Töpel
2025-03-26 19:54 ` Björn Töpel
2025-04-03 16:20 ` patchwork-bot+linux-riscv
1 sibling, 1 reply; 4+ messages in thread
From: Björn Töpel @ 2025-03-26 17:04 UTC (permalink / raw)
To: Yao Zi, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Pasha Tatashin, Kent Overstreet, Petr Tesarik,
Ying Sun, Samuel Holland
Cc: linux-riscv, linux-kernel, Han Gao, Yao Zi
Yao Zi <ziyao@disroot.org> writes:
> Commit 58ff537109ac ("riscv: Omit optimized string routines when
> using KASAN") introduced calls to EXPORT_SYMBOL() in assembly string
> routines, which result in R_RISCV_64 relocations against
> .export_symbol section. As these rountines are reused by RISC-V
> purgatory and our relocator doesn't recognize these relocations, this
> fails kexec-file-load with dmesg like
>
> [ 11.344251] kexec_image: Unknown rela relocation: 2
> [ 11.345972] kexec_image: Error loading purgatory ret=-8
>
> Let's support R_RISCV_64 relocation to fix kexec on 64-bit RISC-V.
> 32-bit variant isn't covered since KEXEC_FILE and KEXEC_PURGATORY isn't
> available.
Hi!
This patch does fix the vmlinux loading for kexec-file -- very nice!
However, I haven't been able to get kexec to successfully boot a kernel
from qemu, i.e.:
kexec -s -l /path/to/vmlinux # fixed w/ your patch
kexec -e # hangs after "Bye..."
Same when I try vanilla kexec (kexec -c -l /path/to/vmlinux). kexec with
an Image works for me in qemu.
Before I start to bisect too much; What config/qemu did you use to test
this?
Thanks,
Björn
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] riscv/kexec_file: Handle R_RISCV_64 in purgatory relocator
2025-03-26 17:04 ` Björn Töpel
@ 2025-03-26 19:54 ` Björn Töpel
0 siblings, 0 replies; 4+ messages in thread
From: Björn Töpel @ 2025-03-26 19:54 UTC (permalink / raw)
To: Yao Zi, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Pasha Tatashin, Kent Overstreet, Petr Tesarik,
Ying Sun, Samuel Holland
Cc: linux-riscv, linux-kernel, Han Gao, Yao Zi
Björn Töpel <bjorn@kernel.org> writes:
> Yao Zi <ziyao@disroot.org> writes:
>
>> Commit 58ff537109ac ("riscv: Omit optimized string routines when
>> using KASAN") introduced calls to EXPORT_SYMBOL() in assembly string
>> routines, which result in R_RISCV_64 relocations against
>> .export_symbol section. As these rountines are reused by RISC-V
>> purgatory and our relocator doesn't recognize these relocations, this
>> fails kexec-file-load with dmesg like
>>
>> [ 11.344251] kexec_image: Unknown rela relocation: 2
>> [ 11.345972] kexec_image: Error loading purgatory ret=-8
>>
>> Let's support R_RISCV_64 relocation to fix kexec on 64-bit RISC-V.
>> 32-bit variant isn't covered since KEXEC_FILE and KEXEC_PURGATORY isn't
>> available.
>
> Hi!
>
> This patch does fix the vmlinux loading for kexec-file -- very nice!
> However, I haven't been able to get kexec to successfully boot a kernel
> from qemu, i.e.:
>
> kexec -s -l /path/to/vmlinux # fixed w/ your patch
> kexec -e # hangs after "Bye..."
>
> Same when I try vanilla kexec (kexec -c -l /path/to/vmlinux). kexec with
> an Image works for me in qemu.
>
> Before I start to bisect too much; What config/qemu did you use to test
> this?
Nevermind! Got it to work; Sorry for the noise.
Tested-by: Björn Töpel <bjorn@rivosinc.com>
Reviewed-by: Björn Töpel <bjorn@rivosinc.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] riscv/kexec_file: Handle R_RISCV_64 in purgatory relocator
2025-03-26 5:14 [PATCH] riscv/kexec_file: Handle R_RISCV_64 in purgatory relocator Yao Zi
2025-03-26 17:04 ` Björn Töpel
@ 2025-04-03 16:20 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+linux-riscv @ 2025-04-03 16:20 UTC (permalink / raw)
To: Yao Zi
Cc: linux-riscv, paul.walmsley, palmer, aou, alex, pasha.tatashin,
kent.overstreet, petr, sunying, samuel.holland, linux-kernel,
rabenda.cn
Hello:
This patch was applied to riscv/linux.git (for-next)
by Alexandre Ghiti <alexghiti@rivosinc.com>:
On Wed, 26 Mar 2025 05:14:46 +0000 you wrote:
> Commit 58ff537109ac ("riscv: Omit optimized string routines when
> using KASAN") introduced calls to EXPORT_SYMBOL() in assembly string
> routines, which result in R_RISCV_64 relocations against
> .export_symbol section. As these rountines are reused by RISC-V
> purgatory and our relocator doesn't recognize these relocations, this
> fails kexec-file-load with dmesg like
>
> [...]
Here is the summary with links:
- riscv/kexec_file: Handle R_RISCV_64 in purgatory relocator
https://git.kernel.org/riscv/c/28093cfef5dd
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-03 16:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-26 5:14 [PATCH] riscv/kexec_file: Handle R_RISCV_64 in purgatory relocator Yao Zi
2025-03-26 17:04 ` Björn Töpel
2025-03-26 19:54 ` Björn Töpel
2025-04-03 16:20 ` 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
all inboxes | Powered by JetHome®