arm64: reduce trampoline data alignment
PATCH 1/1 arm64: reduce trampoline data alignment
From: Remi Denis-Courmont <[email protected]>
The trampoline data, currently consisting of two relocated pointers, must be within a single page. However, there are no needs for it to start a page.
This reduces the alignment to 16 bytes, which ensures that the 16 bytes of data are in the same page.
This patch assumes that the page alignment was just a quick and dirty trick to not worry about fixmap. If however the page alignment was meant to present a data page with no other data than the trampoline's, then both the current code and this patch are wrong.
--- arch/arm64/kernel/entry.S | 6 +++--- arch/arm64/mm/mmu.c | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-)
arch/arm64/kernel/entry.S +3 -3
@@ -805,9 +805,9 @@ alternative_else_nop_endif 2: tramp_map_kernel x30 #ifdef CONFIG_RANDOMIZE_BASE - adr x30, tramp_vectors + PAGE_SIZE + adrp x30, tramp_vectors + PAGE_SIZE alternative_insn isb, nop, ARM64_WORKAROUND_QCOM_FALKOR_E1003 - ldr x30, [x30] + ldr x30, [x30, #:lo12:__entry_tramp_data_start] #else ldr x30, =vectors #endif
@@ -858,7 +858,7 @@ END(tramp_exit_compat) .popsection // .entry.tramp.text #ifdef CONFIG_RANDOMIZE_BASE .pushsection ".rodata", "a" - .align PAGE_SHIFT + .align 4 .globl __entry_tramp_data_start __entry_tramp_data_start: .quad vectors
arch/arm64/mm/mmu.c +2 -3
@@ -599,9 +599,8 @@ static int __init map_entry_trampoline(void)if (IS_ENABLED (CONFIG_RANDOMIZE_BASE )) {extern char __entry_tramp_data_start[]; -__set_fixmap (FIX_ENTRY_TRAMP_DATA , -__pa_symbol (__entry_tramp_data_start), -PAGE_KERNEL_RO ); + pa_start =__pa_symbol (__entry_tramp_data_start) &PAGE_MASK ; +__set_fixmap (FIX_ENTRY_TRAMP_DATA , pa_start,PAGE_KERNEL_RO ); }return 0 ;
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Rutland
reviewer[adding arm64 folk]
Quoted 6 lines · Rémi Denis-Courmont
From: Remi Denis-Courmont <[email protected]>
The trampoline data, currently consisting of two relocated pointers, must be within a single page. However, there are no needs for it to start a page.
Quoted 7 lines
This reduces the alignment to 16 bytes, which ensures that the 16 bytes of data are in the same page.
This patch assumes that the page alignment was just a quick and dirty trick to not worry about fixmap. If however the page alignment was meant to present a data page with no other data than the trampoline's, then both the current code and this patch are wrong.
I think that aligning it to a page was a simplification overall, not just for the fixmap. However, I do agree that as the page isn't mapped during EL0 execution, it's fine for other bits of .rodata to share the page.
I also think that it's a bit scary that we rely on nothing being placed in .rodata between __entry_tramp_data_start and __sdei_asm_trampoline_next_handler, since macros could easily place something between the two. Luckily NOKPROBE() adds stuff to .init.data, but I had to check.
I think it would be better to add a new .entry.tramp.data section to ensure that, which we can align appropriately in the linker script.
Thanks,
Mark.
Quoted 56 lines
Signed-off-by Remi Denis-Courmont <[email protected]>--- arch/arm64/kernel/entry.S | 6 +++--- arch/arm64/mm/mmu.c | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-)arch/arm64/kernel/entry.S +3
-3@@ -805,9 +805,9 @@ alternative_else_nop_endif 2: tramp_map_kernel x30 #ifdef CONFIG_RANDOMIZE_BASE - adr x30, tramp_vectors + PAGE_SIZE + adrp x30, tramp_vectors + PAGE_SIZE alternative_insn isb, nop, ARM64_WORKAROUND_QCOM_FALKOR_E1003 - ldr x30, [x30] + ldr x30, [x30, #:lo12:__entry_tramp_data_start] #else ldr x30, =vectors #endif@@ -858,7 +858,7 @@ END(tramp_exit_compat) .popsection // .entry.tramp.text #ifdef CONFIG_RANDOMIZE_BASE .pushsection ".rodata", "a" - .align PAGE_SHIFT + .align 4 .globl __entry_tramp_data_start __entry_tramp_data_start: .quad vectorsarch/arm64/mm/mmu.c +2
-3@@ -599,9 +599,8 @@ static int __init map_entry_trampoline(void)if (IS_ENABLED (CONFIG_RANDOMIZE_BASE )) {extern char __entry_tramp_data_start[]; -__set_fixmap (FIX_ENTRY_TRAMP_DATA , -__pa_symbol (__entry_tramp_data_start), -PAGE_KERNEL_RO ); + pa_start =__pa_symbol (__entry_tramp_data_start) &PAGE_MASK ; +__set_fixmap (FIX_ENTRY_TRAMP_DATA , pa_start,PAGE_KERNEL_RO ); }return 0 ;Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerQuoted 11 lines · Mark Rutland
[adding arm64 folk]
Quoted 8 lines · Rémi Denis-Courmont
From: Remi Denis-Courmont <[email protected]>
The trampoline data, currently consisting of two relocated pointers, must be within a single page. However, there are no needs for it to start a page.
This reduces the alignment to 16 bytes, which ensures that the 16 bytes of data are in the same page.
I don't follow this bit: it's one 8 byte pointer.
Quoted 10 lines
Quoted 4 lines
This patch assumes that the page alignment was just a quick and dirty trick to not worry about fixmap. If however the page alignment was meant to present a data page with no other data than the trampoline's, then both the current code and this patch are wrong.
I think that aligning it to a page was a simplification overall, not just for the fixmap. However, I do agree that as the page isn't mapped during EL0 execution, it's fine for other bits of .rodata to share the page.
Quoted 8 lines
I also think that it's a bit scary that we rely on nothing being placed in .rodata between
__entry_tramp_data_startand__sdei_asm_trampoline_next_handler, since macros could easily place something between the two. LuckilyNOKPROBE()adds stuff to .init.data, but I had to check.I think it would be better to add a new .entry.tramp.data section to ensure that, which we can align appropriately in the linker script.
Remi's patch looks fine though, no? (modulo the confusing commit message)
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Le 2020-03-05 11:23, Will Deacon a écrit :
Quoted 6 lines · Mark Rutland
Quoted 5 lines
[adding arm64 folk]
Quoted 2 lines · Rémi Denis-Courmont
From: Remi Denis-Courmont <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
The trampoline data, currently consisting of two relocated pointers, must be within a single page. However, there are no needs for it to start a page.
This reduces the alignment to 16 bytes, which ensures that the 16 bytes of data are in the same page.
I don't follow this bit: it's one 8 byte pointer.
I guess I misread the quad pseudo op as 4x4 instead of 4x2 bytes.
So it might actually be possible to remove the align stanza completely...
Quoted 16 lines
Quoted 16 lines
Quoted 4 lines
This patch assumes that the page alignment was just a quick and dirty trick to not worry about fixmap. If however the page alignment was meant to present a data page with no other data than the trampoline's, then both the current code and this patch are wrong.
I think that aligning it to a page was a simplification overall, not just for the fixmap. However, I do agree that as the page isn't mapped during EL0 execution, it's fine for other bits of .rodata to share the page.
I also think that it's a bit scary that we rely on nothing being placed in .rodata between
__entry_tramp_data_startand__sdei_asm_trampoline_next_handler, since macros could easily place something between the two. LuckilyNOKPROBE()adds stuff to .init.data, but I had to check.
Quoted 4 lines
Quoted 2 lines
I think it would be better to add a new .entry.tramp.data section to ensure that, which we can align appropriately in the linker script.
Remi's patch looks fine though, no? (modulo the confusing commit message)
... though now I'm not sure if we want to have a separate .tramp.rodata section, a separate page within .rodata, or just a fixed version of this patch?
I suppose it's a tradeoff between peace of mind regarding leaking kernel read-only data in the trampoline mappings versus memory use?
Signature · 6 lines
Rémi Denis-Courmont _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Rutland
reviewerQuoted 6 lines · Will Deacon
Quoted 5 lines · Mark Rutland
[adding arm64 folk]
Quoted 2 lines · Rémi Denis-Courmont
From: Remi Denis-Courmont <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
The trampoline data, currently consisting of two relocated pointers, must be within a single page. However, there are no needs for it to start a page.
This reduces the alignment to 16 bytes, which ensures that the 16 bytes of data are in the same page.
I don't follow this bit: it's one 8 byte pointer.
When the kernel is built with SDEI, there are two 8-byte pointers that need to live in the same page: the one at __entry_tramp_data_start and the one at __sdei_asm_trampoline_next_handler.
Reducing the alignment to 8 would mean that the SDEI pointer could get placed in a separate page, and we'd generate a bogus address in __sdei_asm_entry_trampoline.
Quoted 16 lines
Quoted 16 lines
Quoted 4 lines
This patch assumes that the page alignment was just a quick and dirty trick to not worry about fixmap. If however the page alignment was meant to present a data page with no other data than the trampoline's, then both the current code and this patch are wrong.
I think that aligning it to a page was a simplification overall, not just for the fixmap. However, I do agree that as the page isn't mapped during EL0 execution, it's fine for other bits of .rodata to share the page.
I also think that it's a bit scary that we rely on nothing being placed in .rodata between
__entry_tramp_data_startand__sdei_asm_trampoline_next_handler, since macros could easily place something between the two. LuckilyNOKPROBE()adds stuff to .init.data, but I had to check.
Quoted 4 lines
Quoted 2 lines
I think it would be better to add a new .entry.tramp.data section to ensure that, which we can align appropriately in the linker script.
Remi's patch looks fine though, no? (modulo the confusing commit message)
It looks fine, I just think that if we're going to clean this up it'd be good to make it more robust. Given how easy it is to miss the SDEI case (as above), it's likely that'll get broken, and it's rarely tested.
Thanks,
Mark.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel