Problem loading linux 5.19 as PV dom0
A Linux kernel 5.19 can only be loaded as dom0, if it has been built with CONFIG_AMD_MEM_ENCRYPT enabled. This is due to the fact that otherwise the (relevant) last section of the built kernel has the NOLOAD flag set (it is still marked with SHF_ALLOC).
I think at least the hypervisor needs to be changed to support this layout. Otherwise it will put the initial page tables for dom0 at the same position as this last section, leading to early crashes.
A workaround in the kernel would be to always add a small section at the end which needs to be loaded (like is done with CONFIG_AMD_MEM_ENCRYPT set), but I don't think we can put this burden on all guests being capable to run in PV mode.
I haven't tested yet, whether unprivileged PV guests are affected, too.
Juergen
Quoted 10 lines · Juergen Gross
A Linux kernel 5.19 can only be loaded as dom0, if it has been built with
CONFIG_AMD_MEM_ENCRYPTenabled. This is due to the fact that otherwise the (relevant) last section of the built kernel has the NOLOAD flag set (it is still marked withSHF_ALLOC).I think at least the hypervisor needs to be changed to support this layout. Otherwise it will put the initial page tables for dom0 at the same position as this last section, leading to early crashes.
Isn't Xen using the bzImage header there, rather than any ELF one? In which case it would matter how the NOLOAD section is actually represented in that header. Can you provide a dump (or binary representation) of both headers?
Jan
Quoted 11 lines
A workaround in the kernel would be to always add a small section at the end which needs to be loaded (like is done with
CONFIG_AMD_MEM_ENCRYPTset), but I don't think we can put this burden on all guests being capable to run in PV mode.I haven't tested yet, whether unprivileged PV guests are affected, too.
Juergen
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Juergen Gross
A Linux kernel 5.19 can only be loaded as dom0, if it has been built with
CONFIG_AMD_MEM_ENCRYPTenabled. This is due to the fact that otherwise the (relevant) last section of the built kernel has the NOLOAD flag set (it is still marked withSHF_ALLOC).
Quoted 7 lines
Quoted 4 lines
I think at least the hypervisor needs to be changed to support this layout. Otherwise it will put the initial page tables for dom0 at the same position as this last section, leading to early crashes.
Isn't Xen using the bzImage header there, rather than any ELF one? In which case it would matter how the NOLOAD section is
For a PV kernel? No, I don't think so. Just sent a patch repairing the issue, BTW.
Quoted 2 lines
actually represented in that header. Can you provide a dump (or binary representation) of both headers?
Program Header:
LOAD off 0x0000000000200000 vaddr 0xffffffff81000000 paddr
0x0000000001000000 align 2**21
filesz 0x000000000145e114 memsz 0x000000000145e114 flags r-x
LOAD off 0x0000000001800000 vaddr 0xffffffff82600000 paddr
0x0000000002600000 align 2**21
filesz 0x00000000006b7000 memsz 0x00000000006b7000 flags rw-
LOAD off 0x0000000002000000 vaddr 0x0000000000000000 paddr
0x0000000002cb7000 align 2**21
filesz 0x00000000000312a8 memsz 0x00000000000312a8 flags rw-
LOAD off 0x00000000020e9000 vaddr 0xffffffff82ce9000 paddr
0x0000000002ce9000 align 2**21
filesz 0x00000000001fd000 memsz 0x0000000000317000 flags rwx
NOTE off 0x000000000165df10 vaddr 0xffffffff8245df10 paddr
0x000000000245df10 align 2**2
filesz 0x0000000000000204 memsz 0x0000000000000204 flags ---Sections:
Idx Name Size VMA LMA File off Algn
...
30 .smp_locks 00009000 ffffffff82edc000 0000000002edc000 022dc000 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
31 .data_nosave 00001000 ffffffff82ee5000 0000000002ee5000 022e5000 2**2
CONTENTS, ALLOC, LOAD, DATA
32 .bss 0011a000 ffffffff82ee6000 0000000002ee6000 022e6000 2**12
ALLOC
33 .brk 00026000 ffffffff83000000 ffffffff83000000 00000000 2**0
ALLOC
And the related linker script part:
__end_of_kernel_reserve = .;
. = ALIGN(PAGE_SIZE);
.brk (NOLOAD) : AT(ADDR(.brk) - LOAD_OFFSET) {
__brk_base = .;
. += 64 * 1024; /* 64k alignment slop space */
*(.bss..brk) /* areas brk users have reserved */
__brk_limit = .;
}
. = ALIGN(PAGE_SIZE); /* keep VO_INIT_SIZE page aligned */
_end = .;Juergen
Quoted 13 lines · Juergen Gross
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Juergen Gross
A Linux kernel 5.19 can only be loaded as dom0, if it has been built with
CONFIG_AMD_MEM_ENCRYPTenabled. This is due to the fact that otherwise the (relevant) last section of the built kernel has the NOLOAD flag set (it is still marked withSHF_ALLOC).I think at least the hypervisor needs to be changed to support this layout. Otherwise it will put the initial page tables for dom0 at the same position as this last section, leading to early crashes.
Quoted 4 lines
Quoted 2 lines
Isn't Xen using the bzImage header there, rather than any ELF one? In which case it would matter how the NOLOAD section is
For a PV kernel? No, I don't think so.
Actually it's a mix (and the same for PV and PVH) - the bzImage header is parsed to get at the embedded ELF header. XenoLinux was what would/could be loaded as plain ELF.
Quoted 4 lines
Quoted 2 lines
actually represented in that header. Can you provide a dump (or binary representation) of both headers?
Program Header:
Quoted 12 lines
LOAD off 0x0000000000200000 vaddr 0xffffffff81000000 paddr
0x0000000001000000 align 2**21
filesz 0x000000000145e114 memsz 0x000000000145e114 flags r-x
LOAD off 0x0000000001800000 vaddr 0xffffffff82600000 paddr
0x0000000002600000 align 2**21
filesz 0x00000000006b7000 memsz 0x00000000006b7000 flags rw-
LOAD off 0x0000000002000000 vaddr 0x0000000000000000 paddr
0x0000000002cb7000 align 2**21
filesz 0x00000000000312a8 memsz 0x00000000000312a8 flags rw-
LOAD off 0x00000000020e9000 vaddr 0xffffffff82ce9000 paddr
0x0000000002ce9000 align 2**21
filesz 0x00000000001fd000 memsz 0x0000000000317000 flags rwx20e9000 + 317000 = 240000
Quoted 5 lines
NOTE off 0x000000000165df10 vaddr 0xffffffff8245df10 paddr
0x000000000245df10 align 2**2
filesz 0x0000000000000204 memsz 0x0000000000000204 flags ---Quoted 9 lines
Sections:
Idx Name Size VMA LMA File off Algn
...
30 .smp_locks 00009000ffffffff82edc0000000000002edc000022dc0002**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
31 .data_nosave 00001000ffffffff82ee50000000000002ee5000022e50002**2
CONTENTS, ALLOC, LOAD, DATA
32 .bss0011a000ffffffff82ee60000000000002ee6000022e60002**12
ALLOC
2ee6000 + 11a000 = 240000
Quoted 2 lines
33 .brk 00026000
ffffffff83000000ffffffff8300000000000000 2**0
ALLOC
This space isn't covered by any program header. Which in turn may be a result of its LMA matching its VMA, unlike for all other sections. Looks like a linker script or linker issue to me: While ...
Quoted 6 lines
And the related linker script part:
__end_of_kernel_reserve = .; . = ALIGN(PAGE_SIZE); .brk (NOLOAD) : AT(ADDR(.brk) - LOAD_OFFSET) {
... this AT() looks correct to me, I'm uncertain of the use of NOLOAD. Note that .bss doesn't have NOLOAD, matching the vast majority of the linker scripts ld itself has.
Jan
Quoted 11 lines
__brk_base = .; . += 64 * 1024; /* 64k alignment slop space */ *(.bss..brk) /* areas brk users have reserved */ __brk_limit = .; } . = ALIGN(PAGE_SIZE); /* keep VO_INIT_SIZE page aligned */ _end = .;Juergen
Quoted 68 lines · Jan Beulich
Quoted 13 lines · Juergen Gross
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Juergen Gross
A Linux kernel 5.19 can only be loaded as dom0, if it has been built with
CONFIG_AMD_MEM_ENCRYPTenabled. This is due to the fact that otherwise the (relevant) last section of the built kernel has the NOLOAD flag set (it is still marked withSHF_ALLOC).I think at least the hypervisor needs to be changed to support this layout. Otherwise it will put the initial page tables for dom0 at the same position as this last section, leading to early crashes.
Quoted 4 lines
Quoted 2 lines
Isn't Xen using the bzImage header there, rather than any ELF one? In which case it would matter how the NOLOAD section is
For a PV kernel? No, I don't think so.
Actually it's a mix (and the same for PV and PVH) - the bzImage header is parsed to get at the embedded ELF header. XenoLinux was what would/could be loaded as plain ELF.
Quoted 4 lines
Quoted 2 lines
actually represented in that header. Can you provide a dump (or binary representation) of both headers?
Program Header:
Quoted 12 lines
LOAD off 0x0000000000200000 vaddr 0xffffffff81000000 paddr 0x0000000001000000 align 2**21 filesz 0x000000000145e114 memsz 0x000000000145e114 flags r-x LOAD off 0x0000000001800000 vaddr 0xffffffff82600000 paddr 0x0000000002600000 align 2**21 filesz 0x00000000006b7000 memsz 0x00000000006b7000 flags rw- LOAD off 0x0000000002000000 vaddr 0x0000000000000000 paddr 0x0000000002cb7000 align 2**21 filesz 0x00000000000312a8 memsz 0x00000000000312a8 flags rw- LOAD off 0x00000000020e9000 vaddr 0xffffffff82ce9000 paddr 0x0000000002ce9000 align 2**21 filesz 0x00000000001fd000 memsz 0x0000000000317000 flags rwx20e9000 + 317000 = 240000
Quoted 5 lines
NOTE off 0x000000000165df10 vaddr 0xffffffff8245df10 paddr 0x000000000245df10 align 2**2 filesz 0x0000000000000204 memsz 0x0000000000000204 flags ---Quoted 9 lines
Sections:
Idx Name Size VMA LMA File off Algn
...
30 .smp_locks 00009000ffffffff82edc0000000000002edc000022dc0002**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
31 .data_nosave 00001000ffffffff82ee50000000000002ee5000022e50002**2
CONTENTS, ALLOC, LOAD, DATA
32 .bss0011a000ffffffff82ee60000000000002ee6000022e60002**12
ALLOC2ee6000 + 11a000 = 240000
Quoted 2 lines
33 .brk 00026000 ffffffff83000000 ffffffff83000000 00000000 2**0 ALLOCThis space isn't covered by any program header. Which in turn may be a result of its LMA matching its VMA, unlike for all other sections. Looks like a linker script or linker issue to me: While ...
Quoted 2 lines
And the related linker script part:
Quoted 8 lines
Quoted 4 lines
__end_of_kernel_reserve = .; . = ALIGN(PAGE_SIZE); .brk (NOLOAD) : AT(ADDR(.brk) - LOAD_OFFSET) {... this
AT()looks correct to me, I'm uncertain of the use of NOLOAD. Note that .bss doesn't have NOLOAD, matching the vast majority of the linker scripts ld itself has.
Yeah, but the filesz and memsz values of the .bss related program header differ a lot (basically by the .bss size plus some alignment), and the .bss section flags clearly say that its attributes match those of .brk.
I'm not sure why the linker wouldn't add .brk to the same pgrogram header entry as .bss, but maybe that is some .bss special handling.
In the end I think this might be a linker issue, but even in this case we should really consider to handle it, as otherwise we'd just say "hey, due to a linker problem we don't support Linux 5.19 in PV mode".
In the end we can't control which linker versions are used to link the kernel.
Juergen
Quoted 74 lines · Juergen Gross
Quoted 73 lines · Jan Beulich
Quoted 13 lines · Juergen Gross
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Juergen Gross
A Linux kernel 5.19 can only be loaded as dom0, if it has been built with
CONFIG_AMD_MEM_ENCRYPTenabled. This is due to the fact that otherwise the (relevant) last section of the built kernel has the NOLOAD flag set (it is still marked withSHF_ALLOC).I think at least the hypervisor needs to be changed to support this layout. Otherwise it will put the initial page tables for dom0 at the same position as this last section, leading to early crashes.
Quoted 4 lines
Quoted 2 lines
Isn't Xen using the bzImage header there, rather than any ELF one? In which case it would matter how the NOLOAD section is
For a PV kernel? No, I don't think so.
Actually it's a mix (and the same for PV and PVH) - the bzImage header is parsed to get at the embedded ELF header. XenoLinux was what would/could be loaded as plain ELF.
Quoted 4 lines
Quoted 2 lines
actually represented in that header. Can you provide a dump (or binary representation) of both headers?
Program Header:
Quoted 12 lines
LOAD off 0x0000000000200000 vaddr 0xffffffff81000000 paddr 0x0000000001000000 align 2**21 filesz 0x000000000145e114 memsz 0x000000000145e114 flags r-x LOAD off 0x0000000001800000 vaddr 0xffffffff82600000 paddr 0x0000000002600000 align 2**21 filesz 0x00000000006b7000 memsz 0x00000000006b7000 flags rw- LOAD off 0x0000000002000000 vaddr 0x0000000000000000 paddr 0x0000000002cb7000 align 2**21 filesz 0x00000000000312a8 memsz 0x00000000000312a8 flags rw- LOAD off 0x00000000020e9000 vaddr 0xffffffff82ce9000 paddr 0x0000000002ce9000 align 2**21 filesz 0x00000000001fd000 memsz 0x0000000000317000 flags rwx20e9000 + 317000 = 240000
Quoted 5 lines
NOTE off 0x000000000165df10 vaddr 0xffffffff8245df10 paddr 0x000000000245df10 align 2**2 filesz 0x0000000000000204 memsz 0x0000000000000204 flags ---Quoted 9 lines
Sections:
Idx Name Size VMA LMA File off Algn
...
30 .smp_locks 00009000ffffffff82edc0000000000002edc000022dc0002**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
31 .data_nosave 00001000ffffffff82ee50000000000002ee5000022e50002**2
CONTENTS, ALLOC, LOAD, DATA
32 .bss0011a000ffffffff82ee60000000000002ee6000022e60002**12
ALLOC2ee6000 + 11a000 = 240000
Quoted 2 lines
33 .brk 00026000 ffffffff83000000 ffffffff83000000 00000000 2**0 ALLOCThis space isn't covered by any program header. Which in turn may be a result of its LMA matching its VMA, unlike for all other sections. Looks like a linker script or linker issue to me: While ...
Quoted 6 lines
And the related linker script part:
__end_of_kernel_reserve = .; . = ALIGN(PAGE_SIZE); .brk (NOLOAD) : AT(ADDR(.brk) - LOAD_OFFSET) {
Quoted 6 lines
Quoted 3 lines
... this
AT()looks correct to me, I'm uncertain of the use of NOLOAD. Note that .bss doesn't have NOLOAD, matching the vast majority of the linker scripts ld itself has.Yeah, but the filesz and memsz values of the .bss related program header differ a lot (basically by the .bss size plus some alignment),
That's the very nature of .bss - no data to be loaded from the file.
Quoted 5 lines
and the
.bss section flags clearly say that its attributes match those of .brk.I'm not sure why the linker wouldn't add .brk to the same pgrogram header entry as .bss, but maybe that is some .bss special handling.
I don't know either, but I suspect this to be an effect of using NOLOAD (without meaning to decide yet whether it's a wrong use of the attribute or bad handling of it in ld).
Quoted 6 lines
In the end I think this might be a linker issue, but even in this case we should really consider to handle it, as otherwise we'd just say "hey, due to a linker problem we don't support Linux 5.19 in PV mode".
In the end we can't control which linker versions are used to link the kernel.
Right, but the workaround for such a linker issue (if any) would better live in Linux 5.19.
Jan
Quoted 87 lines · Jan Beulich
Quoted 74 lines · Juergen Gross
Quoted 73 lines · Jan Beulich
Quoted 13 lines · Juergen Gross
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Juergen Gross
A Linux kernel 5.19 can only be loaded as dom0, if it has been built with
CONFIG_AMD_MEM_ENCRYPTenabled. This is due to the fact that otherwise the (relevant) last section of the built kernel has the NOLOAD flag set (it is still marked withSHF_ALLOC).I think at least the hypervisor needs to be changed to support this layout. Otherwise it will put the initial page tables for dom0 at the same position as this last section, leading to early crashes.
Quoted 4 lines
Quoted 2 lines
Isn't Xen using the bzImage header there, rather than any ELF one? In which case it would matter how the NOLOAD section is
For a PV kernel? No, I don't think so.
Actually it's a mix (and the same for PV and PVH) - the bzImage header is parsed to get at the embedded ELF header. XenoLinux was what would/could be loaded as plain ELF.
Quoted 4 lines
Quoted 2 lines
actually represented in that header. Can you provide a dump (or binary representation) of both headers?
Program Header:
Quoted 12 lines
LOAD off 0x0000000000200000 vaddr 0xffffffff81000000 paddr 0x0000000001000000 align 2**21 filesz 0x000000000145e114 memsz 0x000000000145e114 flags r-x LOAD off 0x0000000001800000 vaddr 0xffffffff82600000 paddr 0x0000000002600000 align 2**21 filesz 0x00000000006b7000 memsz 0x00000000006b7000 flags rw- LOAD off 0x0000000002000000 vaddr 0x0000000000000000 paddr 0x0000000002cb7000 align 2**21 filesz 0x00000000000312a8 memsz 0x00000000000312a8 flags rw- LOAD off 0x00000000020e9000 vaddr 0xffffffff82ce9000 paddr 0x0000000002ce9000 align 2**21 filesz 0x00000000001fd000 memsz 0x0000000000317000 flags rwx20e9000 + 317000 = 240000
Quoted 8 lines
NOTE off 0x000000000165df10 vaddr 0xffffffff8245df10 paddr 0x000000000245df10 align 2**2 filesz 0x0000000000000204 memsz 0x0000000000000204 flags ---Sections:
Idx Name Size VMA LMA File off Algn
...Quoted 6 lines
30 .smp_locks 00009000 ffffffff82edc000 0000000002edc000 022dc000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 31 .data_nosave 00001000 ffffffff82ee5000 0000000002ee5000 022e5000 2**2 CONTENTS, ALLOC, LOAD, DATA 32 .bss 0011a000 ffffffff82ee6000 0000000002ee6000 022e6000 2**12 ALLOC2ee6000 + 11a000 = 240000
Quoted 2 lines
33 .brk 00026000 ffffffff83000000 ffffffff83000000 00000000 2**0 ALLOCThis space isn't covered by any program header. Which in turn may be a result of its LMA matching its VMA, unlike for all other sections. Looks like a linker script or linker issue to me: While ...
Quoted 6 lines
And the related linker script part:
__end_of_kernel_reserve = .; . = ALIGN(PAGE_SIZE); .brk (NOLOAD) : AT(ADDR(.brk) - LOAD_OFFSET) {Quoted 6 lines
Quoted 3 lines
... this
AT()looks correct to me, I'm uncertain of the use of NOLOAD. Note that .bss doesn't have NOLOAD, matching the vast majority of the linker scripts ld itself has.Yeah, but the filesz and memsz values of the .bss related program header differ a lot (basically by the .bss size plus some alignment),
That's the very nature of .bss - no data to be loaded from the file.
Quoted 3 lines
and the
.bss section flags clearly say that its attributes match those of .brk.
Quoted 6 lines
Quoted 2 lines
I'm not sure why the linker wouldn't add .brk to the same pgrogram header entry as .bss, but maybe that is some .bss special handling.
I don't know either, but I suspect this to be an effect of using NOLOAD (without meaning to decide yet whether it's a wrong use of the attribute or bad handling of it in ld).
I just did a test: dropping the "(NOLOAD)" for .brk in the linker script will result in the .brk section to be included in the same program header as the .bss section.
I'll start an upstream discussion to drop it (I could imagine problems e.g. when using grub, as grub might place the initrd overlapping the .brk section when not using a compressed kernel).
Juergen