powerpc/prom_init: Undo relocation before entering secure mode
Subsystems (2)
PATCH 1/1 powerpc/prom_init: Undo relocation before entering secure mode
The ultravisor will do an integrity check of the kernel image but we relocated it so the check will fail. Restore the original image by relocating it back to the kernel virtual base address.
This works because during build vmlinux is linked with an expected virtual runtime address of KERNELBASE.
--- arch/powerpc/include/asm/elf.h | 3 +++ arch/powerpc/kernel/prom_init.c | 11 +++++++++++ arch/powerpc/kernel/prom_init_check.sh | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/elf.h +3 -0
@@ -175,4 +175,7 @@ do { \ARCH_DLINFO_CACHE_GEOMETRY ; \ } while (0) +/* Relocate the kernel image to @final_address */ +void relocate(unsigned long final_address); +#endif /* _ASM_POWERPC_ELF_H */
arch/powerpc/kernel/prom_init.c +11 -0
@@ -3249,7 +3249,18 @@ static void setup_secure_guest(unsigned long kbase, unsigned long fdt)/* Switch to secure mode. */ prom_printf ("Switching to secure mode.\n" ); +/* +* The ultravisor will do an integrity check of the kernel image but we +* relocated it so the check will fail. Restore the original image by +* relocating it back to the kernel virtual base address. +*/ +relocate (KERNELBASE ); + ret =enter_secure_mode (kbase, fdt); + +/* Relocate the kernel again. */ +relocate (kbase); +if (ret !=U_SUCCESS ) {prom_printf ("Returned %d from switching to secure mode.\n" , ret);prom_rtas_os_term ("Switch to secure mode failed.\n" );
arch/powerpc/kernel/prom_init_check.sh +2 -1
@@ -26,7 +26,8 @@ _end enter_prom $MEM_FUNCS reloc_offset __secondary_hold __secondary_hold_acknowledge __secondary_hold_spinloop __start logo_linux_clut224 btext_prepare_BAT reloc_got2 kernstart_addr memstart_addr linux_banner _stext -__prom_init_toc_start __prom_init_toc_end btext_setup_display TOC." +__prom_init_toc_start __prom_init_toc_end btext_setup_display TOC. +relocate" NM="$1" OBJ="$2"
Quoted 9 lines · Thiago Jung Bauermann
The ultravisor will do an integrity check of the kernel image but we relocated it so the check will fail. Restore the original image by relocating it back to the kernel virtual base address.
This works because during build vmlinux is linked with an expected virtual runtime address of KERNELBASE.
Fixes 6a9c930bd775 ("powerpc/prom_init: Add the ESM call to prom_init")Signed-off-by Thiago Jung Bauermann <[email protected]>
I meant to put a Suggested-by: Paul Mackerras <[email protected]>
Sorry. Will add it if there's a v2.
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Quoted 9 lines · Thiago Jung Bauermann
Quoted 7 lines · Thiago Jung Bauermann
The ultravisor will do an integrity check of the kernel image but we relocated it so the check will fail. Restore the original image by relocating it back to the kernel virtual base address.
This works because during build vmlinux is linked with an expected virtual runtime address of KERNELBASE.
Quoted 6 lines
Quoted 2 lines
Fixes 6a9c930bd775 ("powerpc/prom_init: Add the ESM call to prom_init")Signed-off-by Thiago Jung Bauermann <[email protected]>I meant to put a Suggested-by: Paul Mackerras <[email protected]>
Sorry. Will add it if there's a v2.
Ping?
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Quoted 9 lines · Thiago Jung Bauermann
The ultravisor will do an integrity check of the kernel image but we relocated it so the check will fail. Restore the original image by relocating it back to the kernel virtual base address.
This works because during build vmlinux is linked with an expected virtual runtime address of KERNELBASE.
Fixes 6a9c930bd775 ("powerpc/prom_init: Add the ESM call to prom_init")Signed-off-by Thiago Jung Bauermann <[email protected]>
Quoted 55 lines
--- arch/powerpc/include/asm/elf.h | 3 +++ arch/powerpc/kernel/prom_init.c | 11 +++++++++++ arch/powerpc/kernel/prom_init_check.sh | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-)arch/powerpc/include/asm/elf.h +3
-0@@ -175,4 +175,7 @@ do { \ARCH_DLINFO_CACHE_GEOMETRY ; \ } while (0) +/* Relocate the kernel image to @final_address */ +void relocate(unsigned long final_address); +#endif /* _ASM_POWERPC_ELF_H */ arch/powerpc/kernel/prom_init.c +11
-0@@ -3249,7 +3249,18 @@ static void setup_secure_guest(unsigned long kbase, unsigned long fdt)/* Switch to secure mode. */ prom_printf ("Switching to secure mode.\n" ); +/* +* The ultravisor will do an integrity check of the kernel image but we +* relocated it so the check will fail. Restore the original image by +* relocating it back to the kernel virtual base address. +*/ +relocate (KERNELBASE ); + ret =enter_secure_mode (kbase, fdt); + +/* Relocate the kernel again. */ +relocate (kbase); +if (ret !=U_SUCCESS ) {prom_printf ("Returned %d from switching to secure mode.\n" , ret);prom_rtas_os_term ("Switch to secure mode failed.\n" );arch/powerpc/kernel/prom_init_check.sh +2
-1@@ -26,7 +26,8 @@ _end enter_prom $MEM_FUNCS reloc_offset __secondary_hold __secondary_hold_acknowledge __secondary_hold_spinloop __start logo_linux_clut224 btext_prepare_BAT reloc_got2 kernstart_addr memstart_addr linux_banner _stext -__prom_init_toc_start __prom_init_toc_end btext_setup_display TOC." +__prom_init_toc_start __prom_init_toc_end btext_setup_display TOC. +relocate" NM="$1" OBJ="$2"
Signature · 1 line
Ram Pai
Michael Ellerman
reviewerQuoted 7 lines · Thiago Jung Bauermann
The ultravisor will do an integrity check of the kernel image but we relocated it so the check will fail. Restore the original image by relocating it back to the kernel virtual base address.
This works because during build vmlinux is linked with an expected virtual runtime address of KERNELBASE.
Quoted 7 lines
Fixes 6a9c930bd775 ("powerpc/prom_init: Add the ESM call to prom_init")Signed-off-by Thiago Jung Bauermann <[email protected]>--- arch/powerpc/include/asm/elf.h | 3 +++ arch/powerpc/kernel/prom_init.c | 11 +++++++++++ arch/powerpc/kernel/prom_init_check.sh | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-)
This breaks the build when CONFIG_RELOCATABLE=n:
prom_init.c:(.init.text+0x3160): undefined reference to `relocate'
See http://kisskb.ellerman.id.au/kisskb/buildresult/14004234/
cheers
Michael Ellerman
AppliedQuoted 9 lines · Thiago Jung Bauermann
The ultravisor will do an integrity check of the kernel image but we relocated it so the check will fail. Restore the original image by relocating it back to the kernel virtual base address.
This works because during build vmlinux is linked with an expected virtual runtime address of KERNELBASE.
Fixes 6a9c930bd775 ("powerpc/prom_init: Add the ESM call to prom_init")Signed-off-by Thiago Jung Bauermann <[email protected]>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/05d9a952832cb206a32e3705eff6edebdb2207e7
cheers