From patchwork Tue Jul 4 15:47:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Druzhinin X-Patchwork-Id: 9825369 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 6978A602F0 for ; Tue, 4 Jul 2017 15:50:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B3A928497 for ; Tue, 4 Jul 2017 15:50:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FA632852E; Tue, 4 Jul 2017 15:50:19 +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 CCEB028497 for ; Tue, 4 Jul 2017 15:50:18 +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 1dSQ3k-0003KP-Mq; Tue, 04 Jul 2017 15:48:16 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSQ3j-0003K5-Gc for xen-devel@lists.xenproject.org; Tue, 04 Jul 2017 15:48:15 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id 9C/62-03937-EB8BB595; Tue, 04 Jul 2017 15:48:14 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHIsWRWlGSWpSXmKPExsWyU9JRQnffjuh Ig752dovvWyYzOTB6HP5whSWAMYo1My8pvyKBNeNrwx/WgolyFR/brjM3MDaJdjFyckgI+Enc ODqLFcRmEzCQOLVpEQuILSJgKzH771TmLkYuDmaBGYwSL582sIEkhAV8Jb5c7GcGsVkEVCS2v L4I1swr4CmxYutWdoihchI3z3WC1XAKeElcbl0DFhcCqjl34QMTRL2gxMmZT8CWMQtISBx88Y IZokZN4mjXLhaIOekSK/aeYpnAyDcLScssJC0LGJlWMWoUpxaVpRbpGhvrJRVlpmeU5CZm5ug aGpjp5aYWFyemp+YkJhXrJefnbmIEhhUDEOxg3Lk+8BCjJAeTkihvrFl0pBBfUn5KZUZicUZ8 UWlOavEhRhkODiUJXq/tQDnBotT01Iq0zBxggMOkJTh4lER4JbYBpXmLCxJzizPTIVKnGHU5X k34/41JiCUvPy9VSpyXC2SGAEhRRmke3AhYtF1ilJUS5mUEOkqIpyC1KDezBFX+FaM4B6OSMO 98kCk8mXklcJteAR3BBHREQ08EyBEliQgpqQbGlVujIvMtTNZMP5Jazer3t/oVp1fvuXWiIWu mii7aUdf4cOd89mTRiB1sL1oT9PjDor7Mmqm6JdX+ouU/YWnBXafvF3PHxpXHi7xYsuGkjPaS X2elOuQtxawy+u9fnnhVcs36Sk+u84WX83qC/NeFL96+kJ8h5ujV9T78vTJXNrGZLfd7lR6rx FKckWioxVxUnAgAvHfVx7ECAAA= X-Env-Sender: prvs=3512ce2cb=igor.druzhinin@citrix.com X-Msg-Ref: server-15.tower-21.messagelabs.com!1499183286!71516320!3 X-Originating-IP: [185.25.65.24] X-SpamReason: No, hits=0.0 required=7.0 tests=received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31310 invoked from network); 4 Jul 2017 15:48:13 -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:13 -0000 X-IronPort-AV: E=Sophos;i="5.40,309,1496102400"; d="scan'208";a="48812837" From: Igor Druzhinin To: , Date: Tue, 4 Jul 2017 16:47:45 +0100 Message-ID: <1499183267-28623-3-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 2/4] xen/mapcache: add an ability to create dummy mappings 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 Dummys are simple anonymous mappings that are placed instead of regular foreign mappings in certain situations when we need to postpone the actual mapping but still have to give a memory region to QEMU to play with. This is planned to be used for restore on Xen. Signed-off-by: Igor Druzhinin Reviewed-by: Paul Durrant Reviewed-by: Stefano Stabellini --- hw/i386/xen/xen-mapcache.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c index e60156c..cd4e746 100644 --- a/hw/i386/xen/xen-mapcache.c +++ b/hw/i386/xen/xen-mapcache.c @@ -53,6 +53,8 @@ typedef struct MapCacheEntry { uint8_t *vaddr_base; unsigned long *valid_mapping; uint8_t lock; +#define XEN_MAPCACHE_ENTRY_DUMMY (1 << 0) + uint8_t flags; hwaddr size; struct MapCacheEntry *next; } MapCacheEntry; @@ -150,7 +152,8 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque) static void xen_remap_bucket(MapCacheEntry *entry, hwaddr size, - hwaddr address_index) + hwaddr address_index, + bool dummy) { uint8_t *vaddr_base; xen_pfn_t *pfns; @@ -177,11 +180,27 @@ static void xen_remap_bucket(MapCacheEntry *entry, pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i; } - vaddr_base = xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PROT_WRITE, - nb_pfn, pfns, err); - if (vaddr_base == NULL) { - perror("xenforeignmemory_map"); - exit(-1); + if (!dummy) { + vaddr_base = xenforeignmemory_map(xen_fmem, xen_domid, + PROT_READ|PROT_WRITE, + nb_pfn, pfns, err); + if (vaddr_base == NULL) { + perror("xenforeignmemory_map"); + exit(-1); + } + entry->flags &= ~(XEN_MAPCACHE_ENTRY_DUMMY); + } else { + /* + * We create dummy mappings where we are unable to create a foreign + * mapping immediately due to certain circumstances (i.e. on resume now) + */ + vaddr_base = mmap(NULL, size, PROT_READ|PROT_WRITE, + MAP_ANON|MAP_SHARED, -1, 0); + if (vaddr_base == NULL) { + perror("mmap"); + exit(-1); + } + entry->flags |= XEN_MAPCACHE_ENTRY_DUMMY; } entry->vaddr_base = vaddr_base; @@ -211,6 +230,7 @@ static uint8_t *xen_map_cache_unlocked(hwaddr phys_addr, hwaddr size, hwaddr cache_size = size; hwaddr test_bit_size; bool translated = false; + bool dummy = false; tryagain: address_index = phys_addr >> MCACHE_BUCKET_SHIFT; @@ -262,14 +282,14 @@ tryagain: if (!entry) { entry = g_malloc0(sizeof (MapCacheEntry)); pentry->next = entry; - xen_remap_bucket(entry, cache_size, address_index); + xen_remap_bucket(entry, cache_size, address_index, dummy); } else if (!entry->lock) { if (!entry->vaddr_base || entry->paddr_index != address_index || entry->size != cache_size || !test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { - xen_remap_bucket(entry, cache_size, address_index); + xen_remap_bucket(entry, cache_size, address_index, dummy); } } @@ -282,6 +302,10 @@ tryagain: translated = true; goto tryagain; } + if (!dummy && runstate_check(RUN_STATE_INMIGRATE)) { + dummy = true; + goto tryagain; + } trace_xen_map_cache_return(NULL); return NULL; }