From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com,
ian.campbell@citrix.com, wei.liu2@citrix.com
Cc: jgross@suse.com, Boris Ostrovsky <boris.ostrovsky@oracle.com>,
roger.pau@citrix.com, xen-devel@lists.xen.org
Subject: [PATCH v2 2/2] libxc: Defer initialization of start_page for HVM guests
Date: Tue, 5 Jan 2016 17:26:10 -0500 [thread overview]
Message-ID: <1452032770-5642-3-git-send-email-boris.ostrovsky@oracle.com> (raw)
In-Reply-To: <1452032770-5642-1-git-send-email-boris.ostrovsky@oracle.com>
With commit 8c45adec18e0 ("libxc: create unmapped initrd in domain
builder if supported") location of ramdisk may not be available to
HVMlite guests by the time alloc_magic_pages_hvm() is invoked if the
guest supports unmapped initrd.
So let's move ramdisk info initialization (along with a few other
operations that are not directly related to allocating magic/special
pages) from alloc_magic_pages_hvm() to bootlate_hvm().
Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
tools/libxc/xc_dom_x86.c | 117 ++++++++++++++++++++++++++-------------------
1 files changed, 68 insertions(+), 49 deletions(-)
diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c
index b696149..e8c947f 100644
--- a/tools/libxc/xc_dom_x86.c
+++ b/tools/libxc/xc_dom_x86.c
@@ -586,23 +586,12 @@ static void build_hvm_info(void *hvm_info_page, struct xc_dom_image *dom)
static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
{
unsigned long i;
- void *hvm_info_page;
uint32_t *ident_pt, domid = dom->guest_domid;
int rc;
xen_pfn_t special_array[X86_HVM_NR_SPECIAL_PAGES];
xen_pfn_t ioreq_server_array[NR_IOREQ_SERVER_PAGES];
xc_interface *xch = dom->xch;
- if ( dom->device_model )
- {
- if ( (hvm_info_page = xc_map_foreign_range(
- xch, domid, PAGE_SIZE, PROT_READ | PROT_WRITE,
- HVM_INFO_PFN)) == NULL )
- goto error_out;
- build_hvm_info(hvm_info_page, dom);
- munmap(hvm_info_page, PAGE_SIZE);
- }
-
/* Allocate and clear special pages. */
for ( i = 0; i < X86_HVM_NR_SPECIAL_PAGES; i++ )
special_array[i] = special_pfn(i);
@@ -637,12 +626,9 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
if ( !dom->device_model )
{
struct xc_dom_seg seg;
- struct hvm_start_info *start_info;
- char *cmdline;
struct hvm_modlist_entry *modlist;
- void *start_page;
size_t cmdline_size = 0;
- size_t start_info_size = sizeof(*start_info);
+ size_t start_info_size = sizeof(struct hvm_start_info);
if ( dom->cmdline )
{
@@ -666,39 +652,6 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
goto out;
}
- start_page = xc_map_foreign_range(xch, domid, start_info_size,
- PROT_READ | PROT_WRITE,
- seg.pfn);
- if ( start_page == NULL )
- {
- DOMPRINTF("Unable to map HVM start info page");
- goto error_out;
- }
-
- start_info = start_page;
- cmdline = start_page + sizeof(*start_info);
- modlist = start_page + sizeof(*start_info) + cmdline_size;
-
- if ( dom->cmdline )
- {
- strcpy(cmdline, dom->cmdline);
- start_info->cmdline_paddr = (seg.pfn << PAGE_SHIFT) +
- ((uintptr_t)cmdline - (uintptr_t)start_info);
- }
-
- if ( dom->ramdisk_blob )
- {
- modlist[0].paddr = dom->ramdisk_seg.vstart - dom->parms.virt_base;
- modlist[0].size = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart;
- start_info->modlist_paddr = (seg.pfn << PAGE_SHIFT) +
- ((uintptr_t)modlist - (uintptr_t)start_info);
- start_info->nr_modules = 1;
- }
-
- start_info->magic = HVM_START_MAGIC_VALUE;
-
- munmap(start_page, start_info_size);
-
dom->start_info_pfn = seg.pfn;
}
else
@@ -1788,7 +1741,73 @@ static int alloc_pgtables_hvm(struct xc_dom_image *dom)
static int bootlate_hvm(struct xc_dom_image *dom)
{
- DOMPRINTF("%s: doing nothing", __func__);
+ uint32_t domid = dom->guest_domid;
+ xc_interface *xch = dom->xch;
+
+ if ( !dom->device_model )
+ {
+ struct hvm_start_info *start_info;
+ size_t start_info_size = sizeof(*start_info);
+ void *start_page;
+ struct hvm_modlist_entry *modlist;
+ size_t cmdline_size = 0;
+
+ if ( dom->cmdline )
+ {
+ cmdline_size = ROUNDUP(strlen(dom->cmdline) + 1, 8);
+ start_info_size += cmdline_size;
+ }
+ if ( dom->ramdisk_blob )
+ start_info_size += sizeof(*modlist); /* Limited to one module. */
+
+ start_page = xc_map_foreign_range(xch, domid, start_info_size,
+ PROT_READ | PROT_WRITE,
+ dom->start_info_pfn);
+ if ( start_page == NULL )
+ {
+ DOMPRINTF("Unable to map HVM start info page");
+ return -1;
+ }
+
+ start_info = start_page;
+
+ if ( dom->cmdline )
+ {
+ char *cmdline = start_page + sizeof(*start_info);
+
+ /* We've already tested cmdline's size in alloc_magic_pages_hvm() */
+ strcpy(cmdline, dom->cmdline);
+ start_info->cmdline_paddr = (dom->start_info_pfn << PAGE_SHIFT) +
+ ((uintptr_t)cmdline - (uintptr_t)start_info);
+ }
+
+ if ( dom->ramdisk_blob )
+ {
+ modlist = start_page + sizeof(*start_info) + cmdline_size;
+
+ modlist[0].paddr = dom->ramdisk_seg.vstart - dom->parms.virt_base;
+ modlist[0].size = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart;
+ start_info->modlist_paddr = (dom->start_info_pfn << PAGE_SHIFT) +
+ ((uintptr_t)modlist - (uintptr_t)start_info);
+ start_info->nr_modules = 1;
+ }
+
+ start_info->magic = HVM_START_MAGIC_VALUE;
+
+ munmap(start_page, start_info_size);
+ }
+ else
+ {
+ void *hvm_info_page;
+
+ if ( (hvm_info_page = xc_map_foreign_range(
+ xch, domid, PAGE_SIZE, PROT_READ | PROT_WRITE,
+ HVM_INFO_PFN)) == NULL )
+ return -1;
+ build_hvm_info(hvm_info_page, dom);
+ munmap(hvm_info_page, PAGE_SIZE);
+ }
+
return 0;
}
--
1.7.1
next prev parent reply other threads:[~2016-01-05 22:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-05 22:26 [PATCH v2 0/2] HVMlite start_info initialization fixes Boris Ostrovsky
2016-01-05 22:26 ` [PATCH v2 1/2] libxc: Don't write terminating NULL character to command string Boris Ostrovsky
2016-01-05 22:42 ` Andrew Cooper
2016-01-05 22:59 ` Boris Ostrovsky
2016-01-05 23:01 ` Andrew Cooper
2016-01-06 16:44 ` Ian Campbell
2016-01-06 16:51 ` Andrew Cooper
2016-01-06 17:06 ` Ian Campbell
2016-01-05 22:26 ` Boris Ostrovsky [this message]
2016-01-06 15:58 ` [PATCH v2 2/2] libxc: Defer initialization of start_page for HVM guests Wei Liu
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=1452032770-5642-3-git-send-email-boris.ostrovsky@oracle.com \
--to=boris.ostrovsky@oracle.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jgross@suse.com \
--cc=roger.pau@citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.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).