[PATCH 4/4] arm64: kexec: Change relocate_kernel to C code
Mark Rutland
mark.rutland at arm.com
Tue Apr 2 02:55:08 PDT 2024
On Thu, Mar 28, 2024 at 07:56:54PM +0800, Pingfan Liu wrote:
> The kexec_relocate.o is a self-contained section, and it should be PIE.
>
> Beside that, C function call requires stack, which is built on the idmap
> of the rear of kimage->control_code_page.
>
> Signed-off-by: Pingfan Liu <piliu at redhat.com>
> Cc: Catalin Marinas <catalin.marinas at arm.com>
> Cc: Will Deacon <will at kernel.org>
> Cc: Ard Biesheuvel <ardb at kernel.org>
> Cc: Kees Cook <keescook at chromium.org>
> Cc: Mark Rutland <mark.rutland at arm.com>
> Cc: Pasha Tatashin <pasha.tatashin at soleen.com>
> To: linux-arm-kernel at lists.infradead.org
> ---
> arch/arm64/kernel/Makefile | 1 +
> arch/arm64/kernel/asm-offsets.c | 10 --
> arch/arm64/kernel/machine_kexec.c | 9 +-
> arch/arm64/kernel/relocate_kernel.S | 100 --------------
> arch/arm64/kernel/relocate_kernel.c | 197 ++++++++++++++++++++++++++++
> arch/arm64/kernel/vmlinux.lds.S | 1 +
> 6 files changed, 206 insertions(+), 112 deletions(-)
> delete mode 100644 arch/arm64/kernel/relocate_kernel.S
> create mode 100644 arch/arm64/kernel/relocate_kernel.c
> +static void __kexec_section turn_mmu_off(void)
> +{
> + u64 tmp = INIT_SCTLR_EL1_MMU_OFF;
> +
> + /* pre_disable_mmu_workaround */
> +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_E1041
> + isb();
> +#endif
> + write_sysreg(tmp, sctlr_el1);
> + isb();
> +}
Disabling the MMU cannot be done from C; as soon as we write to SCTLR_EL1 (even
before the ISB) we cannot safely access the stack until that has been explcitly
cleaned+invalidated to the PoC (and that has to be done by VA).
I don't think we should bother trying to move this to C; the MMU-off portions
should remain as asssembly.
If you want to move the MMU-on portions to C, then *maybe* that's worthwhile, but
given the diffstat I reckon it's better to leave this all as asm for now. We
can make this more legibile without converting it to C.
Mark.
More information about the linux-arm-kernel
mailing list