From: David Woodhouse <dwmw2@infradead.org>
To: xen-devel@lists.xenproject.org
Cc: "Stefano Stabellini" <sstabellini@kernel.org>,
"Julien Grall" <julien@xen.org>, "Wei Liu" <wl@xen.org>,
"Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com>,
"George Dunlap" <George.Dunlap@eu.citrix.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Varad Gautam" <vrd@amazon.de>,
"Ian Jackson" <ian.jackson@eu.citrix.com>,
"Hongyan Xia" <hongyxia@amazon.com>,
"Paul Durrant" <pdurrant@amazon.co.uk>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [Xen-devel] [PATCH 8/8] x86/setup: lift dom0 creation out into create_dom0() function
Date: Sat, 1 Feb 2020 00:33:03 +0000 [thread overview]
Message-ID: <20200201003303.2363081-8-dwmw2@infradead.org> (raw)
In-Reply-To: <8a95f787ca93b23ee8d8c0b55fcc63d22a75c5f3.camel@infradead.org>
From: David Woodhouse <dwmw@amazon.co.uk>
The creation of dom0 can be relatively self-contained. Shift it into
a separate function and simplify __start_xen() a little bit.
This is a cleanup in its own right, but will be even more desireable
when live update provides an alternative path through __start_xen()
that doesn't involve creating a new dom0 at all.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
xen/arch/x86/setup.c | 169 +++++++++++++++++++++++--------------------
1 file changed, 92 insertions(+), 77 deletions(-)
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 10209e6bfb..9d86722ecd 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -678,6 +678,92 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li
return n;
}
+static struct domain * __init create_dom0(const module_t *image,
+ unsigned long headroom,
+ module_t *initrd, char *kextra,
+ char *loader)
+{
+ struct xen_domctl_createdomain dom0_cfg = {
+ .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0,
+ .max_evtchn_port = -1,
+ .max_grant_frames = -1,
+ .max_maptrack_frames = -1,
+ };
+ struct domain *d;
+ char *cmdline;
+
+ if ( opt_dom0_pvh )
+ {
+ dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm |
+ ((hvm_hap_supported() && !opt_dom0_shadow) ?
+ XEN_DOMCTL_CDF_hap : 0));
+
+ dom0_cfg.arch.emulation_flags |=
+ XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI;
+ }
+ dom0_cfg.max_vcpus = dom0_max_vcpus();
+
+ if ( iommu_enabled )
+ dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;
+
+ /* Create initial domain 0. */
+ d = domain_create(get_initial_domain_id(), &dom0_cfg, !pv_shim);
+ if ( IS_ERR(d) || (alloc_dom0_vcpu0(d) == NULL) )
+ panic("Error creating domain 0\n");
+
+ /* Grab the DOM0 command line. */
+ cmdline = (char *)(image->string ? __va(image->string) : NULL);
+ if ( (cmdline != NULL) || (kextra != NULL) )
+ {
+ static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE];
+
+ cmdline = cmdline_cook(cmdline, loader);
+ safe_strcpy(dom0_cmdline, cmdline);
+
+ if ( kextra != NULL )
+ /* kextra always includes exactly one leading space. */
+ safe_strcat(dom0_cmdline, kextra);
+
+ /* Append any extra parameters. */
+ if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") )
+ safe_strcat(dom0_cmdline, " noapic");
+ if ( (strlen(acpi_param) == 0) && acpi_disabled )
+ {
+ printk("ACPI is disabled, notifying Domain 0 (acpi=off)\n");
+ safe_strcpy(acpi_param, "off");
+ }
+ if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") )
+ {
+ safe_strcat(dom0_cmdline, " acpi=");
+ safe_strcat(dom0_cmdline, acpi_param);
+ }
+
+ cmdline = dom0_cmdline;
+ }
+
+ /*
+ * Temporarily clear SMAP in CR4 to allow user-accesses in construct_dom0().
+ * This saves a large number of corner cases interactions with
+ * copy_from_user().
+ */
+ if ( cpu_has_smap )
+ {
+ cr4_pv32_mask &= ~X86_CR4_SMAP;
+ write_cr4(read_cr4() & ~X86_CR4_SMAP);
+ }
+
+ if ( construct_dom0(d, image, headroom, initrd, cmdline) != 0 )
+ panic("Could not construct domain 0\n");
+
+ if ( cpu_has_smap )
+ {
+ write_cr4(read_cr4() | X86_CR4_SMAP);
+ cr4_pv32_mask |= X86_CR4_SMAP;
+ }
+
+ return d;
+}
+
/* How much of the directmap is prebuilt at compile time. */
#define PREBUILT_MAP_LIMIT (1 << L2_PAGETABLE_SHIFT)
@@ -697,12 +783,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)
.parity = 'n',
.stop_bits = 1
};
- struct xen_domctl_createdomain dom0_cfg = {
- .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0,
- .max_evtchn_port = -1,
- .max_grant_frames = -1,
- .max_maptrack_frames = -1,
- };
const char *hypervisor_name;
/* Critical region without IDT or TSS. Any fault is deadly! */
@@ -1740,58 +1820,13 @@ void __init noreturn __start_xen(unsigned long mbi_p)
init_guest_cpuid();
init_guest_msr_policy();
- if ( opt_dom0_pvh )
- {
- dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm |
- ((hvm_hap_supported() && !opt_dom0_shadow) ?
- XEN_DOMCTL_CDF_hap : 0));
-
- dom0_cfg.arch.emulation_flags |=
- XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI;
- }
- dom0_cfg.max_vcpus = dom0_max_vcpus();
-
- if ( iommu_enabled )
- dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;
-
- /* Create initial domain 0. */
- dom0 = domain_create(get_initial_domain_id(), &dom0_cfg, !pv_shim);
- if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
- panic("Error creating domain 0\n");
-
- /* Grab the DOM0 command line. */
- cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
- if ( (cmdline != NULL) || (kextra != NULL) )
- {
- static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE];
-
- cmdline = cmdline_cook(cmdline, loader);
- safe_strcpy(dom0_cmdline, cmdline);
-
- if ( kextra != NULL )
- /* kextra always includes exactly one leading space. */
- safe_strcat(dom0_cmdline, kextra);
-
- /* Append any extra parameters. */
- if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") )
- safe_strcat(dom0_cmdline, " noapic");
- if ( (strlen(acpi_param) == 0) && acpi_disabled )
- {
- printk("ACPI is disabled, notifying Domain 0 (acpi=off)\n");
- safe_strcpy(acpi_param, "off");
- }
- if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") )
- {
- safe_strcat(dom0_cmdline, " acpi=");
- safe_strcat(dom0_cmdline, acpi_param);
- }
-
- cmdline = dom0_cmdline;
- }
-
if ( xen_cpuidle )
xen_processor_pmbits |= XEN_PROCESSOR_PM_CX;
+ printk("%sNX (Execute Disable) protection %sactive\n",
+ cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ",
+ cpu_has_nx ? "" : "not ");
+
initrdidx = find_first_bit(module_map, mbi->mods_count);
if ( initrdidx < mbi->mods_count )
initrd = mod + initrdidx;
@@ -1801,34 +1836,14 @@ void __init noreturn __start_xen(unsigned long mbi_p)
"Multiple initrd candidates, picking module #%u\n",
initrdidx);
- /*
- * Temporarily clear SMAP in CR4 to allow user-accesses in construct_dom0().
- * This saves a large number of corner cases interactions with
- * copy_from_user().
- */
- if ( cpu_has_smap )
- {
- cr4_pv32_mask &= ~X86_CR4_SMAP;
- write_cr4(read_cr4() & ~X86_CR4_SMAP);
- }
-
- printk("%sNX (Execute Disable) protection %sactive\n",
- cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ",
- cpu_has_nx ? "" : "not ");
-
/*
* 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.
*/
- if ( construct_dom0(dom0, mod, modules_headroom, initrd, cmdline) != 0 )
+ dom0 = create_dom0(mod, modules_headroom, initrd, kextra, loader);
+ if ( dom0 == NULL )
panic("Could not set up DOM0 guest OS\n");
- if ( cpu_has_smap )
- {
- write_cr4(read_cr4() | X86_CR4_SMAP);
- cr4_pv32_mask |= X86_CR4_SMAP;
- }
-
heap_init_late();
init_trace_bufs();
--
2.21.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-02-01 0:33 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-01 0:32 [Xen-devel] [PATCH 0/8] Early cleanups and bug fixes in preparation for live update David Woodhouse
2020-02-01 0:32 ` [Xen-devel] [PATCH 1/8] x86/smp: reset x2apic_enabled in smp_send_stop() David Woodhouse
2020-02-03 16:18 ` Roger Pau Monné
2020-02-01 0:32 ` [Xen-devel] [PATCH 2/8] x86/setup: Fix badpage= handling for memory above HYPERVISOR_VIRT_END David Woodhouse
2020-02-03 10:57 ` Julien Grall
2020-02-20 15:38 ` Jan Beulich
2020-03-06 22:52 ` Julien Grall
2020-02-01 0:32 ` [Xen-devel] [PATCH 3/8] x86/setup: Don't skip 2MiB underneath relocated Xen image David Woodhouse
2020-02-01 0:32 ` [Xen-devel] [PATCH 4/8] xen/vmap: allow vm_init_type to be called during early_boot David Woodhouse
2020-02-13 10:36 ` Julien Grall
2020-02-21 16:42 ` Jan Beulich
2020-02-01 0:33 ` [Xen-devel] [PATCH 5/8] xen/vmap: allow vmap() to be called during early boot David Woodhouse
2020-02-03 14:00 ` Julien Grall
2020-02-03 16:37 ` David Woodhouse
2020-02-04 11:00 ` George Dunlap
2020-02-04 11:06 ` David Woodhouse
2020-02-04 11:18 ` David Woodhouse
2020-02-09 18:19 ` Julien Grall
2020-02-21 16:46 ` Jan Beulich
2020-02-01 0:33 ` [Xen-devel] [PATCH 6/8] x86/setup: move vm_init() before end_boot_allocator() David Woodhouse
2020-02-03 11:10 ` Xia, Hongyan
2020-02-03 14:03 ` David Woodhouse
2020-02-21 16:48 ` Jan Beulich
2020-02-01 0:33 ` [Xen-devel] [PATCH 7/8] x86/setup: simplify handling of initrdidx when no initrd present David Woodhouse
2020-02-13 10:47 ` Julien Grall
2020-02-21 16:59 ` Jan Beulich
2020-02-24 13:31 ` Julien Grall
2020-02-25 12:34 ` Jan Beulich
2020-02-26 7:13 ` Julien Grall
2020-02-26 8:37 ` Jan Beulich
2020-02-01 0:33 ` David Woodhouse [this message]
2020-02-03 14:28 ` [Xen-devel] [PATCH 8/8] x86/setup: lift dom0 creation out into create_dom0() function Julien Grall
2020-02-03 15:03 ` David Woodhouse
2020-02-21 17:06 ` Jan Beulich
2020-03-17 23:45 ` David Woodhouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200201003303.2363081-8-dwmw2@infradead.org \
--to=dwmw2@infradead.org \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=hongyxia@amazon.com \
--cc=ian.jackson@eu.citrix.com \
--cc=julien@xen.org \
--cc=konrad.wilk@oracle.com \
--cc=pdurrant@amazon.co.uk \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=vrd@amazon.de \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).