Skip to contentSkip to conversation

x86/pvh: pass module command line to dom0

PATCH In review Roger Pau Monne 3 participants 4 messages Jan 29, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/pvh: pass module command line to dom0

Both the multiboot and the HVM start info structures allow passing a string together with a module. Implement the missing support in pvh_load_kernel so that module strings found in the multiboot structure are forwarded to dom0.

Fixes 62ba982424 ('x86: parse Dom0 kernel for PVHv2')

---
NB: str cannot be made const because __hvm_copy buf parameter (that maps to str in the added code) is bi-directional depending on the flags passed to the function.

---
 xen/arch/x86/hvm/dom0_build.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/dom0_build.c +15 -1
index 12a82c9d7c..5f9281ce30 100644
@@ -617,7 +617,21 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image,
 
         mod.paddr = last_addr;
         mod.size = initrd->mod_end;
-        last_addr += ROUNDUP(initrd->mod_end, PAGE_SIZE);
+        last_addr += ROUNDUP(initrd->mod_end, elf_64bit(&elf) ? 8 : 4);
+        if ( initrd->string )
+        {
+            char *str = __va(initrd->string);
+
+            rc = hvm_copy_to_guest_phys(last_addr, str, strlen(str) + 1, v);
+            if ( rc )
+            {
+                printk("Unable to copy module command line\n");
+                return rc;
+            }
+            mod.cmdline_paddr = last_addr;
+            last_addr += strlen(str) + 1;
+        }
+        last_addr = ROUNDUP(last_addr, PAGE_SIZE);
     }
 
     /* Free temporary buffers. */
Signature · 1 line
2.29.2
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Roger Pau Monne

Both the multiboot and the HVM start info structures allow passing a string together with a module. Implement the missing support in pvh_load_kernel so that module strings found in the multiboot structure are forwarded to dom0.

Fixes 62ba982424 ('x86: parse Dom0 kernel for PVHv2')

This really is relevant only when it's not an initrd which gets passed as module, I suppose? I'm not fully convinced I'd call this a bug then, but perhaps more a missing feature. Which in turn means I'm not sure about the change's disposition wrt 4.15. Cc-ing Ian.

Quoted 1 line

Albeit ...

Quoted 10 lines
xen/arch/x86/hvm/dom0_build.c +3 -1
@@ -617,7 +617,21 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image,
 
         mod.paddr = last_addr;
         mod.size = initrd->mod_end;
-        last_addr += ROUNDUP(initrd->mod_end, PAGE_SIZE);
+        last_addr += ROUNDUP(initrd->mod_end, elf_64bit(&elf) ? 8 : 4);
+        if ( initrd->string )
+        {

xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel(struct domain *d, const module_t *image, · line 632

Quoted 10 lines
xen/arch/x86/hvm/dom0_build.c +10 -0
+            char *str = __va(initrd->string);
+
+            rc = hvm_copy_to_guest_phys(last_addr, str, strlen(str) + 1, v);
+            if ( rc )
+            {
+                printk("Unable to copy module command line\n");
+                return rc;
+            }
+            mod.cmdline_paddr = last_addr;
+            last_addr += strlen(str) + 1;

... it would have been nice if this length was calculated just once, into a local variable. I'd be fine making the adjustment while committing, so long as you agree.

Jan

#2 lore raw
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monne

Both the multiboot and the HVM start info structures allow passing a string together with a module. Implement the missing support in pvh_load_kernel so that module strings found in the multiboot structure are forwarded to dom0.

Quoted 7 lines
Quoted 1 line
Fixes 62ba982424 ('x86: parse Dom0 kernel for PVHv2')

This really is relevant only when it's not an initrd which gets passed as module, I suppose? I'm not fully convinced I'd call this a bug then, but perhaps more a missing feature. Which in turn means I'm not sure about the change's disposition wrt 4.15. Cc-ing Ian.

Right, the whole kernel loading stuff is IMO not the best one, because all the multiboot modules apart from Xen and the dom0 kernel (the first 2) should be passed to the dom0 IMO using the HVM start_info structure.

The module command line is just a red herring, as none of the OSes that currently have PVH dom0 support need this, but still would be nice to get it fixed so that if new OSes are added it works properly. It's unexpected that a loader can append a string to a module, but then the dom0 kernel finds none in the start_info module list.

Regarding 4.15 acceptance: I think this is very low risk, as it exclusively touches PVH dom0 code which is experimental anyway, but I'm not going to insist on it getting committed.

Quoted 21 lines
Quoted 1 line

Albeit ...

Quoted 16 lines
xen/arch/x86/hvm/dom0_build.c +9 -1
@@ -617,7 +617,21 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image,
 
         mod.paddr = last_addr;
         mod.size = initrd->mod_end;
-        last_addr += ROUNDUP(initrd->mod_end, PAGE_SIZE);
+        last_addr += ROUNDUP(initrd->mod_end, elf_64bit(&elf) ? 8 : 4);
+        if ( initrd->string )
+        {
+            char *str = __va(initrd->string);
+
+            rc = hvm_copy_to_guest_phys(last_addr, str, strlen(str) + 1, v);
+            if ( rc )
+            {
+                printk("Unable to copy module command line\n");
Quoted 8 lines

xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel(struct domain *d, const module_t *image, · line 632

Quoted 4 lines
xen/arch/x86/hvm/dom0_build.c +4 -0
+                return rc;
+            }
+            mod.cmdline_paddr = last_addr;
+            last_addr += strlen(str) + 1;

... it would have been nice if this length was calculated just once, into a local variable. I'd be fine making the adjustment while committing, so long as you agree.

Sure, feel free to add a len variable to the scope of the if.

Thanks, Roger.

#3 lore raw

Roger Pau Monné writes ("Re: [PATCH] x86/pvh: pass module command line to dom0"):

Quoted 26 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monne
Quoted 5 lines

Both the multiboot and the HVM start info structures allow passing a string together with a module. Implement the missing support in pvh_load_kernel so that module strings found in the multiboot structure are forwarded to dom0.

Quoted 7 lines
Quoted 1 line
Fixes 62ba982424 ('x86: parse Dom0 kernel for PVHv2')

This really is relevant only when it's not an initrd which gets passed as module, I suppose? I'm not fully convinced I'd call this a bug then, but perhaps more a missing feature. Which in turn means I'm not sure about the change's disposition wrt 4.15. Cc-ing Ian.

Right, the whole kernel loading stuff is IMO not the best one, because all the multiboot modules apart from Xen and the dom0 kernel (the first 2) should be passed to the dom0 IMO using the HVM start_info structure.

The module command line is just a red herring, as none of the OSes that currently have PVH dom0 support need this, but still would be nice to get it fixed so that if new OSes are added it works properly. It's unexpected that a loader can append a string to a module, but then the dom0 kernel finds none in the start_info module list.

Quoted 3 lines

Regarding 4.15 acceptance: I think this is very low risk, as it exclusively touches PVH dom0 code which is experimental anyway, but I'm not going to insist on it getting committed.

Thanks for the explanation. I'm not sure from reading this, whether this is a bugfix, but your analysis is convincing, so: