From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
boris.ostrovsky@oracle.com,
Roger Pau Monne <roger.pau@citrix.com>,
Jan Beulich <jbeulich@suse.com>,
konrad.wilk@oracle.com
Subject: [PATCH v5 6/9] xen/x86: parse Dom0 kernel for PVHv2
Date: Thu, 19 Jan 2017 17:29:38 +0000 [thread overview]
Message-ID: <20170119172941.65642-7-roger.pau@citrix.com> (raw)
In-Reply-To: <20170119172941.65642-1-roger.pau@citrix.com>
Introduce a helper to parse the Dom0 kernel.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
Changes since v4:
- s/hvm/pvh.
- Use hvm_copy_to_guest_phys_vcpu.
Changes since v3:
- Change one error message.
- Indent "out" label by one space.
- Introduce hvm_copy_to_phys and slightly simplify the code in hvm_load_kernel.
Changes since v2:
- Remove debug messages.
- Don't hardcode the number of modules to 1.
---
xen/arch/x86/domain_build.c | 143 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 143 insertions(+)
diff --git a/xen/arch/x86/domain_build.c b/xen/arch/x86/domain_build.c
index fbce1c2..4f5f712 100644
--- a/xen/arch/x86/domain_build.c
+++ b/xen/arch/x86/domain_build.c
@@ -39,6 +39,7 @@
#include <asm/hpet.h>
#include <public/version.h>
+#include <public/arch-x86/hvm/start_info.h>
static long __initdata dom0_nrpages;
static long __initdata dom0_min_nrpages;
@@ -1959,12 +1960,146 @@ static int __init pvh_setup_p2m(struct domain *d)
#undef MB1_PAGES
}
+static int __init pvh_load_kernel(struct domain *d, const module_t *image,
+ unsigned long image_headroom,
+ module_t *initrd, char *image_base,
+ char *cmdline, paddr_t *entry,
+ paddr_t *start_info_addr)
+{
+ char *image_start = image_base + image_headroom;
+ unsigned long image_len = image->mod_end;
+ struct elf_binary elf;
+ struct elf_dom_parms parms;
+ paddr_t last_addr;
+ struct hvm_start_info start_info;
+ struct hvm_modlist_entry mod = { 0 };
+ struct vcpu *saved_current, *v = d->vcpu[0];
+ int rc;
+
+ if ( (rc = bzimage_parse(image_base, &image_start, &image_len)) != 0 )
+ {
+ printk("Error trying to detect bz compressed kernel\n");
+ return rc;
+ }
+
+ if ( (rc = elf_init(&elf, image_start, image_len)) != 0 )
+ {
+ printk("Unable to init ELF\n");
+ return rc;
+ }
+#ifdef VERBOSE
+ elf_set_verbose(&elf);
+#endif
+ elf_parse_binary(&elf);
+ if ( (rc = elf_xen_parse(&elf, &parms)) != 0 )
+ {
+ printk("Unable to parse kernel for ELFNOTES\n");
+ return rc;
+ }
+
+ if ( parms.phys_entry == UNSET_ADDR32 ) {
+ printk("Unable to find XEN_ELFNOTE_PHYS32_ENTRY address\n");
+ return -EINVAL;
+ }
+
+ printk("OS: %s version: %s loader: %s bitness: %s\n", parms.guest_os,
+ parms.guest_ver, parms.loader,
+ elf_64bit(&elf) ? "64-bit" : "32-bit");
+
+ /* 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;
+
+ /*
+ * NB: we need to set vCPU 0 of Dom0 as the current vCPU (instead of the
+ * idle one) because elf_load_binary calls raw_{copy_to/clear}_guest, and
+ * the target domain is not passed anywhere. This is very similar to what
+ * is done during classic PV Dom0 creation, where Xen switches to the Dom0
+ * page tables. We also cannot pass a struct domain or vcpu to
+ * elf_load_binary, since the interface is shared with the toolstack, and
+ * it doesn't have any notion of a domain or vcpu struct.
+ */
+ saved_current = current;
+ set_current(v);
+ rc = elf_load_binary(&elf);
+ set_current(saved_current);
+ if ( rc < 0 )
+ {
+ printk("Failed to load kernel: %d\n", rc);
+ printk("Xen dom0 kernel broken ELF: %s\n", elf_check_broken(&elf));
+ return rc;
+ }
+
+ last_addr = ROUNDUP(parms.virt_kend - parms.virt_base, PAGE_SIZE);
+
+ if ( initrd != NULL )
+ {
+ rc = hvm_copy_to_guest_phys_vcpu(last_addr,
+ mfn_to_virt(initrd->mod_start),
+ initrd->mod_end, v);
+ if ( rc )
+ {
+ printk("Unable to copy initrd to guest\n");
+ return rc;
+ }
+
+ mod.paddr = last_addr;
+ mod.size = initrd->mod_end;
+ last_addr += ROUNDUP(initrd->mod_end, PAGE_SIZE);
+ }
+
+ /* Free temporary buffers. */
+ discard_initial_images();
+
+ memset(&start_info, 0, sizeof(start_info));
+ if ( cmdline != NULL )
+ {
+ rc = hvm_copy_to_guest_phys_vcpu(last_addr, cmdline,
+ strlen(cmdline) + 1, v);
+ if ( rc )
+ {
+ printk("Unable to copy guest command line\n");
+ return rc;
+ }
+ start_info.cmdline_paddr = last_addr;
+ last_addr += ROUNDUP(strlen(cmdline) + 1, 8);
+ }
+ if ( initrd != NULL )
+ {
+ rc = hvm_copy_to_guest_phys_vcpu(last_addr, &mod, sizeof(mod), v);
+ if ( rc )
+ {
+ printk("Unable to copy guest modules\n");
+ return rc;
+ }
+ start_info.modlist_paddr = last_addr;
+ start_info.nr_modules = 1;
+ last_addr += sizeof(mod);
+ }
+
+ start_info.magic = XEN_HVM_START_MAGIC_VALUE;
+ start_info.flags = SIF_PRIVILEGED | SIF_INITDOMAIN;
+ rc = hvm_copy_to_guest_phys_vcpu(last_addr, &start_info,
+ sizeof(start_info), v);
+ if ( rc )
+ {
+ printk("Unable to copy start info to guest\n");
+ return rc;
+ }
+
+ *entry = parms.phys_entry;
+ *start_info_addr = last_addr;
+
+ return 0;
+}
+
static int __init construct_dom0_pvh(struct domain *d, const module_t *image,
unsigned long image_headroom,
module_t *initrd,
void *(*bootstrap_map)(const module_t *),
char *cmdline)
{
+ paddr_t entry, start_info;
int rc;
printk("** Building a PVH Dom0 **\n");
@@ -1978,6 +2113,14 @@ static int __init construct_dom0_pvh(struct domain *d, const module_t *image,
return rc;
}
+ rc = pvh_load_kernel(d, image, image_headroom, initrd, bootstrap_map(image),
+ cmdline, &entry, &start_info);
+ if ( rc )
+ {
+ printk("Failed to load Dom0 kernel\n");
+ return rc;
+ }
+
return 0;
}
--
2.10.1 (Apple Git-78)
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-01-19 17:30 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-19 17:29 [PATCH v5 0/9] Initial PVHv2 Dom0 support Roger Pau Monne
2017-01-19 17:29 ` [PATCH v5 1/9] xen/x86: remove XENFEAT_hvm_pirqs for PVHv2 guests Roger Pau Monne
2017-01-20 18:41 ` Andrew Cooper
2017-01-23 12:28 ` Roger Pau Monne
2017-01-19 17:29 ` [PATCH v5 2/9] x86/iommu: add IOMMU entries for p2m_mmio_direct pages Roger Pau Monne
2017-01-20 6:41 ` Tian, Kevin
2017-01-20 10:28 ` Roger Pau Monne
2017-01-20 18:44 ` Andrew Cooper
2017-01-22 4:45 ` Tian, Kevin
2017-01-19 17:29 ` [PATCH v5 3/9] xen/x86: split Dom0 build into PV and PVHv2 Roger Pau Monne
2017-01-20 19:03 ` Andrew Cooper
2017-01-23 12:58 ` Roger Pau Monne
2017-01-23 12:59 ` Andrew Cooper
2017-01-20 19:13 ` Boris Ostrovsky
2017-01-20 19:27 ` Andrew Cooper
2017-01-26 11:43 ` Jan Beulich
2017-01-26 16:36 ` Roger Pau Monne
2017-01-19 17:29 ` [PATCH v5 4/9] xen/x86: populate PVHv2 Dom0 physical memory map Roger Pau Monne
2017-01-20 19:41 ` Andrew Cooper
2017-01-23 11:23 ` Jan Beulich
2017-01-23 14:11 ` Boris Ostrovsky
2017-01-23 14:43 ` Roger Pau Monne
2017-01-26 12:41 ` Jan Beulich
2017-01-27 11:14 ` Tim Deegan
2017-01-27 12:37 ` Roger Pau Monne
2017-01-27 12:51 ` Andrew Cooper
2017-01-27 13:20 ` Tim Deegan
2017-01-27 13:46 ` Andrew Cooper
2017-01-27 14:01 ` Tim Deegan
2017-01-27 14:35 ` Andrew Cooper
2017-01-27 19:43 ` Tim Deegan
2017-01-30 10:43 ` Jan Beulich
2017-01-30 11:06 ` Andrew Cooper
2017-01-27 16:40 ` Jan Beulich
2017-01-27 18:06 ` Andrew Cooper
2017-02-03 13:57 ` Jan Beulich
2017-01-27 19:48 ` Tim Deegan
2017-02-02 15:38 ` Jan Beulich
2017-01-27 12:23 ` Roger Pau Monne
2017-01-27 15:11 ` Jan Beulich
2017-01-27 16:04 ` Roger Pau Monne
2017-01-27 16:29 ` Jan Beulich
2017-01-19 17:29 ` [PATCH v5 5/9] x86/hvm: add vcpu parameter to guest memory copy function Roger Pau Monne
2017-01-20 19:45 ` Andrew Cooper
2017-01-23 13:50 ` Roger Pau Monne
2017-01-26 12:51 ` Jan Beulich
2017-01-26 13:33 ` Jan Beulich
2017-01-27 14:55 ` Roger Pau Monne
2017-01-19 17:29 ` Roger Pau Monne [this message]
2017-01-26 13:37 ` [PATCH v5 6/9] xen/x86: parse Dom0 kernel for PVHv2 Jan Beulich
2017-01-27 17:22 ` Roger Pau Monne
2017-01-27 17:28 ` Roger Pau Monne
2017-01-30 10:20 ` Jan Beulich
2017-01-27 18:03 ` Roger Pau Monne
2017-01-30 10:14 ` Jan Beulich
2017-01-19 17:29 ` [PATCH v5 7/9] x86/PVHv2: fix dom0_max_vcpus so it's capped to 128 for PVHv2 Dom0 Roger Pau Monne
2017-01-19 17:32 ` Andrew Cooper
2017-01-26 13:39 ` Jan Beulich
2017-01-19 17:29 ` [PATCH v5 8/9] xen/x86: Setup PVHv2 Dom0 CPUs Roger Pau Monne
2017-01-26 13:46 ` Jan Beulich
2017-02-08 12:48 ` Roger Pau Monne
2017-02-08 13:02 ` Jan Beulich
2017-01-19 17:29 ` [PATCH v5 9/9] xen/x86: setup PVHv2 Dom0 ACPI tables Roger Pau Monne
2017-01-26 14:16 ` Jan Beulich
2017-02-08 15:10 ` Roger Pau Monne
2017-02-08 15:50 ` Jan Beulich
2017-02-08 15:58 ` Roger Pau Monne
2017-02-08 16:03 ` Jan Beulich
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=20170119172941.65642-7-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jbeulich@suse.com \
--cc=konrad.wilk@oracle.com \
--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).