diff mbox series

[v7,1/2] libelf: Store maximum PHDR p_align

Message ID 20240404212519.16401-2-jason.andryuk@amd.com (mailing list archive)
State New, archived
Headers show
Series x86/pvh: Support relocating dom0 kernel | expand

Commit Message

Jason Andryuk April 4, 2024, 9:25 p.m. UTC
While parsing the PHDRs, store the maximum p_align value.  This may be
consulted for moving a PVH image's load address.

Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
---
v6:
New

v7:
Remove printing p_align.  It may be confusing and is only useful when
a PVH kernel needs to be moved.
---
 xen/common/libelf/libelf-loader.c | 5 +++++
 xen/include/xen/libelf.h          | 1 +
 2 files changed, 6 insertions(+)

Comments

Jan Beulich April 8, 2024, 6:55 a.m. UTC | #1
On 04.04.2024 23:25, Jason Andryuk wrote:
> While parsing the PHDRs, store the maximum p_align value.  This may be
> consulted for moving a PVH image's load address.
> 
> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>

Acked-by: Jan Beulich <jbeulich@suse.com>
diff mbox series

Patch

diff --git a/xen/common/libelf/libelf-loader.c b/xen/common/libelf/libelf-loader.c
index 629cc0d3e6..e571ea670e 100644
--- a/xen/common/libelf/libelf-loader.c
+++ b/xen/common/libelf/libelf-loader.c
@@ -468,6 +468,7 @@  void elf_parse_binary(struct elf_binary *elf)
 {
     ELF_HANDLE_DECL(elf_phdr) phdr;
     uint64_t low = -1, high = 0, paddr, memsz;
+    uint64_t max_align = 0, palign;
     unsigned i, count;
 
     count = elf_phdr_count(elf);
@@ -481,15 +482,19 @@  void elf_parse_binary(struct elf_binary *elf)
             continue;
         paddr = elf_uval(elf, phdr, p_paddr);
         memsz = elf_uval(elf, phdr, p_memsz);
+        palign = elf_uval(elf, phdr, p_align);
         elf_msg(elf, "ELF: phdr: paddr=%#" PRIx64 " memsz=%#" PRIx64 "\n",
                 paddr, memsz);
         if ( low > paddr )
             low = paddr;
         if ( high < paddr + memsz )
             high = paddr + memsz;
+        if ( max_align < palign )
+            max_align = palign;
     }
     elf->pstart = low;
     elf->pend = high;
+    elf->palign = max_align;
     elf_msg(elf, "ELF: memory: %#" PRIx64 " -> %#" PRIx64 "\n",
             elf->pstart, elf->pend);
 }
diff --git a/xen/include/xen/libelf.h b/xen/include/xen/libelf.h
index 1c77e3df31..2d971f958e 100644
--- a/xen/include/xen/libelf.h
+++ b/xen/include/xen/libelf.h
@@ -196,6 +196,7 @@  struct elf_binary {
     size_t dest_size;
     uint64_t pstart;
     uint64_t pend;
+    uint64_t palign;
     uint64_t reloc_offset;
 
     uint64_t bsd_symtab_pstart;