From patchwork Tue Jul 4 15:47:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Druzhinin X-Patchwork-Id: 9825371 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 51E4C602F0 for ; Tue, 4 Jul 2017 15:50:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F1EE284D1 for ; Tue, 4 Jul 2017 15:50:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 322DC28535; Tue, 4 Jul 2017 15:50:23 +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 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 BDABC284FC for ; Tue, 4 Jul 2017 15:50:22 +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 1dSQ3s-0003OE-98; Tue, 04 Jul 2017 15:48:24 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSQ3q-0003MX-Rj for xen-devel@lists.xenproject.org; Tue, 04 Jul 2017 15:48:22 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id 82/A1-03704-6C8BB595; Tue, 04 Jul 2017 15:48:22 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCIsWRWlGSWpSXmKPExsWyU9JRQvfojuh Ig42v5Cy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyd79YxF3yQr/j3fz5LA+MKyS5GTg4JAT+J l+/XsoPYbAIGEqc2LWIBsUUEbCVm/53K3MXIxcEsMINR4uXTBjaQhLCAv8SsZx9YQWwWARWJp Ut/gjXwCnhKrLu4hgliqJzEzXOdzCA2p4CXxOXWNWALhIBqzl34wARRLyhxcuYTsF5mAQmJgy 9eMEPUqEkc7drFAjEnXWLF3lMsExj5ZiFpmYWkZQEj0ypGjeLUorLUIl1jY72kosz0jJLcxMw cXUMDM73c1OLixPTUnMSkYr3k/NxNjMCwYgCCHYw71wceYpTkYFIS5Y01i44U4kvKT6nMSCzO iC8qzUktPsQow8GhJMHrtR0oJ1iUmp5akZaZAwxwmLQEB4+SCK/ENqA0b3FBYm5xZjpE6hSjM ceqmT+/MXG8mvD/G5MQS15+XqqUOC8XyCQBkNKM0jy4QbDIu8QoKyXMywh0mhBPQWpRbmYJqv wrRnEORiVh3vkgU3gy80rg9r0COoUJ6JSGngiQU0oSEVJSDYw8hmGuf0TuXb9xRHLPa+7ZB+0 WsCe/fTPj6dbJJpsDSyZOf+kqc3lxcKl9/6bGf7pTfZyjFq5m9K5uqDU25Nrp6LFx19/nu70K 7p8NvhZwd3kBQ4DBwpKWa++f1d7P+KUufu6t4bbIz/enTC4sSmKalz5pysMptpHf9/UKG5x+2 pM5d5lU3ZQbSizFGYmGWsxFxYkAgaRiNrcCAAA= X-Env-Sender: prvs=3512ce2cb=igor.druzhinin@citrix.com X-Msg-Ref: server-15.tower-21.messagelabs.com!1499183286!71516320!5 X-Originating-IP: [185.25.65.24] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32262 invoked from network); 4 Jul 2017 15:48:21 -0000 Received: from smtp.ctxuk.citrix.com (HELO SMTP.EU.CITRIX.COM) (185.25.65.24) by server-15.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 4 Jul 2017 15:48:21 -0000 X-IronPort-AV: E=Sophos;i="5.40,309,1496102400"; d="scan'208";a="48812843" From: Igor Druzhinin To: , Date: Tue, 4 Jul 2017 16:47:47 +0100 Message-ID: <1499183267-28623-5-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499183267-28623-1-git-send-email-igor.druzhinin@citrix.com> References: <1499183267-28623-1-git-send-email-igor.druzhinin@citrix.com> MIME-Version: 1.0 X-ClientProxiedBy: FTLPEX02CAS01.citrite.net (10.13.99.120) To AMSPEX02CL01.citrite.net (10.69.22.125) Cc: anthony.perard@citrix.com, Igor Druzhinin , sstabellini@kernel.org, paul.durrant@citrix.com, pbonzini@redhat.com Subject: [Xen-devel] [PATCH v2 4/4] xen: don't use xenstore to save/restore physmap anymore 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP If we have a system with xenforeignmemory_map2() implemented we don't need to save/restore physmap on suspend/restore anymore. In case we resume a VM without physmap - try to recreate the physmap during memory region restore phase and remap map cache entries accordingly. The old code is left for compatibility reasons. Signed-off-by: Igor Druzhinin --- hw/i386/xen/xen-hvm.c | 48 ++++++++++++++++++++++++++++++++++----------- include/hw/xen/xen_common.h | 1 + 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index d259cf7..d24ca47 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -289,6 +289,7 @@ static XenPhysmap *get_physmapping(XenIOState *state, return NULL; } +#ifdef XEN_COMPAT_PHYSMAP static hwaddr xen_phys_offset_to_gaddr(hwaddr start_addr, ram_addr_t size, void *opaque) { @@ -334,6 +335,12 @@ static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) } return 0; } +#else +static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) +{ + return 0; +} +#endif static int xen_add_to_physmap(XenIOState *state, hwaddr start_addr, @@ -368,6 +375,26 @@ go_physmap: DPRINTF("mapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx"\n", start_addr, start_addr + size); + mr_name = memory_region_name(mr); + + physmap = g_malloc(sizeof (XenPhysmap)); + + physmap->start_addr = start_addr; + physmap->size = size; + physmap->name = mr_name; + physmap->phys_offset = phys_offset; + + QLIST_INSERT_HEAD(&state->physmap, physmap, list); + + if (runstate_check(RUN_STATE_INMIGRATE)) { + /* Now when we have a physmap entry we can replace a dummy mapping with + * a real one of guest foreign memory. */ + uint8_t *p = xen_replace_cache_entry(phys_offset, start_addr, size); + assert(p && p == memory_region_get_ram_ptr(mr)); + + return 0; + } + pfn = phys_offset >> TARGET_PAGE_BITS; start_gpfn = start_addr >> TARGET_PAGE_BITS; for (i = 0; i < size >> TARGET_PAGE_BITS; i++) { @@ -382,17 +409,6 @@ go_physmap: } } - mr_name = memory_region_name(mr); - - physmap = g_malloc(sizeof (XenPhysmap)); - - physmap->start_addr = start_addr; - physmap->size = size; - physmap->name = mr_name; - physmap->phys_offset = phys_offset; - - QLIST_INSERT_HEAD(&state->physmap, physmap, list); - xc_domain_pin_memory_cacheattr(xen_xc, xen_domid, start_addr >> TARGET_PAGE_BITS, (start_addr + size - 1) >> TARGET_PAGE_BITS, @@ -1158,6 +1174,7 @@ static void xen_exit_notifier(Notifier *n, void *data) xs_daemon_close(state->xenstore); } +#ifdef XEN_COMPAT_PHYSMAP static void xen_read_physmap(XenIOState *state) { XenPhysmap *physmap = NULL; @@ -1205,6 +1222,11 @@ static void xen_read_physmap(XenIOState *state) } free(entries); } +#else +static void xen_read_physmap(XenIOState *state) +{ +} +#endif static void xen_wakeup_notifier(Notifier *notifier, void *data) { @@ -1331,7 +1353,11 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) state->bufioreq_local_port = rc; /* Init RAM management */ +#ifdef XEN_COMPAT_PHYSMAP xen_map_cache_init(xen_phys_offset_to_gaddr, state); +#else + xen_map_cache_init(NULL, state); +#endif xen_ram_init(pcms, ram_size, ram_memory); qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state); diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 70a5cad..c04c5c9 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -80,6 +80,7 @@ extern xenforeignmemory_handle *xen_fmem; #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41000 +#define XEN_COMPAT_PHYSMAP #define xenforeignmemory_map2(h, d, a, p, f, ps, ar, e) \ xenforeignmemory_map(h, d, p, ps, ar, e)