diff mbox series

[v5,08/44] x86/boot: convert setup.c mod refs to early_mod

Message ID 20241006214956.24339-9-dpsmith@apertussolutions.com (mailing list archive)
State Superseded
Headers show
Series Boot modules for Hyperlaunch | expand

Commit Message

Daniel P. Smith Oct. 6, 2024, 9:49 p.m. UTC
To allow a slow conversion of x86 over to struct boot_module, start with
replacing all references to struct mod to the early_mod element of struct
boot_module. These serves twofold, first to allow the incremental transition
from struct mod fields to struct boot_module fields. The second is to allow
the conversion of function definitions from taking struct mod parameters to
accepting struct boot_module as needed when a transitioned field will be
accessed.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
---
 xen/arch/x86/setup.c | 61 ++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 27 deletions(-)

Comments

Jason Andryuk Oct. 7, 2024, 7:34 p.m. UTC | #1
On 2024-10-06 17:49, Daniel P. Smith wrote:
> To allow a slow conversion of x86 over to struct boot_module, start with
> replacing all references to struct mod to the early_mod element of struct
> boot_module. These serves twofold, first to allow the incremental transition
> from struct mod fields to struct boot_module fields. The second is to allow
> the conversion of function definitions from taking struct mod parameters to
> accepting struct boot_module as needed when a transitioned field will be
> accessed.
> 
> Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
> ---
>   xen/arch/x86/setup.c | 61 ++++++++++++++++++++++++--------------------
>   1 file changed, 34 insertions(+), 27 deletions(-)
> 
> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
> index dd82ca3d43e2..ba4bee6b93af 100644
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c
> @@ -1341,15 +1341,15 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
>       set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
>       kexec_reserve_area();
>   
> -    initial_images = mod;
> +    initial_images = bi->mods[0].mod;

Isn't this wrong?
mod is the array of module_t * of *all* modules, but bi->mods[0].mod is 
a single module_t *?

