2022-10-03 22:25:11

by Ali Raza

[permalink] [raw]
Subject: [RFC UKL 02/10] x86/boot: Load the PT_TLS segment for Unikernel configs

The kernel normally skips loading this segment as it is not inlcuded in
standard builds. However, when linked with an application in the Unikernel
configuration the segment will be present. Load PT_TLS when configured as a
unikernel.

Cc: Jonathan Corbet <[email protected]>
Cc: Masahiro Yamada <[email protected]>
Cc: Michal Marek <[email protected]>
Cc: Nick Desaulniers <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Eric Biederman <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Juri Lelli <[email protected]>
Cc: Vincent Guittot <[email protected]>
Cc: Dietmar Eggemann <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Ben Segall <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Daniel Bristot de Oliveira <[email protected]>
Cc: Valentin Schneider <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Josh Poimboeuf <[email protected]>

Signed-off-by: Ali Raza <[email protected]>
---
arch/x86/boot/compressed/misc.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index cf690d8712f4..0d07b5661c9c 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -310,6 +310,9 @@ static void parse_elf(void *output)
phdr = &phdrs[i];

switch (phdr->p_type) {
+#ifdef CONFIG_UNIKERNEL_LINUX
+ case PT_TLS:
+#endif
case PT_LOAD:
#ifdef CONFIG_X86_64
if ((phdr->p_align % 0x200000) != 0)
--
2.21.3


2022-10-04 18:22:28

by Andy Lutomirski

[permalink] [raw]
Subject: Re: [RFC UKL 02/10] x86/boot: Load the PT_TLS segment for Unikernel configs

On Mon, Oct 3, 2022, at 3:21 PM, Ali Raza wrote:
> The kernel normally skips loading this segment as it is not inlcuded in
> standard builds. However, when linked with an application in the Unikernel
> configuration the segment will be present. Load PT_TLS when configured as a
> unikernel.
>
> Cc: Jonathan Corbet <[email protected]>
> Cc: Masahiro Yamada <[email protected]>
> Cc: Michal Marek <[email protected]>
> Cc: Nick Desaulniers <[email protected]>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: Borislav Petkov <[email protected]>
> Cc: Dave Hansen <[email protected]>
> Cc: "H. Peter Anvin" <[email protected]>
> Cc: Andy Lutomirski <[email protected]>
> Cc: Eric Biederman <[email protected]>
> Cc: Kees Cook <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: Alexander Viro <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Cc: Juri Lelli <[email protected]>
> Cc: Vincent Guittot <[email protected]>
> Cc: Dietmar Eggemann <[email protected]>
> Cc: Steven Rostedt <[email protected]>
> Cc: Ben Segall <[email protected]>
> Cc: Mel Gorman <[email protected]>
> Cc: Daniel Bristot de Oliveira <[email protected]>
> Cc: Valentin Schneider <[email protected]>
> Cc: Paolo Bonzini <[email protected]>
> Cc: Josh Poimboeuf <[email protected]>
>
> Signed-off-by: Ali Raza <[email protected]>
> ---
> arch/x86/boot/compressed/misc.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
> index cf690d8712f4..0d07b5661c9c 100644
> --- a/arch/x86/boot/compressed/misc.c
> +++ b/arch/x86/boot/compressed/misc.c
> @@ -310,6 +310,9 @@ static void parse_elf(void *output)
> phdr = &phdrs[i];
>
> switch (phdr->p_type) {
> +#ifdef CONFIG_UNIKERNEL_LINUX
> + case PT_TLS:
> +#endif

Can you explain why exactly a Linux boot image would have a TLS segment? What does it do?

> case PT_LOAD:
> #ifdef CONFIG_X86_64
> if ((phdr->p_align % 0x200000) != 0)
> --
> 2.21.3

2022-10-06 21:23:21

by Ali Raza

[permalink] [raw]
Subject: Re: [RFC UKL 02/10] x86/boot: Load the PT_TLS segment for Unikernel configs

On 10/4/22 13:30, Andy Lutomirski wrote:
> On Mon, Oct 3, 2022, at 3:21 PM, Ali Raza wrote:
>> The kernel normally skips loading this segment as it is not inlcuded in
>> standard builds. However, when linked with an application in the Unikernel
>> configuration the segment will be present. Load PT_TLS when configured as a
>> unikernel.
>>
>> Cc: Jonathan Corbet <[email protected]>
>> Cc: Masahiro Yamada <[email protected]>
>> Cc: Michal Marek <[email protected]>
>> Cc: Nick Desaulniers <[email protected]>
>> Cc: Thomas Gleixner <[email protected]>
>> Cc: Ingo Molnar <[email protected]>
>> Cc: Borislav Petkov <[email protected]>
>> Cc: Dave Hansen <[email protected]>
>> Cc: "H. Peter Anvin" <[email protected]>
>> Cc: Andy Lutomirski <[email protected]>
>> Cc: Eric Biederman <[email protected]>
>> Cc: Kees Cook <[email protected]>
>> Cc: Peter Zijlstra <[email protected]>
>> Cc: Alexander Viro <[email protected]>
>> Cc: Arnd Bergmann <[email protected]>
>> Cc: Juri Lelli <[email protected]>
>> Cc: Vincent Guittot <[email protected]>
>> Cc: Dietmar Eggemann <[email protected]>
>> Cc: Steven Rostedt <[email protected]>
>> Cc: Ben Segall <[email protected]>
>> Cc: Mel Gorman <[email protected]>
>> Cc: Daniel Bristot de Oliveira <[email protected]>
>> Cc: Valentin Schneider <[email protected]>
>> Cc: Paolo Bonzini <[email protected]>
>> Cc: Josh Poimboeuf <[email protected]>
>>
>> Signed-off-by: Ali Raza <[email protected]>
>> ---
>> arch/x86/boot/compressed/misc.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
>> index cf690d8712f4..0d07b5661c9c 100644
>> --- a/arch/x86/boot/compressed/misc.c
>> +++ b/arch/x86/boot/compressed/misc.c
>> @@ -310,6 +310,9 @@ static void parse_elf(void *output)
>> phdr = &phdrs[i];
>>
>> switch (phdr->p_type) {
>> +#ifdef CONFIG_UNIKERNEL_LINUX
>> + case PT_TLS:
>> +#endif
>
> Can you explain why exactly a Linux boot image would have a TLS segment? What does it do?

Thank you for taking the time to review the patch.

A UKL boot image will have a TLS segment if an application has it, or is
linked with glibc, and the resulting binary is then linked with the
kernel. This will allow applications depending on TLS to function
without modification in the UKL setting.

That is why, the first patch in this series adds TLS section to the
kernel linker script. Also, if you use an application binary that does
not have a TLS section (like the one given with this patchset in
samples/ukl), you can turn it off through the CONFIG_UKL_TLS option.
This means the size of the TLS section would be zero and this code will
effectively not load anything.

>
>> case PT_LOAD:
>> #ifdef CONFIG_X86_64
>> if ((phdr->p_align % 0x200000) != 0)
>> --
>> 2.21.3