Skip to contentSkip to conversation

x86/boot: Misc improvements to dom0 construction

PATCH In review Andrew Cooper 2 participants 9 messages May 20, 2019 – May 23, 2019

lore
Share & tools
lore
#0 lore raw

cover x86/boot: Misc improvements to dom0 construction

This started out as just patch 3, trying to clean up the remains of the pv-l1tf debugging, and expanded a little upon reading the surrounding code.

Andrew Cooper (4):
x86/pv: Fix error handling in dom0_construct_pv() x86/boot: Rename dom0_{pvh,verbose} variables to have an opt_ prefix x86/boot: Wire up dom0=shadow for PV dom0
x86/boot: Link opt_dom0_verbose to CONFIG_VERBOSE_DEBUG

 docs/misc/xen-command-line.pandoc | 17 +++++++++++------
 xen/arch/x86/dom0_build.c         | 20 ++++++--------------
 xen/arch/x86/hvm/dom0_build.c     |  2 +-
 xen/arch/x86/pv/dom0_build.c      | 26 +++++++++++++++-----------
 xen/arch/x86/setup.c              |  2 +-
 xen/include/asm-x86/setup.h       |  4 ++--
 6 files changed, 36 insertions(+), 35 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/4 x86/pv: Fix error handling in dom0_construct_pv()

One path in dom0_construct_pv() returns -1 unlike all other error paths. Switch it to returning -EINVAL.

This was last modified by c/s c84481fb XSA-55, but the bug predates that series. However, this patch did (for no obvious reason) introduce a bifurcated tail to the function with two subtly different elf_check_broken() clauses.