>   
>       for ( i = 0; !efi_enabled(EFI_LOADER) && i < bi->nr_modules; i++ )
>       {
> -        if ( mod[i].mod_start & (PAGE_SIZE - 1) )
> +        if ( bi->mods[i].mod->mod_start & (PAGE_SIZE - 1) )
>               panic("Bootloader didn't honor module alignment request\n");
> -        mod[i].mod_end -= mod[i].mod_start;
> -        mod[i].mod_start >>= PAGE_SHIFT;
> -        mod[i].reserved = 0;
> +        bi->mods[i].mod->mod_end -= bi->mods[i].mod->mod_start;
> +        bi->mods[i].mod->mod_start >>= PAGE_SHIFT;
> +        bi->mods[i].mod->reserved = 0;
>       }
>   
>       /*

> @@ -1509,13 +1510,15 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
>   #endif
>       }
>   
> -    if ( bi->mods[0].headroom && !mod->reserved )
> +    if ( bi->mods[0].headroom && !bi->mods[0].mod->reserved )
>           panic("Not enough memory to relocate the dom0 kernel image\n");
>       for ( i = 0; i < bi->nr_modules; ++i )
>       {
> -        uint64_t s = (uint64_t)mod[i].mod_start << PAGE_SHIFT;
> +        uint64_t s = (uint64_t)bi->mods[i].mod->mod_start
> +                        << PAGE_SHIFT;

pfn_to_paddr() ?

>   
> -        reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end));
> +        reserve_e820_ram(&boot_e820, s,
> +                         s + PAGE_ALIGN(bi->mods[i].mod->mod_end));
>       }
>   
>       if ( !xen_phys_start )
> @@ -1593,8 +1596,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
>                   map_e = boot_e820.map[j].addr + boot_e820.map[j].size;
>                   for ( j = 0; j < bi->nr_modules; ++j )
>                   {
> -                    uint64_t end = pfn_to_paddr(mod[j].mod_start) +
> -                                   mod[j].mod_end;
> +                    uint64_t end = pfn_to_paddr(
> +                                   bi->mods[j].mod->mod_start) +
> +                                   bi->mods[j].mod->mod_end;

I think you want a different indent.  I think
     uint64_t end = pfn_to_paddr(bi->mods[j].mod->mod_start)

will all fit on one line (indented all the way).  (Thunderbird makes it 
difficult me to send indented.)

>   
>                       if ( map_e < end )
>                           map_e = end;
> @@ -1668,11 +1672,13 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
>   
>       for ( i = 0; i < bi->nr_modules; ++i )
>       {
> -        set_pdx_range(mod[i].mod_start,
> -                      mod[i].mod_start + PFN_UP(mod[i].mod_end));
> -        map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start),
> -                         _mfn(mod[i].mod_start),
> -                         PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
> +        set_pdx_range(bi->mods[i].mod->mod_start,
> +                      bi->mods[i].mod->mod_start +
> +                      PFN_UP(bi->mods[i].mod->mod_end));
> +        map_pages_to_xen(
> +            (unsigned long)mfn_to_virt(bi->mods[i].mod->mod_start),

map_pages_to_xen((unsigned long)maddr_to_virt(bi->mods[i].start),

All fits on one line.

> +            _mfn(bi->mods[i].mod->mod_start),
> +            PFN_UP(bi->mods[i].mod->mod_end), PAGE_HYPERVISOR);
>       }
>   
>   #ifdef CONFIG_KEXEC

Regards,
Jason
Daniel P. Smith Oct. 9, 2024, 2:23 p.m. UTC | #2
On 10/7/24 15:34, Jason Andryuk wrote:
> On 2024-10-06 17:49, Daniel P. Smith wrote:
>> To allow a slow conversion of x86 over to struct boot_module, start with
>> replacing all references to struct mod to the early_mod element of struct
>> boot_module. These serves twofold, first to allow the incremental 
>> transition
>> from struct mod fields to struct boot_module fields. The second is to 
>> allow
>> the conversion of function definitions from taking struct mod 
>> parameters to
>> accepting struct boot_module as needed when a transitioned field will be
>> accessed.
>>
>> Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
>> ---
>>   xen/arch/x86/setup.c | 61 ++++++++++++++++++++++++--------------------
>>   1 file changed, 34 insertions(+), 27 deletions(-)
>>
>> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
>> index dd82ca3d43e2..ba4bee6b93af 100644
>> --- a/xen/arch/x86/setup.c
>> +++ b/xen/arch/x86/setup.c
>> @@ -1341,15 +1341,15 @@ void asmlinkage __init noreturn 
>> __start_xen(unsigned long mbi_p)
>>       set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
>>       kexec_reserve_area();
>> -    initial_images = mod;
>> +    initial_images = bi->mods[0].mod;
> 
> Isn't this wrong?
> mod is the array of module_t * of *all* modules, but bi->mods[0].mod is 
> a single module_t *?

No it is not wrong:
   bi->mods[0].mod == __va(mbi->mods_addr)[0]

While the modules themselves get relocated, the location of the array of 
module_t never change.

The question does give me pause to double check the patch ordering, just 
to be sure that mod_start and mod_end are correct up until we transition
to using the boot_module fields.

>>       for ( i = 0; !efi_enabled(EFI_LOADER) && i < bi->nr_modules; i++ )
>>       {
>> -        if ( mod[i].mod_start & (PAGE_SIZE - 1) )
>> +        if ( bi->mods[i].mod->mod_start & (PAGE_SIZE - 1) )
>>               panic("Bootloader didn't honor module alignment 
>> request\n");
>> -        mod[i].mod_end -= mod[i].mod_start;
>> -        mod[i].mod_start >>= PAGE_SHIFT;
>> -        mod[i].reserved = 0;
>> +        bi->mods[i].mod->mod_end -= bi->mods[i].mod->mod_start;
>> +        bi->mods[i].mod->mod_start >>= PAGE_SHIFT;
>> +        bi->mods[i].mod->reserved = 0;
>>       }
>>       /*
> 
>> @@ -1509,13 +1510,15 @@ void asmlinkage __init noreturn 
>> __start_xen(unsigned long mbi_p)
>>   #endif
>>       }
>> -    if ( bi->mods[0].headroom && !mod->reserved )
>> +    if ( bi->mods[0].headroom && !bi->mods[0].mod->reserved )
>>           panic("Not enough memory to relocate the dom0 kernel image\n");
>>       for ( i = 0; i < bi->nr_modules; ++i )
>>       {
>> -        uint64_t s = (uint64_t)mod[i].mod_start << PAGE_SHIFT;
>> +        uint64_t s = (uint64_t)bi->mods[i].mod->mod_start
>> +                        << PAGE_SHIFT;
> 
> pfn_to_paddr() ?

Yep, missed one ( ._.)

>> -        reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end));
>> +        reserve_e820_ram(&boot_e820, s,
>> +                         s + PAGE_ALIGN(bi->mods[i].mod->mod_end));
>>       }
>>       if ( !xen_phys_start )
>> @@ -1593,8 +1596,9 @@ void asmlinkage __init noreturn 
>> __start_xen(unsigned long mbi_p)
>>                   map_e = boot_e820.map[j].addr + boot_e820.map[j].size;
>>                   for ( j = 0; j < bi->nr_modules; ++j )
>>                   {
>> -                    uint64_t end = pfn_to_paddr(mod[j].mod_start) +
>> -                                   mod[j].mod_end;
>> +                    uint64_t end = pfn_to_paddr(
>> +                                   bi->mods[j].mod->mod_start) +
>> +                                   bi->mods[j].mod->mod_end;
> 
> I think you want a different indent.  I think
>      uint64_t end = pfn_to_paddr(bi->mods[j].mod->mod_start)
> 
> will all fit on one line (indented all the way).  (Thunderbird makes it 
> difficult me to send indented.)

Yes, it will fit on one line without the '+', but I believe one of the 
many unwritten coding style rules is that the '+' stays with the LHS, so 
I wrapped the LHS with the '+'.

>>                       if ( map_e < end )
>>                           map_e = end;
>> @@ -1668,11 +1672,13 @@ void asmlinkage __init noreturn 
>> __start_xen(unsigned long mbi_p)
>>       for ( i = 0; i < bi->nr_modules; ++i )
>>       {
>> -        set_pdx_range(mod[i].mod_start,
>> -                      mod[i].mod_start + PFN_UP(mod[i].mod_end));
>> -        map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start),
>> -                         _mfn(mod[i].mod_start),
>> -                         PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
>> +        set_pdx_range(bi->mods[i].mod->mod_start,
>> +                      bi->mods[i].mod->mod_start +
>> +                      PFN_UP(bi->mods[i].mod->mod_end));
>> +        map_pages_to_xen(
>> +            (unsigned long)mfn_to_virt(bi->mods[i].mod->mod_start),
> 
> map_pages_to_xen((unsigned long)maddr_to_virt(bi->mods[i].start),
> 
> All fits on one line.

If it does, I will bring it back up.

v/r,
dps
Jan Beulich Oct. 9, 2024, 2:29 p.m. UTC | #3
On 09.10.2024 16:23, Daniel P. Smith wrote:
> On 10/7/24 15:34, Jason Andryuk wrote:
>> On 2024-10-06 17:49, Daniel P. Smith wrote:
>>> --- a/xen/arch/x86/setup.c
>>> +++ b/xen/arch/x86/setup.c
>>> @@ -1341,15 +1341,15 @@ void asmlinkage __init noreturn 
>>> __start_xen(unsigned long mbi_p)
>>>       set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
>>>       kexec_reserve_area();
>>> -    initial_images = mod;
>>> +    initial_images = bi->mods[0].mod;
>>
>> Isn't this wrong?
>> mod is the array of module_t * of *all* modules, but bi->mods[0].mod is 
>> a single module_t *?
> 
> No it is not wrong:
>    bi->mods[0].mod == __va(mbi->mods_addr)[0]

Yet as it's seemingly wrong, a comment appears to be necessary.

Jan
Daniel P. Smith Oct. 9, 2024, 2:31 p.m. UTC | #4
On 10/9/24 10:29, Jan Beulich wrote:
> On 09.10.2024 16:23, Daniel P. Smith wrote:
>> On 10/7/24 15:34, Jason Andryuk wrote:
>>> On 2024-10-06 17:49, Daniel P. Smith wrote:
>>>> --- a/xen/arch/x86/setup.c
>>>> +++ b/xen/arch/x86/setup.c
>>>> @@ -1341,15 +1341,15 @@ void asmlinkage __init noreturn
>>>> __start_xen(unsigned long mbi_p)
>>>>        set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
>>>>        kexec_reserve_area();
>>>> -    initial_images = mod;
>>>> +    initial_images = bi->mods[0].mod;
>>>
>>> Isn't this wrong?
>>> mod is the array of module_t * of *all* modules, but bi->mods[0].mod is
>>> a single module_t *?
>>
>> No it is not wrong:
>>     bi->mods[0].mod == __va(mbi->mods_addr)[0]
> 
> Yet as it's seemingly wrong, a comment appears to be necessary.

That is fair, will add comment.

v/r,
dps
Jan Beulich Oct. 9, 2024, 3:29 p.m. UTC | #5
On 06.10.2024 23:49, Daniel P. Smith wrote:
> @@ -2061,8 +2067,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
>       * We're going to setup domain0 using the module(s) that we stashed safely
>       * above our heap. The second module, if present, is an initrd ramdisk.
>       */
> -    dom0 = create_dom0(mod, bi->mods[0].headroom,
> -                       initrdidx < bi->nr_modules ? mod + initrdidx : NULL,
> +    dom0 = create_dom0(bi->mods[0].mod, bi->mods[0].headroom,
> +                       initrdidx < bi->nr_modules ?
> +                            bi->mods[initrdidx].mod : NULL,

See an earlier comment regarding wrapped ?:. We certainly never have
indentation levels of 5 blanks.

Jan
Daniel P. Smith Oct. 10, 2024, 1:07 a.m. UTC | #6
On 10/9/24 11:29, Jan Beulich wrote:
> On 06.10.2024 23:49, Daniel P. Smith wrote:
>> @@ -2061,8 +2067,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
>>        * We're going to setup domain0 using the module(s) that we stashed safely
>>        * above our heap. The second module, if present, is an initrd ramdisk.
>>        */
>> -    dom0 = create_dom0(mod, bi->mods[0].headroom,
>> -                       initrdidx < bi->nr_modules ? mod + initrdidx : NULL,
>> +    dom0 = create_dom0(bi->mods[0].mod, bi->mods[0].headroom,
>> +                       initrdidx < bi->nr_modules ?
>> +                            bi->mods[initrdidx].mod : NULL,
> 
> See an earlier comment regarding wrapped ?:. We certainly never have
> indentation levels of 5 blanks.

Can format similar as earlier, and just fyi, that is a stray space from 
wrapping and not a five space indent.

v/r,
dps
diff mbox series

Patch

diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index dd82ca3d43e2..ba4bee6b93af 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -1341,15 +1341,15 @@  void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
     kexec_reserve_area();
 
-    initial_images = mod;
+    initial_images = bi->mods[0].mod;
 
     for ( i = 0; !efi_enabled(EFI_LOADER) && i < bi->nr_modules; i++ )
     {
-        if ( mod[i].mod_start & (PAGE_SIZE - 1) )
+        if ( bi->mods[i].mod->mod_start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request\n");
-        mod[i].mod_end -= mod[i].mod_start;
-        mod[i].mod_start >>= PAGE_SHIFT;
-        mod[i].reserved = 0;
+        bi->mods[i].mod->mod_end -= bi->mods[i].mod->mod_start;
+        bi->mods[i].mod->mod_start >>= PAGE_SHIFT;
+        bi->mods[i].mod->reserved = 0;
     }
 
     /*
@@ -1360,6 +1360,7 @@  void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( xen_phys_start )
     {
+        unsigned int xen = bi->nr_modules;
         relocated = true;
 
         /*
@@ -1367,8 +1368,8 @@  void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
          * respective reserve_e820_ram() invocation below. No need to
          * query efi_boot_mem_unused() here, though.
          */
-        mod[bi->nr_modules].mod_start = virt_to_mfn(_stext);
-        mod[bi->nr_modules].mod_end = __2M_rwdata_end - _stext;
+        bi->mods[xen].mod->mod_start = virt_to_mfn(_stext);
+        bi->mods[xen].mod->mod_end = __2M_rwdata_end - _stext;
     }
 
     bi->mods[0].headroom =
@@ -1462,9 +1463,9 @@  void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
             struct boot_module *bm = &bi->mods[j];
             unsigned long size;
 
-            size = PAGE_ALIGN(bm->headroom + mod[j].mod_end);
+            size = PAGE_ALIGN(bm->headroom + bm->mod->mod_end);
 
-            if ( mod[j].reserved )
+            if ( bi->mods[j].mod->reserved )
                 continue;
 
             /* Don't overlap with other modules (or Xen itself). */
@@ -1476,14 +1477,14 @@  void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
             if ( s < end &&
                  (bm->headroom ||
-                  ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) )
+                  ((end - size) >> PAGE_SHIFT) > bm->mod->mod_start) )
             {
                 move_memory(end - size + bm->headroom,
-                            (uint64_t)mod[j].mod_start << PAGE_SHIFT,
-                            mod[j].mod_end);
-                mod[j].mod_start = (end - size) >> PAGE_SHIFT;
-                mod[j].mod_end += bm->headroom;
-                mod[j].reserved = 1;
+                            (uint64_t)bm->mod->mod_start << PAGE_SHIFT,
+                            bm->mod->mod_end);
+                bm->mod->mod_start = (end - size) >> PAGE_SHIFT;
+                bm->mod->mod_end += bm->headroom;
+                bm->mod->reserved = 1;
             }
         }
 
