2020-03-01 23:06:12

by Arvind Sankar

[permalink] [raw]
Subject: [PATCH 3/5] efi/x86: Add kernel preferred address to PE header

Store the kernel's link address as ImageBase in the PE header. Note that
the PE specification requires the ImageBase to be 64k aligned. The
preferred address should almost always satisfy that, except for 32-bit
kernel if the configuration has been customized.

Signed-off-by: Arvind Sankar <[email protected]>
---
arch/x86/boot/header.S | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
index 4ee25e28996f..0d8d2cb28fd9 100644
--- a/arch/x86/boot/header.S
+++ b/arch/x86/boot/header.S
@@ -138,10 +138,12 @@ optional_header:
#endif

extra_header_fields:
+ # PE specification requires ImageBase to be 64k-aligned
+ .set ImageBase, (LOAD_PHYSICAL_ADDR+0xffff) & ~0xffff
#ifdef CONFIG_X86_32
- .long 0 # ImageBase
+ .long ImageBase # ImageBase
#else
- .quad 0 # ImageBase
+ .quad ImageBase # ImageBase
#endif
.long 0x20 # SectionAlignment
.long 0x20 # FileAlignment
--
2.24.1


2020-03-03 21:41:47

by Ard Biesheuvel

[permalink] [raw]
Subject: Re: [PATCH 3/5] efi/x86: Add kernel preferred address to PE header

On Mon, 2 Mar 2020 at 00:05, Arvind Sankar <[email protected]> wrote:
>
> Store the kernel's link address as ImageBase in the PE header. Note that
> the PE specification requires the ImageBase to be 64k aligned. The
> preferred address should almost always satisfy that, except for 32-bit
> kernel if the configuration has been customized.
>
> Signed-off-by: Arvind Sankar <[email protected]>
> ---
> arch/x86/boot/header.S | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
> index 4ee25e28996f..0d8d2cb28fd9 100644
> --- a/arch/x86/boot/header.S
> +++ b/arch/x86/boot/header.S
> @@ -138,10 +138,12 @@ optional_header:
> #endif
>
> extra_header_fields:
> + # PE specification requires ImageBase to be 64k-aligned
> + .set ImageBase, (LOAD_PHYSICAL_ADDR+0xffff) & ~0xffff

Could you call this image_base please, and put some spaces around the +

> #ifdef CONFIG_X86_32
> - .long 0 # ImageBase
> + .long ImageBase # ImageBase
> #else
> - .quad 0 # ImageBase
> + .quad ImageBase # ImageBase
> #endif
> .long 0x20 # SectionAlignment
> .long 0x20 # FileAlignment
> --
> 2.24.1
>