[MINI-OS PATCH 09/19] kexec: restructure building the start info data

Juergen Gross posted 19 patches 4 months ago
There is a newer version of this series
[MINI-OS PATCH 09/19] kexec: restructure building the start info data
Posted by Juergen Gross 4 months ago
Instead of setting most of the struct hvm_start_info fields first and
then building the leaf data, restructure kexec_get_entry() by
using an opaque "next" pointer where the next leaf data will be stored
and handle that leaf data together with the associated hvm_start_info
fields.

This will make it easier to add new data items without having to
rewrite large portions of the function.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/kexec.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kexec.c b/arch/x86/kexec.c
index d84df42c..3e3b64e2 100644
--- a/arch/x86/kexec.c
+++ b/arch/x86/kexec.c
@@ -215,6 +215,7 @@ void kexec_set_param_loc(const char *cmdline)
 
 int kexec_get_entry(const char *cmdline)
 {
+    void *next;
     struct hvm_start_info *info;
     struct hvm_memmap_table_entry *mmap;
     unsigned int order;
@@ -229,16 +230,17 @@ int kexec_get_entry(const char *cmdline)
     if ( !kexec_param_mem )
         return ENOMEM;
 
-    info = (struct hvm_start_info *)kexec_param_mem;
+    next = (void *)kexec_param_mem;
+
+    info = next;
     memset(info, 0, sizeof(*info));
     info->magic = XEN_HVM_START_MAGIC_VALUE;
     info->version = 1;
-    info->cmdline_paddr = kexec_param_loc + sizeof(*info) +
-                          e820_entries * sizeof(struct hvm_memmap_table_entry);
-    info->memmap_paddr = kexec_param_loc + sizeof(*info);
-    info->memmap_entries = e820_entries;
+    next = info + 1;
 
-    mmap = (struct hvm_memmap_table_entry *)(info + 1);
+    mmap = next;
+    info->memmap_paddr = kexec_param_loc + (unsigned long)next - kexec_param_mem;
+    info->memmap_entries = e820_entries;
     for ( i = 0; i < e820_entries; i++ )
     {
         mmap->addr = e820_map[i].addr;
@@ -246,8 +248,10 @@ int kexec_get_entry(const char *cmdline)
         mmap->type = e820_map[i].type;
         mmap++;
     }
+    next = mmap;
 
-    strcpy((char *)mmap, cmdline);
+    info->cmdline_paddr = kexec_param_loc + (unsigned long)next - kexec_param_mem;
+    strcpy(next, cmdline);
 
     if ( kexec_add_action(KEXEC_COPY, to_virt(kexec_param_loc), info,
                           kexec_param_size) )
-- 
2.43.0
Re: [MINI-OS PATCH 09/19] kexec: restructure building the start info data
Posted by Jason Andryuk 3 months, 3 weeks ago
On 2025-07-02 04:12, Juergen Gross wrote:
> Instead of setting most of the struct hvm_start_info fields first and
> then building the leaf data, restructure kexec_get_entry() by
> using an opaque "next" pointer where the next leaf data will be stored
> and handle that leaf data together with the associated hvm_start_info
> fields.
> 
> This will make it easier to add new data items without having to
> rewrite large portions of the function.
> 
> Signed-off-by: Juergen Gross<jgross@suse.com>

Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>