Skip to content

Commit a11c07f

Browse files
mickflemmpalmer-dabbelt
authored andcommitted
riscv: Don't use va_pa_offset on kdump
On kdump instead of using an intermediate step to relocate the kernel, that lives in a "control buffer" outside the current kernel's mapping, we jump to the crash kernel directly by calling riscv_kexec_norelocate(). The current implementation uses va_pa_offset while switching to physical addressing, however since we moved the kernel outside the linear mapping this won't work anymore since riscv_kexec_norelocate() is part of the kernel mapping and we should use kernel_map.va_kernel_pa_offset, and also take XIP kernel into account. We don't really need to use va_pa_offset on riscv_kexec_norelocate, we can just set STVEC to the physical address of the new kernel instead and let the hart jump to the new kernel on the next instruction after setting SATP to zero. This fixes kdump and is also simpler/cleaner. I tested this on the latest qemu and HiFive Unmatched and works as expected. Fixes: 2bfc6cd ("riscv: Move kernel mapping outside of linear mapping") Signed-off-by: Nick Kossifidis <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 893eae9 commit a11c07f

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

arch/riscv/kernel/kexec_relocate.S

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,15 @@ SYM_CODE_START(riscv_kexec_norelocate)
159159
* s0: (const) Phys address to jump to
160160
* s1: (const) Phys address of the FDT image
161161
* s2: (const) The hartid of the current hart
162-
* s3: (const) kernel_map.va_pa_offset, used when switching MMU off
163162
*/
164163
mv s0, a1
165164
mv s1, a2
166165
mv s2, a3
167-
mv s3, a4
168166

169167
/* Disable / cleanup interrupts */
170168
csrw CSR_SIE, zero
171169
csrw CSR_SIP, zero
172170

173-
/* Switch to physical addressing */
174-
la s4, 1f
175-
sub s4, s4, s3
176-
csrw CSR_STVEC, s4
177-
csrw CSR_SATP, zero
178-
179-
.align 2
180-
1:
181171
/* Pass the arguments to the next kernel / Cleanup*/
182172
mv a0, s2
183173
mv a1, s1
@@ -214,7 +204,15 @@ SYM_CODE_START(riscv_kexec_norelocate)
214204
csrw CSR_SCAUSE, zero
215205
csrw CSR_SSCRATCH, zero
216206

217-
jalr zero, a2, 0
207+
/*
208+
* Switch to physical addressing
209+
* This will also trigger a jump to CSR_STVEC
210+
* which in this case is the address of the new
211+
* kernel.
212+
*/
213+
csrw CSR_STVEC, a2
214+
csrw CSR_SATP, zero
215+
218216
SYM_CODE_END(riscv_kexec_norelocate)
219217

220218
.section ".rodata"

0 commit comments

Comments
 (0)