Message ID | 20240911095550.31139-1-frediano.ziglio@cloud.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v2] x86: Put trampoline in separate .init.trampoline section | expand |
On 11.09.2024 11:55, Frediano Ziglio wrote: > --- a/xen/arch/x86/boot/head.S > +++ b/xen/arch/x86/boot/head.S > @@ -882,8 +882,9 @@ cmdline_parse_early: > reloc: > .incbin "reloc.bin" > > +#include "x86_64.S" > + > + .section .init.trampoline, "aw", @progbits > ENTRY(trampoline_start) > #include "trampoline.S" > ENTRY(trampoline_end) Hmm, nice - this turns out rather easier than I first thought. > --- a/xen/arch/x86/xen.lds.S > +++ b/xen/arch/x86/xen.lds.S > @@ -269,6 +269,11 @@ SECTIONS > __ctors_end = .; > } PHDR(text) > > + . = ALIGN(PAGE_SIZE); Why? There's no special alignment right now. > + DECL_SECTION(.init.trampoline) { > + *(.init.trampoline) > + } PHDR(text) > + > #ifndef EFI If this is to be a separate section also for ELF, I think that wants mentioning explicitly. "Easily disassemble" is too vague a reason for my taste. Jan
On Sat, Sep 14, 2024 at 7:16 AM Jan Beulich <jbeulich@suse.com> wrote: > > On 11.09.2024 11:55, Frediano Ziglio wrote: > > --- a/xen/arch/x86/boot/head.S > > +++ b/xen/arch/x86/boot/head.S > > @@ -882,8 +882,9 @@ cmdline_parse_early: > > reloc: > > .incbin "reloc.bin" > > > > +#include "x86_64.S" > > + > > + .section .init.trampoline, "aw", @progbits > > ENTRY(trampoline_start) > > #include "trampoline.S" > > ENTRY(trampoline_end) > > Hmm, nice - this turns out rather easier than I first thought. > > > --- a/xen/arch/x86/xen.lds.S > > +++ b/xen/arch/x86/xen.lds.S > > @@ -269,6 +269,11 @@ SECTIONS > > __ctors_end = .; > > } PHDR(text) > > > > + . = ALIGN(PAGE_SIZE); > > Why? There's no special alignment right now. > UEFI CA Memory Mitigation requirements, I'll remove from this commit. > > + DECL_SECTION(.init.trampoline) { > > + *(.init.trampoline) > > + } PHDR(text) > > + > > #ifndef EFI > > If this is to be a separate section also for ELF, I think that > wants mentioning explicitly. "Easily disassemble" is too vague > a reason for my taste. It's not clear if either you changed your mind on that reason or if the commit message is not clear. I'm assuming the latter, I'll improve the commit message. Not clear why you specify "ELF" in the above sentence, I mean, why should it matter if it applies to EFI and/or ELF? And why having it different from ELF to EFI? > > Jan Frediano
On 16.09.2024 11:11, Frediano Ziglio wrote: > On Sat, Sep 14, 2024 at 7:16 AM Jan Beulich <jbeulich@suse.com> wrote: >> On 11.09.2024 11:55, Frediano Ziglio wrote: >>> + DECL_SECTION(.init.trampoline) { >>> + *(.init.trampoline) >>> + } PHDR(text) >>> + >>> #ifndef EFI >> >> If this is to be a separate section also for ELF, I think that >> wants mentioning explicitly. "Easily disassemble" is too vague >> a reason for my taste. > > It's not clear if either you changed your mind on that reason or if > the commit message is not clear. I'm assuming the latter, I'll improve > the commit message. > Not clear why you specify "ELF" in the above sentence, I mean, why > should it matter if it applies to EFI and/or ELF? And why having it > different from ELF to EFI? Why do we fold sections at all? We could keep them all separate, leading to a big section table with -f{function,data}-sections. If you want to change something, you need to clarify why the change is being made, for every part that is affected. We don't have a need for the separate section in ELF, so it becoming one without at least saying so (and ideally also why) it might look like an oversight / mistake to someone later stumbling across that commit. Jan
diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 12bbb97f33..493286a9fb 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -882,8 +882,9 @@ cmdline_parse_early: reloc: .incbin "reloc.bin" +#include "x86_64.S" + + .section .init.trampoline, "aw", @progbits ENTRY(trampoline_start) #include "trampoline.S" ENTRY(trampoline_end) - -#include "x86_64.S" diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index d48de67cfd..390870e463 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -269,6 +269,11 @@ SECTIONS __ctors_end = .; } PHDR(text) + . = ALIGN(PAGE_SIZE); + DECL_SECTION(.init.trampoline) { + *(.init.trampoline) + } PHDR(text) + #ifndef EFI /* * With --orphan-sections=warn (or =error) we need to handle certain linker
This change put the trampoline in a separate, not executable section. The trampoline contains a mix of code and data (data which is modified from C code during early start so must be writable). This is in preparation for W^X patch in order to satisfy UEFI CA memory mitigation requirements. At the moment .init.text and .init.data in EFI mode are put together so they will be in the same final section as before this patch. Putting in a separate section (even in final executables) allows to easily disassembly that section. Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com> --- Changes since last version: - use completely separate section even on final executables (suggested by Jan Beulich). Changes since v1: - remove useless align. --- xen/arch/x86/boot/head.S | 5 +++-- xen/arch/x86/xen.lds.S | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-)