From patchwork Wed Sep 7 18:59:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 9319797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 96F3960869 for ; Wed, 7 Sep 2016 19:07:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B4DB293D4 for ; Wed, 7 Sep 2016 19:07:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FABF29417; Wed, 7 Sep 2016 19:07:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2A60D29416 for ; Wed, 7 Sep 2016 19:07:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhiA9-0004HD-HC; Wed, 07 Sep 2016 19:05:33 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhiA7-0004FD-SQ for xen-devel@lists.xen.org; Wed, 07 Sep 2016 19:05:31 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id C9/92-03778-BF460D75; Wed, 07 Sep 2016 19:05:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsUyZ7p8oO6vlAv hBq2XlS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oxnSy4yFyyVqTg+/RxbA+MS4S5GLg4hgQlM EvdO9LNCOH8YJfZMucYG4WxglLj19wB7FyMnkNPDKPH2mCWIzSZgJHH26HRGEFtEQFri2ufLj CANzAKXGCXmXTzOBJIQFvCRmLH2DVgzi4CqxM9vS1lAbF4Bb4nF7UfYQGwJAQWJKQ/fM4PYnE DxjV8OQy3zknj/ZBUzRI2hxOeNS5knMPItYGRYxahenFpUllqka6yXVJSZnlGSm5iZo2toYKq Xm1pcnJiempOYVKyXnJ+7iREYKgxAsINx7z+nQ4ySHExKorzbWC+EC/El5adUZiQWZ8QXleak Fh9ilOHgUJLg/ZwMlBMsSk1PrUjLzAEGLUxagoNHSYT3LUiat7ggMbc4Mx0idYpRUUqcdxlIQ gAkkVGaB9cGi5RLjLJSwryMQIcI8RSkFuVmlqDKv2IU52BUEubVB8adEE9mXgnc9FdAi5mAFg udOg+yuCQRISXVwBh8VHvlS3Pxp94z/z4Kbp3D0TKxNiJih2eq6BmnsPNerDy/1ks0P23zPMZ leT6o3eWDWEnTdIN5D1/4Ot5cK/dnyrzp/+J0D6s+vXxq6jkxpr+LnqxVkV8T3/Xk8rZZV1O5 K7x8FvHulD78acviKx4PLqTIBE0VWeX5z/KIDIOC8/lFz/xs5c8rsRRnJBpqMRcVJwIA0rBEK o8CAAA= X-Env-Sender: boris.ostrovsky@oracle.com X-Msg-Ref: server-2.tower-206.messagelabs.com!1473275128!42351097!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 47894 invoked from network); 7 Sep 2016 19:05:30 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-2.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 7 Sep 2016 19:05:30 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u87J5K8E031935 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 7 Sep 2016 19:05:20 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u87J5J5A025264 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 7 Sep 2016 19:05:20 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u87J5JID004802; Wed, 7 Sep 2016 19:05:19 GMT Received: from ovs104.us.oracle.com (/10.149.76.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 07 Sep 2016 12:05:19 -0700 From: Boris Ostrovsky To: xen-devel@lists.xen.org Date: Wed, 7 Sep 2016 14:59:29 -0400 Message-Id: <1473274769-19129-20-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1473274769-19129-1-git-send-email-boris.ostrovsky@oracle.com> References: <1473274769-19129-1-git-send-email-boris.ostrovsky@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: wei.liu2@citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, julien.grall@arm.com, jbeulich@suse.com, zhaoshenglong@huawei.com, boris.ostrovsky@oracle.com, roger.pau@citrix.com Subject: [Xen-devel] [PATCH v3 19/19] libxc/xc_dom_core: Copy ACPI tables to guest space X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Load ACPI modules into guest space Signed-off-by: Boris Ostrovsky --- Changes in v3: * Use more macros in first_high_idx intilalization. * Format adjustments tools/libxc/xc_dom_core.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tools/libxc/xc_dom_core.c b/tools/libxc/xc_dom_core.c index ebada89..3817eb8 100644 --- a/tools/libxc/xc_dom_core.c +++ b/tools/libxc/xc_dom_core.c @@ -1040,6 +1040,95 @@ static int xc_dom_build_ramdisk(struct xc_dom_image *dom) return -1; } +static int populate_acpi_pages(struct xc_dom_image *dom, + xen_pfn_t *extents, + unsigned int num_pages) +{ + int rc; + xc_interface *xch = dom->xch; + uint32_t domid = dom->guest_domid; + unsigned long idx; + unsigned int first_high_idx = (4 << 30) >> PAGE_SHIFT; /* 4GB */ + + for ( ; num_pages; num_pages--, extents++ ) + { + + if ( xc_domain_populate_physmap(xch, domid, 1, 0, 0, extents) == 1 ) + continue; + + if (dom->highmem_end) + { + idx = --dom->highmem_end; + if ( idx == first_high_idx ) + dom->highmem_end = 0; + } + else + idx = --dom->lowmem_end; + + rc = xc_domain_add_to_physmap(xch, domid, + XENMAPSPACE_gmfn, + idx, *extents); + if (rc) + return rc; + } + + return 0; +} + +static int xc_dom_load_acpi(struct xc_dom_image *dom) +{ + int j, i = 0; + unsigned num_pages; + xen_pfn_t *extents, base; + void *ptr; + + while ( (i < MAX_ACPI_MODULES) && dom->acpi_modules[i].length ) + { + DOMPRINTF("%s: %d bytes at address %" PRIx64 "\n", __FUNCTION__, + dom->acpi_modules[i].length, + dom->acpi_modules[i].guest_addr_out); + + num_pages = (dom->acpi_modules[i].length + (XC_PAGE_SIZE - 1)) >> + XC_PAGE_SHIFT; + extents = malloc(num_pages * sizeof(*extents)); + if ( !extents ) + { + DOMPRINTF("%s: Out of memory", __FUNCTION__); + goto err; + } + + base = dom->acpi_modules[i].guest_addr_out >> XC_PAGE_SHIFT; + for (j=0; jxch, dom->guest_domid, + XC_PAGE_SIZE * num_pages, + PROT_READ | PROT_WRITE, base); + if ( !ptr ) + { + DOMPRINTF("%s: Can't map %d pages at 0x%lx", + __FUNCTION__, num_pages, base); + goto err; + } + + memcpy(ptr, dom->acpi_modules[i].data, dom->acpi_modules[i].length); + + free(extents); + i++; + } + + return 0; + +err: + free(extents); + return -1; +} + int xc_dom_build_image(struct xc_dom_image *dom) { unsigned int page_size; @@ -1097,6 +1186,10 @@ int xc_dom_build_image(struct xc_dom_image *dom) memcpy(devicetreemap, dom->devicetree_blob, dom->devicetree_size); } + /* load ACPI tables */ + if ( xc_dom_load_acpi(dom) != 0 ) + goto err; + /* allocate other pages */ if ( !dom->arch_hooks->p2m_base_supported || dom->parms.p2m_base >= dom->parms.virt_base ||