* [PATCH v5 1/5] Align relevant sections to 4KB
2026-06-26 12:36 [PATCH v5 0/5] Various patches to improve Secure Boot support Frediano Ziglio
@ 2026-06-26 12:36 ` Frediano Ziglio
2026-06-26 12:36 ` [PATCH v5 2/5] x86/efi: discard multiboot and PVH support for PE binary Frediano Ziglio
` (3 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Frediano Ziglio @ 2026-06-26 12:36 UTC (permalink / raw)
To: xen-devel
Cc: Frediano Ziglio, Jan Beulich, Andrew Cooper, Roger Pau Monné,
Teddy Astie, Marek Marczykowski-Górecki, Frediano Ziglio
From: Frediano Ziglio <frediano.ziglio@cloud.com>
Required by UEFI CA memory mitigation.
It is a requirement for NX_COMPAT so the PE can be loaded with W^X perms
in the pagetables.
NX_COMPAT is a requirement from shim-review,
https://github.com/rhboot/shim-review#do-you-have-the-nx-bit-set-in-your-shim-if-so-is-your-entire-boot-stack-nx-compatible-and-what-testing-have-you-done-to-ensure-such-compatibility
Sections with different permissions must be in separate pages.
In the case of debug sections they are contiguous and have the same
permissions, including the immediately preceding .reloc section, so it's
not an issue if they are not aligned to the page.
Before the .debug sections you could have the .reloc or the SBAT section,
either are permission-compatible.
Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
--
Changes since v1:
- Change subject.
Changes since v2:
- Improved commit message and subject.
Changes since v3:
- Added Acked-by;
- Improved commit message.
Changes since v4:
- Added missing comment;
- Added Acked-by.
---
xen/arch/x86/xen.lds.S | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index b9e888e596..8e63cf5bc2 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -162,8 +162,8 @@ SECTIONS
__note_gnu_build_id_end = .;
} PHDR(note) PHDR(text)
#elif defined(BUILD_ID_EFI)
- /* Workaround bug in binutils < 2.36 */
- . = ALIGN(32);
+ /* Align to satisfy UEFI CA memory mitigation. */
+ . = ALIGN(PAGE_SIZE);
DECL_SECTION(.buildid) {
__note_gnu_build_id_start = .;
*(.buildid)
@@ -330,6 +330,8 @@ SECTIONS
__2M_rwdata_end = ALIGN(SECTION_ALIGN);
#ifdef EFI
+ /* Align to satisfy UEFI CA memory mitigation. */
+ . = ALIGN(PAGE_SIZE);
.reloc ALIGN(4) : {
__base_relocs_start = .;
*(.reloc)
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v5 2/5] x86/efi: discard multiboot and PVH support for PE binary
2026-06-26 12:36 [PATCH v5 0/5] Various patches to improve Secure Boot support Frediano Ziglio
2026-06-26 12:36 ` [PATCH v5 1/5] Align relevant sections to 4KB Frediano Ziglio
@ 2026-06-26 12:36 ` Frediano Ziglio
2026-06-29 13:00 ` Jan Beulich
2026-06-26 12:36 ` [PATCH v5 3/5] x86/efi: avoid a relocation in efi_arch_post_exit_boot() Frediano Ziglio
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Frediano Ziglio @ 2026-06-26 12:36 UTC (permalink / raw)
To: xen-devel
Cc: Roger Pau Monné, Jan Beulich, Andrew Cooper, Teddy Astie,
Marek Marczykowski-Górecki, Frediano Ziglio
From: Roger Pau Monné <roger.pau@citrix.com>
Multiboot and PVH booting are not supported for PE, hence discards them
in the linker script when doing a PE build.
That removes some relocations that otherwise appear due to the usage of the
start and __efi64_mb2_start symbols in the multiboot2 header.
Section discarding is not done updating DISCARD_SECTIONS definition as the
change is specific for x86.
No functional change intended.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
--
Changes since v1:
- improve commit message;
- change section orders to avoid changing code order in final executable;
- merge 2 commits;
- removed deprecated documentation section.
Changes since v2:
- Update commit message, join 2 sentences together.
Changes since v3:
- Added Acked-by.
Changes since v4:
- more clear subject;
- removed more code/data from EFI output;
- removed Acked-by.
---
docs/hypervisor-guide/x86/how-xen-boots.rst | 6 ------
xen/arch/x86/boot/head.S | 8 ++++----
xen/arch/x86/xen.lds.S | 9 +++++++++
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/docs/hypervisor-guide/x86/how-xen-boots.rst b/docs/hypervisor-guide/x86/how-xen-boots.rst
index 8b3229005c..b6d852050a 100644
--- a/docs/hypervisor-guide/x86/how-xen-boots.rst
+++ b/docs/hypervisor-guide/x86/how-xen-boots.rst
@@ -82,12 +82,6 @@ When a PEI-capable toolchain is found, the objects are linked together and a
PE32+ binary is created. It can be run directly from the EFI shell, and has
``efi_start`` as its entry symbol.
-.. note::
-
- xen.efi does contain all MB1/MB2/PVH tags included in the rest of the
- build. However, entry via anything other than the EFI64 protocol is
- unsupported, and won't work.
-
Boot
----
diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index 77bb7a9e21..ebdc562207 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -126,7 +126,7 @@ multiboot2_header:
.size multiboot2_header, . - multiboot2_header
.type multiboot2_header, @object
- .section .init.rodata, "a", @progbits
+ .section .init.rodata.multiboot, "a", @progbits
.Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!"
.Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!"
@@ -135,8 +135,7 @@ multiboot2_header:
.Lbag_alg_msg: .asciz "ERR: Xen must be loaded at a 2Mb boundary!"
.Lno_nx_msg: .asciz "ERR: Not an NX-capable CPU!"
- .section .init.data, "aw", @progbits
- .subsection 1 /* Put data here after the page tables (in x86_64.S). */
+ .section .init.data.multiboot, "aw", @progbits
.align 4
.word 0
@@ -152,7 +151,7 @@ vga_text_buffer:
efi_platform:
.byte 0
- .section .init.text, "ax", @progbits
+ .section .init.multiboot, "ax", @progbits
early_error: /* Here to improve the disassembly. */
@@ -710,6 +709,7 @@ trampoline_setup:
/* Jump into the relocated trampoline. */
lret
+ .section .init.text, "ax", @progbits
ENTRY(trampoline_start)
#include "trampoline.S"
ENTRY(trampoline_end)
diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index 8e63cf5bc2..88553513a9 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -57,6 +57,12 @@ SECTIONS
__image_base__ = .;
#else
. = __image_base__;
+ /DISCARD/ : {
+ *(.text.header)
+ *(.init.multiboot)
+ *(.init.data.multiboot)
+ *(.init.rodata.multiboot)
+ }
#endif
#if 0
@@ -195,6 +201,7 @@ SECTIONS
DECL_SECTION(.init.text) {
#endif
_sinittext = .;
+ *(.init.multiboot)
*(.init.text)
*(.text.startup)
_einittext = .;
@@ -220,6 +227,7 @@ SECTIONS
*(.init.rodata.cf_clobber)
__initdata_cf_clobber_end = .;
+ *(.init.rodata.multiboot)
*(.init.rodata)
*(.init.rodata.*)
@@ -234,6 +242,7 @@ SECTIONS
*(.initcall1.init)
__initcall_end = .;
+ *(.init.data.multiboot)
*(.init.data)
*(.init.data.rel)
*(.init.data.rel.*)
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v5 2/5] x86/efi: discard multiboot and PVH support for PE binary
2026-06-26 12:36 ` [PATCH v5 2/5] x86/efi: discard multiboot and PVH support for PE binary Frediano Ziglio
@ 2026-06-29 13:00 ` Jan Beulich
0 siblings, 0 replies; 11+ messages in thread
From: Jan Beulich @ 2026-06-29 13:00 UTC (permalink / raw)
To: Frediano Ziglio
Cc: Roger Pau Monné, Andrew Cooper, Teddy Astie,
Marek Marczykowski-Górecki, Frediano Ziglio, xen-devel
On 26.06.2026 14:36, Frediano Ziglio wrote:
> Changes since v4:
> - more clear subject;
> - removed more code/data from EFI output;
I can see that you excluded a few data items in the assembly file. But is
there actually any more code excluded? In particular the functions I
mentioned in the v4 comments are still going to remain unreachable in the
image. And addressing that doesn't look difficult at all:
tools/combine_two_binaries.py would need to have .init.text replaced just
like you do it in the assembly source.
Another thing is that with it now being crystal clear that the PVH entry
point goes away, code reachable only when it's present (first and foremost
guest/xen/pvh-boot.c) is then also unreachable. Perhaps the objcopy
involved in the .o -> .init.o conversion could be customized to rename
sections in our favor.
> @@ -135,8 +135,7 @@ multiboot2_header:
> .Lbag_alg_msg: .asciz "ERR: Xen must be loaded at a 2Mb boundary!"
> .Lno_nx_msg: .asciz "ERR: Not an NX-capable CPU!"
>
> - .section .init.data, "aw", @progbits
> - .subsection 1 /* Put data here after the page tables (in x86_64.S). */
> + .section .init.data.multiboot, "aw", @progbits
> .align 4
Turns out the comment must have been stale for a while.
> --- a/xen/arch/x86/xen.lds.S
> +++ b/xen/arch/x86/xen.lds.S
> @@ -57,6 +57,12 @@ SECTIONS
> __image_base__ = .;
> #else
> . = __image_base__;
> + /DISCARD/ : {
> + *(.text.header)
> + *(.init.multiboot)
> + *(.init.data.multiboot)
> + *(.init.rodata.multiboot)
Simply *(.init.*multiboot)?
Jan
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v5 3/5] x86/efi: avoid a relocation in efi_arch_post_exit_boot()
2026-06-26 12:36 [PATCH v5 0/5] Various patches to improve Secure Boot support Frediano Ziglio
2026-06-26 12:36 ` [PATCH v5 1/5] Align relevant sections to 4KB Frediano Ziglio
2026-06-26 12:36 ` [PATCH v5 2/5] x86/efi: discard multiboot and PVH support for PE binary Frediano Ziglio
@ 2026-06-26 12:36 ` Frediano Ziglio
2026-06-30 13:12 ` Roger Pau Monné
2026-06-26 12:36 ` [PATCH v5 4/5] x86: Split .init section to satisfy UEFI CA memory mitigation Frediano Ziglio
2026-06-26 12:36 ` [PATCH v5 5/5] x86/boot: Exclude not used string Frediano Ziglio
4 siblings, 1 reply; 11+ messages in thread
From: Frediano Ziglio @ 2026-06-26 12:36 UTC (permalink / raw)
To: xen-devel
Cc: Roger Pau Monné, Daniel P. Smith,
Marek Marczykowski-Górecki, Jan Beulich, Andrew Cooper,
Teddy Astie, Frediano Ziglio
From: Roger Pau Monné <roger.pau@citrix.com>
Instead of using the absolute __start_xen address, calculate it as an
offset from the current instruction pointer. The relocation would be
problematic if the generated PE binary had .init.text as a standalone
section with just read and execute permissions."
Removing this relocation is necessary to make it safe to split .init.
No functional change intended.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
--
Changes since v1:
- Improve commit message.
Changes since v3:
- Added Acked-by.
---
xen/arch/x86/efi/efi-boot.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index d738b839ee..b983f054b5 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -270,7 +270,9 @@ static void __init noreturn efi_arch_post_exit_boot(void)
/* Jump to higher mappings. */
"mov stack_start(%%rip), %%rsp\n\t"
- "movabs $__start_xen, %[rip]\n\t"
+ "lea __start_xen(%%rip), %[rip]\n\t"
+ "add %[offset], %[rip]\n\t"
+
"push %[cs]\n\t"
"push %[rip]\n\t"
"lretq"
@@ -278,7 +280,8 @@ static void __init noreturn efi_arch_post_exit_boot(void)
[cr4] "+&r" (cr4)
: [cr3] "r" (idle_pg_table),
[cs] "i" (__HYPERVISOR_CS),
- [ds] "r" (__HYPERVISOR_DS)
+ [ds] "r" (__HYPERVISOR_DS),
+ [offset] "r" (__XEN_VIRT_START - xen_phys_start)
: "memory" );
unreachable();
}
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v5 3/5] x86/efi: avoid a relocation in efi_arch_post_exit_boot()
2026-06-26 12:36 ` [PATCH v5 3/5] x86/efi: avoid a relocation in efi_arch_post_exit_boot() Frediano Ziglio
@ 2026-06-30 13:12 ` Roger Pau Monné
0 siblings, 0 replies; 11+ messages in thread
From: Roger Pau Monné @ 2026-06-30 13:12 UTC (permalink / raw)
To: Frediano Ziglio
Cc: xen-devel, Daniel P. Smith, Marek Marczykowski-Górecki,
Jan Beulich, Andrew Cooper, Teddy Astie, Frediano Ziglio
On Fri, Jun 26, 2026 at 01:36:43PM +0100, Frediano Ziglio wrote:
> From: Roger Pau Monné <roger.pau@citrix.com>
>
> Instead of using the absolute __start_xen address, calculate it as an
> offset from the current instruction pointer. The relocation would be
> problematic if the generated PE binary had .init.text as a standalone
> section with just read and execute permissions."
There's a stray " at the end of the line I think.
Thanks, Roger.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v5 4/5] x86: Split .init section to satisfy UEFI CA memory mitigation
2026-06-26 12:36 [PATCH v5 0/5] Various patches to improve Secure Boot support Frediano Ziglio
` (2 preceding siblings ...)
2026-06-26 12:36 ` [PATCH v5 3/5] x86/efi: avoid a relocation in efi_arch_post_exit_boot() Frediano Ziglio
@ 2026-06-26 12:36 ` Frediano Ziglio
2026-06-26 12:36 ` [PATCH v5 5/5] x86/boot: Exclude not used string Frediano Ziglio
4 siblings, 0 replies; 11+ messages in thread
From: Frediano Ziglio @ 2026-06-26 12:36 UTC (permalink / raw)
To: xen-devel
Cc: Frediano Ziglio, Jan Beulich, Andrew Cooper, Roger Pau Monné,
Teddy Astie, Marek Marczykowski-Górecki, Frediano Ziglio
From: Frediano Ziglio <frediano.ziglio@cloud.com>
Currently .init section is both writeable and executable, split data and code
to have 2 sections satisfying W^X rule.
It is a requirement for NX_COMPAT so the PE can be loaded with W^X perms
in the pagetables.
NX_COMPAT is a requirement from shim-review,
https://github.com/rhboot/shim-review#do-you-have-the-nx-bit-set-in-your-shim-if-so-is-your-entire-boot-stack-nx-compatible-and-what-testing-have-you-done-to-ensure-such-compatibility
Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
--
Change since v1:
- update comment style.
Changes since v3:
- Added Acked-by.
Changes since v4:
- Added Acked-by.
---
xen/arch/x86/xen.lds.S | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index 88553513a9..70678ab83c 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -195,11 +195,7 @@ SECTIONS
__2M_init_start = .; /* Start of 2M superpages, mapped RWX (boot only). */
. = ALIGN(PAGE_SIZE); /* Init code and data */
__init_begin = .;
-#ifdef EFI /* EFI wants to merge all of .init.* ELF doesn't. */
- DECL_SECTION(.init) {
-#else
DECL_SECTION(.init.text) {
-#endif
_sinittext = .;
*(.init.multiboot)
*(.init.text)
@@ -212,12 +208,12 @@ SECTIONS
*/
*(.altinstr_replacement)
-#ifdef EFI /* EFI wants to merge all of .init.* ELF doesn't. */
- . = ALIGN(SMP_CACHE_BYTES);
-#else
} PHDR(text)
- DECL_SECTION(.init.data) {
+#ifdef EFI
+ /* Align to satisfy UEFI CA memory mitigation. */
+ . = ALIGN(SECTION_ALIGN);
#endif
+ DECL_SECTION(.init.data) {
*(.init.bss.stack_aligned)
*(.init.data.page_aligned)
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v5 5/5] x86/boot: Exclude not used string
2026-06-26 12:36 [PATCH v5 0/5] Various patches to improve Secure Boot support Frediano Ziglio
` (3 preceding siblings ...)
2026-06-26 12:36 ` [PATCH v5 4/5] x86: Split .init section to satisfy UEFI CA memory mitigation Frediano Ziglio
@ 2026-06-26 12:36 ` Frediano Ziglio
2026-06-29 13:59 ` Jan Beulich
4 siblings, 1 reply; 11+ messages in thread
From: Frediano Ziglio @ 2026-06-26 12:36 UTC (permalink / raw)
To: xen-devel
Cc: Frediano Ziglio, Daniel P. Smith, Jan Beulich, Andrew Cooper,
Roger Pau Monné, Teddy Astie,
Marek Marczykowski-Górecki
If CONFIG_REQUIRE_NX is not enabled the string is not used.
Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
---
xen/arch/x86/boot/head.S | 2 ++
1 file changed, 2 insertions(+)
diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index ebdc562207..981f262b5e 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -133,7 +133,9 @@ multiboot2_header:
.Lbad_ldr_nbs: .asciz "ERR: Bootloader shutdown EFI x64 boot services!"
.Lbad_efi_msg: .asciz "ERR: EFI IA-32 platforms are not supported!"
.Lbag_alg_msg: .asciz "ERR: Xen must be loaded at a 2Mb boundary!"
+#ifdef CONFIG_REQUIRE_NX
.Lno_nx_msg: .asciz "ERR: Not an NX-capable CPU!"
+#endif
.section .init.data.multiboot, "aw", @progbits
.align 4
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v5 5/5] x86/boot: Exclude not used string
2026-06-26 12:36 ` [PATCH v5 5/5] x86/boot: Exclude not used string Frediano Ziglio
@ 2026-06-29 13:59 ` Jan Beulich
2026-06-30 11:06 ` Andrew Cooper
0 siblings, 1 reply; 11+ messages in thread
From: Jan Beulich @ 2026-06-29 13:59 UTC (permalink / raw)
To: Frediano Ziglio
Cc: Frediano Ziglio, Daniel P. Smith, Andrew Cooper,
Roger Pau Monné, Teddy Astie,
Marek Marczykowski-Górecki, xen-devel
On 26.06.2026 14:36, Frediano Ziglio wrote:
> If CONFIG_REQUIRE_NX is not enabled the string is not used.
>
> Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v5 5/5] x86/boot: Exclude not used string
2026-06-29 13:59 ` Jan Beulich
@ 2026-06-30 11:06 ` Andrew Cooper
2026-06-30 11:33 ` Jan Beulich
0 siblings, 1 reply; 11+ messages in thread
From: Andrew Cooper @ 2026-06-30 11:06 UTC (permalink / raw)
To: Jan Beulich, Frediano Ziglio
Cc: Andrew Cooper, Frediano Ziglio, Daniel P. Smith,
Roger Pau Monné, Teddy Astie,
Marek Marczykowski-Górecki, xen-devel
On 29/06/2026 2:59 pm, Jan Beulich wrote:
> On 26.06.2026 14:36, Frediano Ziglio wrote:
>> If CONFIG_REQUIRE_NX is not enabled the string is not used.
>>
>> Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>
I know you're both trying to be helpful, but this patch really isn't.
You are both aware that I have a full series about NX handling in
progress, which deletes more than just this, and also needs backporting.
~Andrew
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v5 5/5] x86/boot: Exclude not used string
2026-06-30 11:06 ` Andrew Cooper
@ 2026-06-30 11:33 ` Jan Beulich
0 siblings, 0 replies; 11+ messages in thread
From: Jan Beulich @ 2026-06-30 11:33 UTC (permalink / raw)
To: Andrew Cooper
Cc: Frediano Ziglio, Daniel P. Smith, Roger Pau Monné,
Teddy Astie, Marek Marczykowski-Górecki, xen-devel,
Frediano Ziglio
On 30.06.2026 13:06, Andrew Cooper wrote:
> On 29/06/2026 2:59 pm, Jan Beulich wrote:
>> On 26.06.2026 14:36, Frediano Ziglio wrote:
>>> If CONFIG_REQUIRE_NX is not enabled the string is not used.
>>>
>>> Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
>> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>
> I know you're both trying to be helpful, but this patch really isn't.
You should have said so earlier, now it's in.
> You are both aware that I have a full series about NX handling in
> progress, which deletes more than just this, and also needs backporting.
That'll be impacted only marginally, afaict.
Jan
^ permalink raw reply [flat|nested] 11+ messages in thread