Skip to contentSkip to conversation

xen/x86: Check supported features even for PVH dom0

PATCH Superseded Frediano Ziglio 3 participants 7 messages Apr 2 – Apr 8

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/x86: Check supported features even for PVH dom0

The supported features ELF notes was tested only if the dom0 was PV. Factor out a function to check ELF notes and reuse it even for PVH.

--
Changes since v1:
- fix typo in title;
- fix minor formatting issue;
- use is_hardware_domain instead of checking is_pv_shim;
- reduce indentation returning earlier;
- return error instead of jumping to cleanup code.

---
 xen/arch/x86/dom0_build.c             | 14 ++++++++++++++
 xen/arch/x86/hvm/dom0_build.c         |  3 +++
 xen/arch/x86/include/asm/dom0_build.h |  2 ++
 xen/arch/x86/pv/dom0_build.c          | 10 ++--------
 4 files changed, 21 insertions(+), 8 deletions(-)
xen/arch/x86/dom0_build.c +14 -0
index 864dd9e53e..a33ce77321 100644
@@ -320,6 +320,20 @@ unsigned long __init dom0_paging_pages(const struct domain *d,
     return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT);
 }
 
+int __init dom0_check_parms(
+    struct domain *d, const struct elf_dom_parms *parms)
+{
+    if ( parms->elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES].type == XEN_ENT_NONE )
+        return 0;
+
+    if ( is_hardware_domain(d) && !test_bit(XENFEAT_dom0, parms->f_supported) )
+    {
+        printk("Kernel does not support Dom0 operation\n");
+        return -EINVAL;
+    }
+
+    return 0;
+}
 
 /*
  * If allocation isn't specified, reserve 1/16th of available memory for
xen/arch/x86/hvm/dom0_build.c +3 -0
index d69a83b089..f95a00acfd 100644
@@ -699,6 +699,9 @@ static int __init pvh_load_kernel(
     if ( !check_and_adjust_load_address(d, &elf, &parms) )
         return -ENOSPC;
 
+    if ( (rc = dom0_check_parms(d, &parms)) != 0 )
+        return rc;
+
     elf_set_vcpu(&elf, v);
     rc = elf_load_binary(&elf);
     if ( rc < 0 )
xen/arch/x86/include/asm/dom0_build.h +2 -0
index ff021c24af..b7bbfcbe6a 100644
@@ -8,6 +8,8 @@
 
 extern unsigned int dom0_memflags;
 
+int dom0_check_parms(struct domain *d,
+                     const struct elf_dom_parms *parms);
 unsigned long dom0_compute_nr_pages(struct domain *d,
                                     struct elf_dom_parms *parms,
                                     unsigned long initrd_len);
xen/arch/x86/pv/dom0_build.c +2 -8
index 075a3646c2..d50e1b9f78 100644
@@ -494,14 +494,8 @@ static int __init dom0_construct(const struct boot_domain *bd)
         return -EINVAL;
     }
 
-    if ( parms.elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES].type != XEN_ENT_NONE )
-    {
-        if ( !pv_shim && !test_bit(XENFEAT_dom0, parms.f_supported) )
-        {
-            printk("Kernel does not support Dom0 operation\n");
-            return -EINVAL;
-        }
-    }
+    if ( (rc = dom0_check_parms(d, &parms)) != 0 )
+        return rc;
 
     nr_pages = dom0_compute_nr_pages(d, &parms, initrd_len);
 
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 24 lines · Frediano Ziglio

The supported features ELF notes was tested only if the dom0 was PV. Factor out a function to check ELF notes and reuse it even for PVH.

--
Changes since v1:
- fix typo in title;
- fix minor formatting issue;
- use is_hardware_domain instead of checking is_pv_shim;
- reduce indentation returning earlier;
- return error instead of jumping to cleanup code.

---
 xen/arch/x86/dom0_build.c             | 14 ++++++++++++++
 xen/arch/x86/hvm/dom0_build.c         |  3 +++
 xen/arch/x86/include/asm/dom0_build.h |  2 ++
 xen/arch/x86/pv/dom0_build.c          | 10 ++--------
 4 files changed, 21 insertions(+), 8 deletions(-)
xen/arch/x86/dom0_build.c +0 -0
index 864dd9e53e..a33ce77321 100644

xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 324

Quoted 5 lines
xen/arch/x86/dom0_build.c +2 -0
@@ -320,6 +320,20 @@ unsigned long __init dom0_paging_pages(const struct domain *d,
     return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT);
 }
 
+int __init dom0_check_parms(
+    struct domain *d, const struct elf_dom_parms *parms)

d should be const also.

Quoted 20 lines
xen/arch/x86/dom0_build.c +12 -0
+{
+    if ( parms->elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES].type == XEN_ENT_NONE )
+        return 0;
+
+    if ( is_hardware_domain(d) && !test_bit(XENFEAT_dom0, parms->f_supported) )
+    {
+        printk("Kernel does not support Dom0 operation\n");
+        return -EINVAL;
+    }
+
+    return 0;
+}
 
 /*
  * If allocation isn't specified, reserve 1/16th of available memory for
xen/arch/x86/hvm/dom0_build.c +0 -0
index d69a83b089..f95a00acfd 100644

xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel( · line 703

Quoted 5 lines
xen/arch/x86/hvm/dom0_build.c +2 -0
@@ -699,6 +699,9 @@ static int __init pvh_load_kernel(
     if ( !check_and_adjust_load_address(d, &elf, &parms) )
         return -ENOSPC;
 
+    if ( (rc = dom0_check_parms(d, &parms)) != 0 )
+        return rc;

I would do the check ahead of check_and_adjust_load_address(), as then we could avoid the load address adjustment if we detect earlier than the dom0 feature is not present. But that's just my taste.

I can adjust the const-ification of d on commit if there are no further objections:

Thanks, Roger.

#2 lore raw
Quoted 64 lines · Roger Pau Monné
Quoted 24 lines · Frediano Ziglio

The supported features ELF notes was tested only if the dom0 was PV. Factor out a function to check ELF notes and reuse it even for PVH.

--
Changes since v1:
- fix typo in title;
- fix minor formatting issue;
- use is_hardware_domain instead of checking is_pv_shim;
- reduce indentation returning earlier;
- return error instead of jumping to cleanup code.

---
 xen/arch/x86/dom0_build.c             | 14 ++++++++++++++
 xen/arch/x86/hvm/dom0_build.c         |  3 +++
 xen/arch/x86/include/asm/dom0_build.h |  2 ++
 xen/arch/x86/pv/dom0_build.c          | 10 ++--------
 4 files changed, 21 insertions(+), 8 deletions(-)
xen/arch/x86/dom0_build.c +0 -0
index 864dd9e53e..a33ce77321 100644

xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 324

Quoted 5 lines
xen/arch/x86/dom0_build.c +2 -0
@@ -320,6 +320,20 @@ unsigned long __init dom0_paging_pages(const struct domain *d,
     return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT);
 }
 
+int __init dom0_check_parms(
+    struct domain *d, const struct elf_dom_parms *parms)

d should be const also.

Quoted 20 lines
xen/arch/x86/dom0_build.c +12 -0
+{
+    if ( parms->elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES].type == XEN_ENT_NONE )
+        return 0;
+
+    if ( is_hardware_domain(d) && !test_bit(XENFEAT_dom0, parms->f_supported) )
+    {
+        printk("Kernel does not support Dom0 operation\n");
+        return -EINVAL;
+    }
+
+    return 0;
+}
 
 /*
  * If allocation isn't specified, reserve 1/16th of available memory for
xen/arch/x86/hvm/dom0_build.c +0 -0
index d69a83b089..f95a00acfd 100644

xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel( · line 703

Quoted 5 lines
xen/arch/x86/hvm/dom0_build.c +2 -0
@@ -699,6 +699,9 @@ static int __init pvh_load_kernel(
     if ( !check_and_adjust_load_address(d, &elf, &parms) )
         return -ENOSPC;
 
+    if ( (rc = dom0_check_parms(d, &parms)) != 0 )
+        return rc;

I would do the check ahead of check_and_adjust_load_address(), as then we could avoid the load address adjustment if we detect earlier than the dom0 feature is not present. But that's just my taste.

Quoted 6 lines

I can adjust the const-ification of d on commit if there are no further objections:

Thanks, Roger.

Fine with me.

Frediano

#4 lore raw
In reply to Frediano Ziglio

xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 323

Quoted 7 lines · Frediano Ziglio
xen/arch/x86/dom0_build.c +1 -0
@@ -320,6 +320,20 @@ unsigned long __init dom0_paging_pages(const struct domain *d,
     return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT);
 }
 
+int __init dom0_check_parms(

I understand the "dom0" in the name is owing to the filename and perhaps adjacent other similar functions, yet ...

xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 329

Quoted 6 lines
xen/arch/x86/dom0_build.c +6 -0
+    struct domain *d, const struct elf_dom_parms *parms)
+{
+    if ( parms->elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES].type == XEN_ENT_NONE )
+        return 0;
+
+    if ( is_hardware_domain(d) && !test_bit(XENFEAT_dom0, parms->f_supported) )

... if this was about solely Dom0, no is_hardware_domain() should be present here. Maybe s/dom0/initdom/ ?

Jan

#3 lore raw
In reply to Roger Pau Monné
Quoted 56 lines · Roger Pau Monné
Quoted 24 lines · Frediano Ziglio

The supported features ELF notes was tested only if the dom0 was PV. Factor out a function to check ELF notes and reuse it even for PVH.

--
Changes since v1:
- fix typo in title;
- fix minor formatting issue;
- use is_hardware_domain instead of checking is_pv_shim;
- reduce indentation returning earlier;
- return error instead of jumping to cleanup code.

---
 xen/arch/x86/dom0_build.c             | 14 ++++++++++++++
 xen/arch/x86/hvm/dom0_build.c         |  3 +++
 xen/arch/x86/include/asm/dom0_build.h |  2 ++
 xen/arch/x86/pv/dom0_build.c          | 10 ++--------
 4 files changed, 21 insertions(+), 8 deletions(-)
xen/arch/x86/dom0_build.c +0 -0
index 864dd9e53e..a33ce77321 100644

xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 324

Quoted 5 lines
xen/arch/x86/dom0_build.c +2 -0
@@ -320,6 +320,20 @@ unsigned long __init dom0_paging_pages(const struct domain *d,
     return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT);
 }
 
+int __init dom0_check_parms(
+    struct domain *d, const struct elf_dom_parms *parms)

d should be const also.

Quoted 23 lines
xen/arch/x86/dom0_build.c +12 -0
+{
+    if ( parms->elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES].type == XEN_ENT_NONE )
+        return 0;
+
+    if ( is_hardware_domain(d) && !test_bit(XENFEAT_dom0, parms->f_supported) )
+    {
+        printk("Kernel does not support Dom0 operation\n");
+        return -EINVAL;
+    }
+
+    return 0;
+}
 
 /*
  * If allocation isn't specified, reserve 1/16th of available memory for
xen/arch/x86/hvm/dom0_build.c +0 -0
index d69a83b089..f95a00acfd 100644
@@ -699,6 +699,9 @@ static int __init pvh_load_kernel(
     if ( !check_and_adjust_load_address(d, &elf, &parms) )
         return -ENOSPC;
 
Quoted 6 lines

xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel( · line 703

Quoted 2 lines
xen/arch/x86/hvm/dom0_build.c +2 -0
+    if ( (rc = dom0_check_parms(d, &parms)) != 0 )
+        return rc;

I would do the check ahead of check_and_adjust_load_address(), as then we could avoid the load address adjustment if we detect earlier than the dom0 feature is not present. But that's just my taste.

+1, perhaps even yet a few more lines further up.

Jan

#5 lore raw
In reply to Jan Beulich
Quoted 12 lines · Jan Beulich

xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 323

Quoted 7 lines · Frediano Ziglio
xen/arch/x86/dom0_build.c +1 -0
@@ -320,6 +320,20 @@ unsigned long __init dom0_paging_pages(const struct domain *d,
     return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT);
 }
 
+int __init dom0_check_parms(

I understand the "dom0" in the name is owing to the filename and perhaps adjacent other similar functions, yet ...

Quoted 9 lines

xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 329

Quoted 6 lines
xen/arch/x86/dom0_build.c +6 -0
+    struct domain *d, const struct elf_dom_parms *parms)
+{
+    if ( parms->elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES].type == XEN_ENT_NONE )
+        return 0;
+
+    if ( is_hardware_domain(d) && !test_bit(XENFEAT_dom0, parms->f_supported) )

... if this was about solely Dom0, no is_hardware_domain() should be present here. Maybe s/dom0/initdom/ ?

I think the naming of the feature flag is not very useful TBH. What is the kernel really advertising when setting XENFEAT_dom0? I've assumed it was the capability of running as a hardware domain, which requires a different set of functionality inside of the kernel to deal with hardware devices.

We might want to take this opportunity to clarify in the headers what XENFEAT_dom0 means.

Thanks, Roger.

#6 lore raw
Quoted 23 lines · Roger Pau Monné
Quoted 12 lines · Jan Beulich

xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 323

Quoted 7 lines · Frediano Ziglio
xen/arch/x86/dom0_build.c +1 -0
@@ -320,6 +320,20 @@ unsigned long __init dom0_paging_pages(const struct domain *d,
     return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT);
 }
 
+int __init dom0_check_parms(

I understand the "dom0" in the name is owing to the filename and perhaps adjacent other similar functions, yet ...

Quoted 9 lines

xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 329

Quoted 6 lines
xen/arch/x86/dom0_build.c +6 -0
+    struct domain *d, const struct elf_dom_parms *parms)
+{
+    if ( parms->elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES].type == XEN_ENT_NONE )
+        return 0;
+
+    if ( is_hardware_domain(d) && !test_bit(XENFEAT_dom0, parms->f_supported) )

... if this was about solely Dom0, no is_hardware_domain() should be present here. Maybe s/dom0/initdom/ ?

Quoted 5 lines

I think the naming of the feature flag is not very useful TBH. What is the kernel really advertising when setting XENFEAT_dom0? I've assumed it was the capability of running as a hardware domain, which requires a different set of functionality inside of the kernel to deal with hardware devices.

Yes, that's my understanding.

Quoted 2 lines

We might want to take this opportunity to clarify in the headers what XENFEAT_dom0 means.

I'm not opposed, yet this isn't directly related to giving the function an appropriate name.

Jan