From patchwork Wed Jan 6 20:03:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 7970471 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D17D5BEEE5 for ; Wed, 6 Jan 2016 20:06:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEC1920155 for ; Wed, 6 Jan 2016 20:06:04 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A9CC220154 for ; Wed, 6 Jan 2016 20:06:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aGuIU-0005xm-9t; Wed, 06 Jan 2016 20:03:06 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aGuIS-0005xb-B4 for xen-devel@lists.xen.org; Wed, 06 Jan 2016 20:03:04 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id 03/B5-31069-7F27D865; Wed, 06 Jan 2016 20:03:03 +0000 X-Env-Sender: boris.ostrovsky@oracle.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1452110579!6826950!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 48718 invoked from network); 6 Jan 2016 20:03:00 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-7.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 6 Jan 2016 20:03:00 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u06K2upB013305 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 6 Jan 2016 20:02:56 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u06K2uWj019991 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 6 Jan 2016 20:02:56 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u06K2ugt023934; Wed, 6 Jan 2016 20:02:56 GMT Received: from ovs104.us.oracle.com (/10.149.76.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Jan 2016 12:02:55 -0800 From: Boris Ostrovsky To: ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, wei.liu2@citrix.com Date: Wed, 6 Jan 2016 15:03:22 -0500 Message-Id: <1452110602-3570-3-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1452110602-3570-1-git-send-email-boris.ostrovsky@oracle.com> References: <1452110602-3570-1-git-send-email-boris.ostrovsky@oracle.com> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Cc: jgross@suse.com, andrew.cooper3@citrix.com, Boris Ostrovsky , roger.pau@citrix.com, xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH v3 2/2] libxc: Defer initialization of start_page for HVM guests X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Wei Liu --- tools/libxc/xc_dom_x86.c | 116 ++++++++++++++++++++++++++------------------- 1 files changed, 67 insertions(+), 49 deletions(-) diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c index b8d2904..e102bd2 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 ) { @@ -661,39 +647,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 ) - { - strncpy(cmdline, dom->cmdline, cmdline_size); - 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 @@ -1783,7 +1736,72 @@ 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); + + strncpy(cmdline, dom->cmdline, cmdline_size); + 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; }