From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Roger Pau Monne <roger.pau@citrix.com>
Cc: xen-devel@lists.xenproject.org, boris.ostrovsky@oracle.com,
Jan Beulich <jbeulich@suse.com>,
Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: [PATCH v3.1 13/15] xen/x86: parse Dom0 kernel for PVHv2
Date: Fri, 11 Nov 2016 15:30:17 -0500 [thread overview]
Message-ID: <20161111203017.GG17979@char.us.oracle.com> (raw)
In-Reply-To: <1477731601-10926-14-git-send-email-roger.pau@citrix.com>
On Sat, Oct 29, 2016 at 10:59:59AM +0200, Roger Pau Monne wrote:
> 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 v2:
> - Remove debug messages.
> - Don't hardcode the number of modules to 1.
> ---
> xen/arch/x86/domain_build.c | 138 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 138 insertions(+)
>
> diff --git a/xen/arch/x86/domain_build.c b/xen/arch/x86/domain_build.c
> index ec1ac89..168be62 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;
> @@ -1895,12 +1896,141 @@ static int __init hvm_setup_p2m(struct domain *d)
> return 0;
> }
>
> +static int __init hvm_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;
> + 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");
Perhaps s/ELFNOTES/PT_NOTEs/?
> + return rc;
> + }
> +
> + if ( parms.phys_entry == UNSET_ADDR32 ) {
> + printk("Unable to find kernel entry point, aborting\n");
Perhaps: Unable to find XEN_ELFNOTE_PHYS32_ENTRY point.
> + return -EINVAL;
> + }
> +
> + printk("OS: %s version: %s loader: %s bitness: %s\n", parms.guest_os,
> + parms.guest_ver, parms.loader,
Hm, I don't know if XEN_ELFNOTE_GUEST_VERSION or XEN_ELFNOTE_GUEST_OS
are mandated.
Perhaps you should do memset(¶ms) before you pass it to elf_xen_parse?
> + 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;
> +
> + saved_current = current;
> + set_current(v);
> +
> + rc = elf_load_binary(&elf);
> + if ( rc < 0 )
> + {
> + printk("Failed to load kernel: %d\n", rc);
> + printk("Xen dom0 kernel broken ELF: %s\n", elf_check_broken(&elf));
> + goto out;
> + }
> +
> + last_addr = ROUNDUP(parms.virt_kend - parms.virt_base, PAGE_SIZE);
> +
> + if ( initrd != NULL )
> + {
> + rc = hvm_copy_to_guest_phys(last_addr, mfn_to_virt(initrd->mod_start),
> + initrd->mod_end);
> + if ( rc != HVMCOPY_okay )
> + {
> + printk("Unable to copy initrd to guest\n");
> + rc = -EFAULT;
> + goto out;
> + }
> +
> + 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(last_addr, cmdline, strlen(cmdline) + 1);
> + if ( rc != HVMCOPY_okay )
> + {
> + printk("Unable to copy guest command line\n");
> + rc = -EFAULT;
> + goto out;
> + }
> + start_info.cmdline_paddr = last_addr;
> + last_addr += ROUNDUP(strlen(cmdline) + 1, 8);
> + }
> + if ( initrd != NULL )
It may be better if this is an array. You can have multiple initrd's.
> + {
> + rc = hvm_copy_to_guest_phys(last_addr, &mod, sizeof(mod));
> + if ( rc != HVMCOPY_okay )
> + {
> + printk("Unable to copy guest modules\n");
> + rc = -EFAULT;
> + goto out;
> + }
> + 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(last_addr, &start_info, sizeof(start_info));
> + if ( rc != HVMCOPY_okay )
> + {
> + printk("Unable to copy start info to guest\n");
> + rc = -EFAULT;
> + goto out;
> + }
> +
> + *entry = parms.phys_entry;
> + *start_info_addr = last_addr;
> + rc = 0;
> +
> +out:
Extra space in front of the label.
> + set_current(saved_current);
> + return rc;
> +}
> +
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-11-11 20:30 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-29 8:59 [PATCH v3.1 00/15] Initial PVHv2 Dom0 support Roger Pau Monne
2016-10-29 8:59 ` [PATCH v3.1 01/15] xen/x86: remove XENFEAT_hvm_pirqs for PVHv2 guests Roger Pau Monne
2016-10-31 16:32 ` Jan Beulich
2016-11-03 12:35 ` Roger Pau Monne
2016-11-03 12:52 ` Jan Beulich
2016-11-03 14:25 ` Konrad Rzeszutek Wilk
2016-11-03 15:05 ` Roger Pau Monne
2016-11-03 14:22 ` Konrad Rzeszutek Wilk
2016-11-03 15:01 ` Roger Pau Monne
2016-11-03 15:43 ` Roger Pau Monne
2016-10-29 8:59 ` [PATCH v3.1 02/15] xen/x86: fix return value of *_set_allocation functions Roger Pau Monne
2016-10-29 22:11 ` Tim Deegan
2016-10-29 8:59 ` [PATCH v3.1 03/15] xen/x86: allow calling {sh/hap}_set_allocation with the idle domain Roger Pau Monne
2016-10-31 16:34 ` Jan Beulich
2016-11-01 10:45 ` Tim Deegan
2016-11-02 17:14 ` Roger Pau Monne
2016-11-03 10:20 ` Roger Pau Monne
2016-11-03 10:33 ` Tim Deegan
2016-11-03 11:31 ` Jan Beulich
2016-10-29 8:59 ` [PATCH v3.1 04/15] xen/x86: assert that local_events_need_delivery is not called by " Roger Pau Monne
2016-10-31 16:37 ` Jan Beulich
2016-10-29 8:59 ` [PATCH v3.1 05/15] x86/paging: introduce paging_set_allocation Roger Pau Monne
2016-10-31 16:42 ` Jan Beulich
2016-11-01 10:29 ` Tim Deegan
2016-10-29 8:59 ` [PATCH v3.1 06/15] xen/x86: split the setup of Dom0 permissions to a function Roger Pau Monne
2016-10-31 16:44 ` Jan Beulich
2016-10-29 8:59 ` [PATCH v3.1 07/15] xen/x86: do the PCI scan unconditionally Roger Pau Monne
2016-10-31 16:47 ` Jan Beulich
2016-11-03 10:58 ` Roger Pau Monne
2016-11-03 11:35 ` Jan Beulich
2016-11-03 11:54 ` Boris Ostrovsky
2016-11-29 12:33 ` Roger Pau Monne
2016-11-29 12:47 ` Jan Beulich
2016-11-29 12:57 ` Roger Pau Monne
2016-11-30 5:53 ` Tian, Kevin
2016-11-30 9:02 ` Jan Beulich
2016-10-29 8:59 ` [PATCH v3.1 08/15] x86/vtd: fix mapping of RMRR regions Roger Pau Monne
2016-11-04 9:16 ` Jan Beulich
2016-11-04 9:45 ` Roger Pau Monne
2016-11-04 10:34 ` Jan Beulich
2016-11-04 12:25 ` Roger Pau Monne
2016-11-04 12:53 ` Jan Beulich
2016-11-04 13:03 ` Roger Pau Monne
2016-11-04 13:16 ` Jan Beulich
2016-11-04 15:33 ` Roger Pau Monne
2016-11-04 16:13 ` Jan Beulich
2016-11-04 16:19 ` Roger Pau Monne
2016-11-04 17:08 ` Jan Beulich
2016-11-04 17:25 ` Roger Pau Monne
2016-11-07 8:36 ` Jan Beulich
2016-10-29 8:59 ` [PATCH v3.1 09/15] xen/x86: allow the emulated APICs to be enabled for the hardware domain Roger Pau Monne
2016-11-04 9:19 ` Jan Beulich
2016-11-04 9:47 ` Roger Pau Monne
2016-11-04 10:21 ` Jan Beulich
2016-11-04 12:09 ` Roger Pau Monne
2016-11-04 12:50 ` Jan Beulich
2016-11-04 13:06 ` Roger Pau Monne
2016-10-29 8:59 ` [PATCH v3.1 10/15] xen/x86: split Dom0 build into PV and PVHv2 Roger Pau Monne
2016-11-11 16:53 ` Jan Beulich
2016-11-16 18:02 ` Roger Pau Monne
2016-11-17 10:49 ` Jan Beulich
2016-11-28 17:49 ` Roger Pau Monne
2016-11-29 9:34 ` Jan Beulich
2016-10-29 8:59 ` [PATCH v3.1 11/15] xen/mm: introduce a function to map large chunks of MMIO Roger Pau Monne
2016-11-11 16:58 ` Jan Beulich
2016-11-29 12:41 ` Roger Pau Monne
2016-11-29 13:00 ` Jan Beulich
2016-11-29 15:32 ` Roger Pau Monne
2016-11-11 20:17 ` Konrad Rzeszutek Wilk
2016-10-29 8:59 ` [PATCH v3.1 12/15] xen/x86: populate PVHv2 Dom0 physical memory map Roger Pau Monne
2016-11-11 17:16 ` Jan Beulich
2016-11-28 11:26 ` Roger Pau Monne
2016-11-28 11:41 ` Jan Beulich
2016-11-28 13:30 ` Roger Pau Monne
2016-11-28 13:49 ` Jan Beulich
2016-11-28 16:02 ` Roger Pau Monne
2016-10-29 8:59 ` [PATCH v3.1 13/15] xen/x86: parse Dom0 kernel for PVHv2 Roger Pau Monne
2016-11-11 20:30 ` Konrad Rzeszutek Wilk [this message]
2016-11-28 12:14 ` Roger Pau Monne
2016-10-29 9:00 ` [PATCH v3.1 14/15] xen/x86: hack to setup PVHv2 Dom0 CPUs Roger Pau Monne
2016-10-29 9:00 ` [PATCH v3.1 15/15] xen/x86: setup PVHv2 Dom0 ACPI tables Roger Pau Monne
2016-11-14 16:15 ` Jan Beulich
2016-11-30 12:40 ` Roger Pau Monne
2016-11-30 14:09 ` Jan Beulich
2016-11-30 14:23 ` Roger Pau Monne
2016-11-30 16:38 ` Jan Beulich
2016-10-31 14:35 ` [PATCH v3.1 00/15] Initial PVHv2 Dom0 support Boris Ostrovsky
2016-10-31 14:43 ` Andrew Cooper
2016-10-31 16:35 ` Roger Pau Monne
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=20161111203017.GG17979@char.us.oracle.com \
--to=konrad.wilk@oracle.com \
--cc=andrew.cooper3@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.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).