From nobody Wed Nov 5 11:37:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498839063988764.6565946719716; Fri, 30 Jun 2017 09:11:03 -0700 (PDT) Received: from localhost ([::1]:45207 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQyVW-0001tC-KU for importer@patchew.org; Fri, 30 Jun 2017 12:10:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQySW-0007Oy-NH for qemu-devel@nongnu.org; Fri, 30 Jun 2017 12:07:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQySR-0006zO-UJ for qemu-devel@nongnu.org; Fri, 30 Jun 2017 12:07:52 -0400 Received: from smtp.ctxuk.citrix.com ([185.25.65.24]:62995 helo=SMTP.EU.CITRIX.COM) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQySR-0006vm-K5 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 12:07:47 -0400 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) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 185.25.65.24 Subject: [Qemu-devel] [PATCH 2/4] xen/mapcache: add an ability to create dummy mappings X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: anthony.perard@citrix.com, Igor Druzhinin , sstabellini@kernel.org, paul.durrant@citrix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) =20 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] =3D (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT))= + i; } =20 - vaddr_base =3D xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PRO= T_WRITE, - nb_pfn, pfns, err); - if (vaddr_base =3D=3D NULL) { - perror("xenforeignmemory_map"); - exit(-1); + if (!dummy) { + vaddr_base =3D xenforeignmemory_map(xen_fmem, xen_domid, + PROT_READ|PROT_WRITE, + nb_pfn, pfns, err); + if (vaddr_base =3D=3D 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 resum= e now) + */ + vaddr_base =3D mmap(NULL, size, PROT_READ|PROT_WRITE, + MAP_ANON|MAP_SHARED, -1, 0); + if (vaddr_base =3D=3D NULL) { + perror("mmap"); + exit(-1); + } } =20 entry->vaddr_base =3D vaddr_base; @@ -211,6 +226,7 @@ static uint8_t *xen_map_cache_unlocked(hwaddr phys_addr= , hwaddr size, hwaddr cache_size =3D size; hwaddr test_bit_size; bool translated =3D false; + bool dummy =3D false; =20 tryagain: address_index =3D phys_addr >> MCACHE_BUCKET_SHIFT; @@ -262,14 +278,14 @@ tryagain: if (!entry) { entry =3D g_malloc0(sizeof (MapCacheEntry)); pentry->next =3D 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 !=3D address_index || entry->size !=3D 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); } } =20 @@ -282,6 +298,10 @@ tryagain: translated =3D true; goto tryagain; } + if (!dummy && runstate_check(RUN_STATE_INMIGRATE)) { + dummy =3D true; + goto tryagain; + } trace_xen_map_cache_return(NULL); return NULL; } --=20 2.7.4