From patchwork Fri Jun 30 16:07:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Druzhinin X-Patchwork-Id: 9819995 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 E43BF60224 for ; Fri, 30 Jun 2017 16:09:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0866285EB for ; Fri, 30 Jun 2017 16:09:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D522628676; Fri, 30 Jun 2017 16:09:27 +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 7F2D7285EB for ; Fri, 30 Jun 2017 16:09:27 +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 1dQySS-0003ig-Tz; Fri, 30 Jun 2017 16:07:48 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQySR-0003iK-Uh for xen-devel@lists.xenproject.org; Fri, 30 Jun 2017 16:07:48 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id 49/10-01862-25776595; Fri, 30 Jun 2017 16:07:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLIsWRWlGSWpSXmKPExsWyU9JRQjewPCz S4OR1A4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNaN/3WKWgvnSFf9/nmFsYHwo1MXIySEh4Cdx acIBZhCbTcBA4tSmRSwgtoiArcTsv1OB4lwczAIzGCVePm1g62Lk4BAW8JL4MS8epIZFQFXi7 fzTrCA2r4CnxKYnj1ghZspJ3DzXCTaTE6h8xsEfbCC2EFDNtqYZjBD1ghInZz4B28UsICFx8M ULZogaNYmjXbtYIOakSbTfv8Y6gZFvFpKWWUhaFjAyrWLUKE4tKkst0jW00EsqykzPKMlNzMz RNTQw1stNLS5OTE/NSUwq1kvOz93ECAyqegYGxh2Mv097HmKU5GBSEuVdeS00UogvKT+lMiOx OCO+qDQntfgQowwHh5IEb3tpWKSQYFFqempFWmYOMLxh0hIcPEoivLJBQGne4oLE3OLMdIjUK UZdjlcT/n9jEmLJy89LlRLn9QGZIQBSlFGaBzcCFmuXGGWlhHkZGRgYhHgKUotyM0tQ5V8xin MwKgnzJoBM4cnMK4Hb9AroCCagI4RnhIAcUZKIkJJqYGyb4195irV93833tbfPLhTJ0HthuNa 3duIS99x7UodcKtfcmH/EkDHl9nb2k5Geos+/6PRPZp5jrGoXqR3W8YHNf87J9fX/F4jv5/y0 aUpswQF2xe2ZezvFsnzWVJucil3tftHuiq9qyYZVUSFc51dxbzucWP17EpcB6+JTDu9CTpznf b7/pr4SS3FGoqEWc1FxIgDXrdfMsAIAAA== X-Env-Sender: prvs=3478c7289=igor.druzhinin@citrix.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1498838862!95841775!2 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.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31609 invoked from network); 30 Jun 2017 16:07:45 -0000 Received: from smtp.eu.citrix.com (HELO SMTP.EU.CITRIX.COM) (185.25.65.24) by server-7.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 30 Jun 2017 16:07:45 -0000 X-IronPort-AV: E=Sophos;i="5.40,287,1496102400"; d="scan'208";a="48683288" From: Igor Druzhinin To: , Date: Fri, 30 Jun 2017 17:07:03 +0100 Message-ID: <1498838825-23701-3-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498838825-23701-1-git-send-email-igor.druzhinin@citrix.com> References: <1498838825-23701-1-git-send-email-igor.druzhinin@citrix.com> MIME-Version: 1.0 X-ClientProxiedBy: FTLPEX02CAS03.citrite.net (10.13.99.94) To AMSPEX02CL03.citrite.net (10.69.22.127) Cc: anthony.perard@citrix.com, Igor Druzhinin , sstabellini@kernel.org, paul.durrant@citrix.com, pbonzini@redhat.com Subject: [Xen-devel] [PATCH 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 --- hw/i386/xen/xen-mapcache.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c index e60156c..05050de 100644 --- a/hw/i386/xen/xen-mapcache.c +++ b/hw/i386/xen/xen-mapcache.c @@ -150,7 +150,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 +178,25 @@ 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); + } + } 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->vaddr_base = vaddr_base; @@ -211,6 +226,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 +278,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 +298,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; }