@@ -1509,13 +1510,15 @@  void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 #endif
     }
 
-    if ( bi->mods[0].headroom && !mod->reserved )
+    if ( bi->mods[0].headroom && !bi->mods[0].mod->reserved )
         panic("Not enough memory to relocate the dom0 kernel image\n");
     for ( i = 0; i < bi->nr_modules; ++i )
     {
-        uint64_t s = (uint64_t)mod[i].mod_start << PAGE_SHIFT;
+        uint64_t s = (uint64_t)bi->mods[i].mod->mod_start
+                        << PAGE_SHIFT;
 
-        reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end));
+        reserve_e820_ram(&boot_e820, s,
+                         s + PAGE_ALIGN(bi->mods[i].mod->mod_end));
     }
 
     if ( !xen_phys_start )
@@ -1593,8 +1596,9 @@  void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
                 map_e = boot_e820.map[j].addr + boot_e820.map[j].size;
                 for ( j = 0; j < bi->nr_modules; ++j )
                 {
-                    uint64_t end = pfn_to_paddr(mod[j].mod_start) +
-                                   mod[j].mod_end;
+                    uint64_t end = pfn_to_paddr(
+                                   bi->mods[j].mod->mod_start) +
+                                   bi->mods[j].mod->mod_end;
 
                     if ( map_e < end )
                         map_e = end;
@@ -1668,11 +1672,13 @@  void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     for ( i = 0; i < bi->nr_modules; ++i )
     {
-        set_pdx_range(mod[i].mod_start,
-                      mod[i].mod_start + PFN_UP(mod[i].mod_end));
-        map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start),
-                         _mfn(mod[i].mod_start),
-                         PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
+        set_pdx_range(bi->mods[i].mod->mod_start,
+                      bi->mods[i].mod->mod_start +
+                      PFN_UP(bi->mods[i].mod->mod_end));
+        map_pages_to_xen(
+            (unsigned long)mfn_to_virt(bi->mods[i].mod->mod_start),
+            _mfn(bi->mods[i].mod->mod_start),
+            PFN_UP(bi->mods[i].mod->mod_end), PAGE_HYPERVISOR);
     }
 
 #ifdef CONFIG_KEXEC
@@ -2061,8 +2067,9 @@  void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
      * We're going to setup domain0 using the module(s) that we stashed safely
      * above our heap. The second module, if present, is an initrd ramdisk.
      */
-    dom0 = create_dom0(mod, bi->mods[0].headroom,
-                       initrdidx < bi->nr_modules ? mod + initrdidx : NULL,
+    dom0 = create_dom0(bi->mods[0].mod, bi->mods[0].headroom,
+                       initrdidx < bi->nr_modules ?
+                            bi->mods[initrdidx].mod : NULL,
                        kextra, bi->loader);
     if ( !dom0 )
         panic("Could not set up DOM0 guest OS\n");