xen/x86: Check supported features even for PVH dom0
PATCH v3 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.
Changes since v2:
- rename dom0_check_parms to initdom_check_parms;
- move call to initdom_check_parms in PVH code earlier;
- make "struct domain" constant.
--- 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
@@ -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 initdom_check_parms ( +const 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
@@ -692,6 +692,9 @@ static int __init pvh_load_kernel(return -EINVAL ; } +if ( (rc =initdom_check_parms (d, &parms)) !=0 ) +return rc; +/* Copy the OS image and free temporary buffer. */ elf.dest_base = (void *)(parms.virt_kstart - parms.virt_base); elf.dest_size = parms.virt_kend - parms.virt_kstart;
xen/arch/x86/include/asm/dom0_build.h +2 -0
@@ -8,6 +8,8 @@extern unsigned int dom0_memflags; +int initdom_check_parms (const 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
@@ -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 =initdom_check_parms (d, &parms)) !=0 ) +return rc; nr_pages =dom0_compute_nr_pages (d, &parms, initrd_len);
Signature · 1 line
2.43.0
Quoted 5 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.
Signed-off-by Frediano Ziglio <[email protected]>
Quoted 10 lines
xen/arch/x86/dom0_build.c +4
-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 initdom_check_parms ( +const struct domain *d,const struct elf_dom_parms *parms) +{ +if ( parms->elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES ].type ==XEN_ENT_NONE )
xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 336
Quoted 10 lines
xen/arch/x86/dom0_build.c +10
-0+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 ; +}
Merely as a remark - personally I would have made a function like this return a boolean. Both call sites would imo benefit from that.
Jan
Quoted 5 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.
Signed-off-by Frediano Ziglio <[email protected]>
I think you dropped my RB from v2:
Thanks, Roger.
Quoted 12 lines · Frediano Ziglio
xen/arch/x86/dom0_build.c +4
-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 initdom_check_parms ( +const struct domain *d,const struct elf_dom_parms *parms) +{ +if ( parms->elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES ].type ==XEN_ENT_NONE )
xen/arch/x86/dom0_build.c unsigned long __init dom0_paging_pages(const struct domain *d, · line 336
Quoted 10 lines
xen/arch/x86/dom0_build.c +10
-0+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 ; +}
Your v1 structure was better (give or take whitespace mangling).
This needs to be a nested pair of if() conditions to not need rewriting when SecureBoot check is added.
I'm going to fold this adjustment and commit it, because I need this patch to fix a separate bug in the patchqueue.
~Andrew