As the elf_check_broken() is just a warning and doesn't influence the further boot, fold the exit paths together and use a single clause.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/pv/dom0_build.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
xen/arch/x86/pv/dom0_build.c +2 -8
index cef2d42..064a10e 100644
@@ -735,7 +735,7 @@ int __init dom0_construct_pv(struct domain *d,
             mapcache_override_current(NULL);
             switch_cr3_cr4(current->arch.cr3, read_cr4());
             printk("Invalid HYPERCALL_PAGE field in ELF notes.\n");
-            rc = -1;
+            rc = -EINVAL;
             goto out;
         }
         hypercall_page_initialise(
@@ -903,21 +903,15 @@ int __init dom0_construct_pv(struct domain *d,
     rc = dom0_setup_permissions(d);
     BUG_ON(rc != 0);
 
-    if ( elf_check_broken(&elf) )
-        printk(" Xen warning: dom0 kernel broken ELF: %s\n",
-               elf_check_broken(&elf));
-
     if ( d->domain_id == hardware_domid )
         iommu_hwdom_init(d);
 
     v->is_initialised = 1;
     clear_bit(_VPF_down, &v->pause_flags);
 
-    return 0;
-
 out:
     if ( elf_check_broken(&elf) )
-        printk(" Xen dom0 kernel broken ELF: %s\n",
+        printk(XENLOG_WARNING "Dom0 kernel broken ELF: %s\n",
                elf_check_broken(&elf));
 
     return rc;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] x86/pv: Fix error handling in dom0_construct_pv()

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 20.05.19 at 12:18, <[email protected]> wrote:

One path in dom0_construct_pv() returns -1 unlike all other error paths. Switch it to returning -EINVAL.

This was last modified by c/s c84481fb XSA-55, but the bug predates that series. However, this patch did (for no obvious reason) introduce a bifurcated tail to the function with two subtly different elf_check_broken() clauses.

Quoted 4 lines

As the elf_check_broken() is just a warning and doesn't influence the further boot, fold the exit paths together and use a single clause.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

PATCH 2/4 x86/boot: Rename dom0_{pvh, verbose} variables to have an opt_ prefix

In reply to Andrew Cooper

For consistency with other command line options.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/dom0_build.c     | 12 ++++++------
 xen/arch/x86/hvm/dom0_build.c |  2 +-
 xen/arch/x86/setup.c          |  2 +-
 xen/include/asm-x86/setup.h   |  4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)
xen/arch/x86/dom0_build.c +6 -6
index 73f5407..27315d5 100644
@@ -261,7 +261,7 @@ unsigned int __init dom0_max_vcpus(void)
         max_vcpus = opt_dom0_max_vcpus_min;
     if ( opt_dom0_max_vcpus_max < max_vcpus )
         max_vcpus = opt_dom0_max_vcpus_max;
-    limit = dom0_pvh ? HVM_MAX_VCPUS : MAX_VIRT_CPUS;
+    limit = opt_dom0_pvh ? HVM_MAX_VCPUS : MAX_VIRT_CPUS;
     if ( max_vcpus > limit )
         max_vcpus = limit;
 
@@ -280,8 +280,8 @@ struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
 #ifdef CONFIG_SHADOW_PAGING
 bool __initdata opt_dom0_shadow;
 #endif
-bool __initdata dom0_pvh = !IS_ENABLED(CONFIG_PV);
-bool __initdata dom0_verbose;
+bool __initdata opt_dom0_pvh = !IS_ENABLED(CONFIG_PV);
+bool __initdata opt_dom0_verbose;
 
 static int __init parse_dom0_param(const char *s)
 {
@@ -296,15 +296,15 @@ static int __init parse_dom0_param(const char *s)
             ss = strchr(s, '\0');
 
         if ( IS_ENABLED(CONFIG_PV) && !cmdline_strcmp(s, "pv") )
-            dom0_pvh = false;
+            opt_dom0_pvh = false;
         else if ( IS_ENABLED(CONFIG_HVM) && !cmdline_strcmp(s, "pvh") )
-            dom0_pvh = true;
+            opt_dom0_pvh = true;
 #ifdef CONFIG_SHADOW_PAGING
         else if ( (val = parse_boolean("shadow", s, ss)) >= 0 )
             opt_dom0_shadow = val;
 #endif
         else if ( (val = parse_boolean("verbose", s, ss)) >= 0 )
-            dom0_verbose = val;
+            opt_dom0_verbose = val;
         else
             rc = -EINVAL;
 
xen/arch/x86/hvm/dom0_build.c +1 -1
index aa599f0..8845399 100644
@@ -484,7 +484,7 @@ static int __init pvh_populate_p2m(struct domain *d)
             return rc;
     }
 
-    if ( dom0_verbose )
+    if ( opt_dom0_verbose )
         print_order_stats(d);
 
     return 0;
xen/arch/x86/setup.c +1 -1
index 9566b1d..0ed94a6 100644
@@ -1713,7 +1713,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     init_guest_cpuid();
     init_guest_msr_policy();
 
-    if ( dom0_pvh )
+    if ( opt_dom0_pvh )
     {
         dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm_guest |
                            ((hvm_hap_supported() && !opt_dom0_shadow) ?
xen/include/asm-x86/setup.h +2 -2
index bb4c385..15d6363 100644
@@ -64,8 +64,8 @@ extern bool opt_dom0_shadow;
 #else
 #define opt_dom0_shadow false
 #endif
-extern bool dom0_pvh;
-extern bool dom0_verbose;
+extern bool opt_dom0_pvh;
+extern bool opt_dom0_verbose;
 
 #define max_init_domid (0)
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] x86/boot: Rename dom0_{pvh, verbose} variables to have an opt_ prefix

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 20.05.19 at 12:18, <[email protected]> wrote:

For consistency with other command line options.

No functional change.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

PATCH 3/4 x86/boot: Wire up dom0=shadow for PV dom0

In reply to Andrew Cooper

This would have been very handy when debugging some pv-l1tf issues. As there is no cost to supporting it, wire it up.

Due to the way dom0 is constructed, switching into shadow mode must be done after the pagetables are written, and because of partially being in dom0 context, shadow_enable() doesn't like the state it finds.

Reuse the pv_l1tf tasklet for convenience, which will switch dom0 into shadow mode just before it starts executing.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 docs/misc/xen-command-line.pandoc | 14 +++++++++-----
 xen/arch/x86/dom0_build.c         |  8 --------
 xen/arch/x86/pv/dom0_build.c      |  9 +++++++++
 3 files changed, 18 insertions(+), 13 deletions(-)
docs/misc/xen-command-line.pandoc +9 -5
index 1fc1802..e6d241e 100644
@@ -675,12 +675,16 @@ Controls for how dom0 is constructed on x86 systems.
         selected mode.
     *   For a PVH dom0, the hardware must have VT-x/SVM extensions available.
 
-*   The `shadow` boolean is only applicable when dom0 is constructed as a PVH
-    guest, and controls whether dom0 uses hardware assisted paging, or shadow
-    paging.  The default is HAP when available, and shadow otherwise.
+*   The `shadow` boolean allows dom0 to be explicitly constructed using shadow
+    paging.  This option is unavailable when `CONFIG_SHADOW_PAGING` is
+    disabled.
 
-    This option is unavailable when `CONFIG_SHADOW_PAGING` is disabled.  Such
-    builds of Xen require HAP-capable hardware to use a PVH dom0.
+    For PVH, dom0 defaults to using HAP on capable hardware, and falls back to
+    shadow paging otherwise.  A PVH dom0 cannot be used if Xen is compiled
+    without paging support, and the hardware lacks HAP support.
+
+    For PV, the use of dom0 shadow mode is only for development purposes.  PV
+    guests do no require any paging support by default.
 
 *   The `verbose` boolean is intended for diagnostics, and prints out extra
     information during the dom0 build.  It defaults to false.
xen/arch/x86/dom0_build.c +0 -8
index 27315d5..93e5531 100644
@@ -588,14 +588,6 @@ int __init construct_dom0(struct domain *d, const module_t *image,
 
     process_pending_softirqs();
 
-#ifdef CONFIG_SHADOW_PAGING
-    if ( opt_dom0_shadow && !dom0_pvh )
-    {
-        opt_dom0_shadow = false;
-        printk(XENLOG_WARNING "Shadow Dom0 requires PVH. Option ignored.\n");
-    }
-#endif
-
     if ( is_hvm_domain(d) )
         rc = dom0_construct_pvh(d, image, image_headroom, initrd, cmdline);
     else if ( is_pv_domain(d) )
xen/arch/x86/pv/dom0_build.c +9 -0
index 064a10e..4a1526a 100644
@@ -906,6 +906,15 @@ int __init dom0_construct_pv(struct domain *d,
     if ( d->domain_id == hardware_domid )
         iommu_hwdom_init(d);
 
+    /* Activate shadow mode, if requested.  Reuse the pv_l1tf tasklet. */
+#ifdef CONFIG_SHADOW_PAGING
+    if ( opt_dom0_shadow )
+    {
+        printk("Switching dom0 to using shadow paging\n");
+        tasklet_schedule(&d->arch.paging.shadow.pv_l1tf_tasklet);
+    }
+#endif
+
     v->is_initialised = 1;
     clear_bit(_VPF_down, &v->pause_flags);
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] x86/boot: Wire up dom0=shadow for PV dom0

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 20.05.19 at 12:18, <[email protected]> wrote:
docs/misc/xen-command-line.pandoc +0 -0
@@ -675,12 +675,16 @@ Controls for how dom0 is constructed on x86 systems.
         selected mode.
     *   For a PVH dom0, the hardware must have VT-x/SVM extensions 

available.

docs/misc/xen-command-line.pandoc +0 -2
-*   The `shadow` boolean is only applicable when dom0 is constructed as a PVH
-    guest, and controls whether dom0 uses hardware assisted paging, or shadow

docs/misc/xen-command-line.pandoc Controls for how dom0 is constructed on x86 systems. · line 684

Quoted 10 lines
docs/misc/xen-command-line.pandoc +6 -3
-    paging.  The default is HAP when available, and shadow otherwise.
+*   The `shadow` boolean allows dom0 to be explicitly constructed using shadow
+    paging.  This option is unavailable when `CONFIG_SHADOW_PAGING` is
+    disabled.
 
-    This option is unavailable when `CONFIG_SHADOW_PAGING` is disabled.  Such
-    builds of Xen require HAP-capable hardware to use a PVH dom0.
+    For PVH, dom0 defaults to using HAP on capable hardware, and falls back to
+    shadow paging otherwise.  A PVH dom0 cannot be used if Xen is compiled
+    without paging support, and the hardware lacks HAP support.

I think you want to add another "shadow" ahead of "paging" here. Other than this

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

PATCH 4/4 x86/boot: Link opt_dom0_verbose to CONFIG_VERBOSE_DEBUG

In reply to Andrew Cooper

We currently have an asymmetric setup where CONFIG_VERBOSE_DEBUG controls extra diagnostics for a PV dom0, and opt_dom0_verbose controls extra diagnostics for a PVH dom0.

Default opt_dom0_verbose to CONFIG_VERBOSE_DEBUG and use opt_dom0_verbose consistently.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 docs/misc/xen-command-line.pandoc | 3 ++-
 xen/arch/x86/dom0_build.c         | 2 +-
 xen/arch/x86/pv/dom0_build.c      | 7 ++++---
 3 files changed, 7 insertions(+), 5 deletions(-)
docs/misc/xen-command-line.pandoc +2 -1
index e6d241e..51dc8ae 100644
@@ -687,7 +687,8 @@ Controls for how dom0 is constructed on x86 systems.
     guests do no require any paging support by default.
 
 *   The `verbose` boolean is intended for diagnostics, and prints out extra
-    information during the dom0 build.  It defaults to false.
+    information during the dom0 build.  It defaults to the compile time choice
+    of `CONFIG_VERBOSE_DEBUG`.
 
 ### dom0-iommu
     = List of [ passthrough=<bool>, strict=<bool>, map-inclusive=<bool>,
xen/arch/x86/dom0_build.c +1 -1
index 93e5531..9b06363 100644
@@ -281,7 +281,7 @@ struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
 bool __initdata opt_dom0_shadow;
 #endif
 bool __initdata opt_dom0_pvh = !IS_ENABLED(CONFIG_PV);
-bool __initdata opt_dom0_verbose;
+bool __initdata opt_dom0_verbose = IS_ENABLED(CONFIG_VERBOSE_DEBUG);
 
 static int __init parse_dom0_param(const char *s)
 {
xen/arch/x86/pv/dom0_build.c +4 -3
index 4a1526a..903611f 100644
@@ -345,9 +345,10 @@ int __init dom0_construct_pv(struct domain *d,
 
     if ( (rc = elf_init(&elf, image_start, image_len)) != 0 )
         return rc;
-#ifdef CONFIG_VERBOSE_DEBUG
-    elf_set_verbose(&elf);
-#endif
+
+    if ( opt_dom0_verbose )
+        elf_set_verbose(&elf);
+
     elf_parse_binary(&elf);
     if ( (rc = elf_xen_parse(&elf, &parms)) != 0 )
         goto out;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] x86/boot: Link opt_dom0_verbose to CONFIG_VERBOSE_DEBUG

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 20.05.19 at 12:18, <[email protected]> wrote:

We currently have an asymmetric setup where CONFIG_VERBOSE_DEBUG controls extra diagnostics for a PV dom0, and opt_dom0_verbose controls extra diagnostics for a PVH dom0.

Default opt_dom0_verbose to CONFIG_VERBOSE_DEBUG and use opt_dom0_verbose consistently.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel