From nobody Sun May 19 18:35:13 2024 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.zohomail.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 1499183453570345.2670662460047; Tue, 4 Jul 2017 08:50:53 -0700 (PDT) Received: from localhost ([::1]:42012 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSQ6F-0000FX-7P for importer@patchew.org; Tue, 04 Jul 2017 11:50:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56600) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSQ3i-0006oU-W8 for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSQ3h-00080H-3e for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:15 -0400 Received: from smtp.eu.citrix.com ([185.25.65.24]:38157) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1dSQ3g-0007zE-PO for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:13 -0400 X-IronPort-AV: E=Sophos;i="5.40,309,1496102400"; d="scan'208";a="48812834" From: Igor Druzhinin To: , Date: Tue, 4 Jul 2017 16:47:44 +0100 Message-ID: <1499183267-28623-2-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) 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 v2 1/4] xen: move physmap saving into a separate function 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" Non-functional change. Signed-off-by: Igor Druzhinin Reviewed-by: Paul Durrant acked-by and reviewed-by that were given (see --- hw/i386/xen/xen-hvm.c | 57 ++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index cffa7e2..d259cf7 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -305,6 +305,36 @@ static hwaddr xen_phys_offset_to_gaddr(hwaddr start_ad= dr, return start_addr; } =20 +static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) +{ + char path[80], value[17]; + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/start_addr", + xen_domid, (uint64_t)physmap->phys_offset); + snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)physmap->start_add= r); + if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { + return -1; + } + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/size", + xen_domid, (uint64_t)physmap->phys_offset); + snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)physmap->size); + if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { + return -1; + } + if (physmap->name) { + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/name", + xen_domid, (uint64_t)physmap->phys_offset); + if (!xs_write(state->xenstore, 0, path, + physmap->name, strlen(physmap->name))) { + return -1; + } + } + return 0; +} + static int xen_add_to_physmap(XenIOState *state, hwaddr start_addr, ram_addr_t size, @@ -316,7 +346,6 @@ static int xen_add_to_physmap(XenIOState *state, XenPhysmap *physmap =3D NULL; hwaddr pfn, start_gpfn; hwaddr phys_offset =3D memory_region_get_ram_addr(mr); - char path[80], value[17]; const char *mr_name; =20 if (get_physmapping(state, start_addr, size)) { @@ -368,31 +397,7 @@ go_physmap: start_addr >> TARGET_PAGE_BITS, (start_addr + size - 1) >> TARGET_PAGE_= BITS, XEN_DOMCTL_MEM_CACHEATTR_WB); - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%"PRIx64"/start_addr", - xen_domid, (uint64_t)phys_offset); - snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)start_addr); - if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { - return -1; - } - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%"PRIx64"/size", - xen_domid, (uint64_t)phys_offset); - snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)size); - if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { - return -1; - } - if (mr_name) { - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%"PRIx64"/name", - xen_domid, (uint64_t)phys_offset); - if (!xs_write(state->xenstore, 0, path, mr_name, strlen(mr_name)))= { - return -1; - } - } - - return 0; + return xen_save_physmap(state, physmap); } =20 static int xen_remove_from_physmap(XenIOState *state, --=20 2.7.4 From nobody Sun May 19 18:35:13 2024 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.zohomail.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 1499183519689279.1431001168389; Tue, 4 Jul 2017 08:51:59 -0700 (PDT) Received: from localhost ([::1]:42015 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSQ7I-00011W-8u for importer@patchew.org; Tue, 04 Jul 2017 11:51:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSQ3k-0006oe-Ee for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSQ3j-00080z-GV for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:16 -0400 Received: from smtp.eu.citrix.com ([185.25.65.24]:24123) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1dSQ3j-00080X-6j for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:15 -0400 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) 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 v2 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 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) =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 +180,27 @@ 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); + } + entry->flags &=3D ~(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 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); + } + entry->flags |=3D XEN_MAPCACHE_ENTRY_DUMMY; } =20 entry->vaddr_base =3D vaddr_base; @@ -211,6 +230,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 +282,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 +302,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 From nobody Sun May 19 18:35:13 2024 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.zohomail.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 1499183580457160.90950891464797; Tue, 4 Jul 2017 08:53:00 -0700 (PDT) Received: from localhost ([::1]:42017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSQ8J-0001Z3-7A for importer@patchew.org; Tue, 04 Jul 2017 11:52:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSQ3o-0006rE-8C for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSQ3m-00082C-Oy for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:20 -0400 Received: from smtp.eu.citrix.com ([185.25.65.24]:24123) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1dSQ3m-00080X-Af for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:18 -0400 X-IronPort-AV: E=Sophos;i="5.40,309,1496102400"; d="scan'208";a="48812839" From: Igor Druzhinin To: , Date: Tue, 4 Jul 2017 16:47:46 +0100 Message-ID: <1499183267-28623-4-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) 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 v2 3/4] xen/mapcache: introduce xen_replace_cache_entry() 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" This new call is trying to update a requested map cache entry according to the changes in the physmap. The call is searching for the entry, unmaps it and maps again at the same place using a new guest address. If the mapping is dummy this call will make it real. This function makes use of a new xenforeignmemory_map2() call with an extended interface that was recently introduced in libxenforeignmemory [1]. [1] https://www.mail-archive.com/xen-devel@lists.xen.org/msg113007.html Signed-off-by: Igor Druzhinin --- configure | 18 ++++++++++ hw/i386/xen/xen-mapcache.c | 79 ++++++++++++++++++++++++++++++++++++++-= ---- include/hw/xen/xen_common.h | 7 ++++ include/sysemu/xen-mapcache.h | 11 +++++- 4 files changed, 106 insertions(+), 9 deletions(-) diff --git a/configure b/configure index c571ad1..ad6156b 100755 --- a/configure +++ b/configure @@ -2021,6 +2021,24 @@ EOF # Xen unstable elif cat > $TMPC < +int main(void) { + xenforeignmemory_handle *xfmem; + + xfmem =3D xenforeignmemory_open(0, 0); + xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0); + + return 0; +} +EOF + compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs" + then + xen_stable_libs=3D"-lxendevicemodel $xen_stable_libs" + xen_ctrl_version=3D41000 + xen=3Dyes + elif + cat > $TMPC < diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c index cd4e746..a988be7 100644 --- a/hw/i386/xen/xen-mapcache.c +++ b/hw/i386/xen/xen-mapcache.c @@ -151,6 +151,7 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void = *opaque) } =20 static void xen_remap_bucket(MapCacheEntry *entry, + void *vaddr, hwaddr size, hwaddr address_index, bool dummy) @@ -167,7 +168,9 @@ static void xen_remap_bucket(MapCacheEntry *entry, err =3D g_malloc0(nb_pfn * sizeof (int)); =20 if (entry->vaddr_base !=3D NULL) { - ram_block_notify_remove(entry->vaddr_base, entry->size); + if (entry->vaddr_base !=3D vaddr) { + ram_block_notify_remove(entry->vaddr_base, entry->size); + } if (munmap(entry->vaddr_base, entry->size) !=3D 0) { perror("unmap fails"); exit(-1); @@ -181,11 +184,11 @@ static void xen_remap_bucket(MapCacheEntry *entry, } =20 if (!dummy) { - vaddr_base =3D xenforeignmemory_map(xen_fmem, xen_domid, - PROT_READ|PROT_WRITE, + vaddr_base =3D xenforeignmemory_map2(xen_fmem, xen_domid, vaddr, + PROT_READ|PROT_WRITE, 0, nb_pfn, pfns, err); if (vaddr_base =3D=3D NULL) { - perror("xenforeignmemory_map"); + perror("xenforeignmemory_map2"); exit(-1); } entry->flags &=3D ~(XEN_MAPCACHE_ENTRY_DUMMY); @@ -194,7 +197,7 @@ static void xen_remap_bucket(MapCacheEntry *entry, * 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, + vaddr_base =3D mmap(vaddr, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); if (vaddr_base =3D=3D NULL) { perror("mmap"); @@ -203,13 +206,16 @@ static void xen_remap_bucket(MapCacheEntry *entry, entry->flags |=3D XEN_MAPCACHE_ENTRY_DUMMY; } =20 + if (entry->vaddr_base =3D=3D NULL || entry->vaddr_base !=3D vaddr) { + ram_block_notify_add(vaddr_base, size); + } + entry->vaddr_base =3D vaddr_base; entry->paddr_index =3D address_index; entry->size =3D size; entry->valid_mapping =3D (unsigned long *) g_malloc0(sizeof(unsigned l= ong) * BITS_TO_LONGS(size >> XC_PAGE_SHIFT)); =20 - ram_block_notify_add(entry->vaddr_base, entry->size); bitmap_zero(entry->valid_mapping, nb_pfn); for (i =3D 0; i < nb_pfn; i++) { if (!err[i]) { @@ -282,14 +288,14 @@ tryagain: if (!entry) { entry =3D g_malloc0(sizeof (MapCacheEntry)); pentry->next =3D entry; - xen_remap_bucket(entry, cache_size, address_index, dummy); + xen_remap_bucket(entry, NULL, 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, dummy); + xen_remap_bucket(entry, NULL, cache_size, address_index, dummy= ); } } =20 @@ -486,3 +492,60 @@ void xen_invalidate_map_cache(void) =20 mapcache_unlock(); } + +static uint8_t *xen_replace_cache_entry_unlocked(hwaddr old_phys_addr, + hwaddr new_phys_addr, + hwaddr size) +{ + MapCacheEntry *entry; + hwaddr address_index; + hwaddr address_offset; + hwaddr cache_size =3D size; + hwaddr test_bit_size; + + address_index =3D old_phys_addr >> MCACHE_BUCKET_SHIFT; + address_offset =3D old_phys_addr & (MCACHE_BUCKET_SIZE - 1); + + assert(size); + /* test_bit_size is always a multiple of XC_PAGE_SIZE */ + test_bit_size =3D size + (old_phys_addr & (XC_PAGE_SIZE - 1)); + if (test_bit_size % XC_PAGE_SIZE) { + test_bit_size +=3D XC_PAGE_SIZE - (test_bit_size % XC_PAGE_SIZE); + } + cache_size =3D size + address_offset; + if (cache_size % MCACHE_BUCKET_SIZE) { + cache_size +=3D MCACHE_BUCKET_SIZE - (cache_size % MCACHE_BUCKET_S= IZE); + } + + entry =3D &mapcache->entry[address_index % mapcache->nr_buckets]; + while (entry && !(entry->paddr_index =3D=3D address_index && entry->si= ze =3D=3D cache_size)) { + entry =3D entry->next; + } + if (!entry) { + DPRINTF("Trying to update an entry for %lx that is not in the mapc= ache!\n", phys_addr); + return NULL; + } + + address_index =3D new_phys_addr >> MCACHE_BUCKET_SHIFT; + address_offset =3D new_phys_addr & (MCACHE_BUCKET_SIZE - 1); + + xen_remap_bucket(entry, entry->vaddr_base, cache_size, address_index, = false); + if(!test_bits(address_offset >> XC_PAGE_SHIFT, + test_bit_size >> XC_PAGE_SHIFT, + entry->valid_mapping)) { + DPRINTF("Unable to update an entry for %lx in the mapcache!\n", ph= ys_addr); + return NULL; + } + + return entry->vaddr_base + address_offset; +} + +uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr, hwaddr new_phys_add= r, hwaddr size) +{ + uint8_t *p; + + mapcache_lock(); + p =3D xen_replace_cache_entry_unlocked(old_phys_addr, new_phys_addr, s= ize); + mapcache_unlock(); + return p; +} diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index e00ddd7..70a5cad 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -78,6 +78,13 @@ static inline void *xenforeignmemory_map(xc_interface *h= , uint32_t dom, =20 extern xenforeignmemory_handle *xen_fmem; =20 +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41000 + +#define xenforeignmemory_map2(h, d, a, p, f, ps, ar, e) \ + xenforeignmemory_map(h, d, p, ps, ar, e) + +#endif + #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40900 =20 typedef xc_interface xendevicemodel_handle; diff --git a/include/sysemu/xen-mapcache.h b/include/sysemu/xen-mapcache.h index 01daaad..b38962c 100644 --- a/include/sysemu/xen-mapcache.h +++ b/include/sysemu/xen-mapcache.h @@ -21,7 +21,9 @@ uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size, ram_addr_t xen_ram_addr_from_mapcache(void *ptr); void xen_invalidate_map_cache_entry(uint8_t *buffer); void xen_invalidate_map_cache(void); - +uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr, + hwaddr new_phys_addr, + hwaddr size); #else =20 static inline void xen_map_cache_init(phys_offset_to_gaddr_t f, @@ -50,6 +52,13 @@ static inline void xen_invalidate_map_cache(void) { } =20 +uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr, + hwaddr new_phys_addr, + hwaddr size) +{ + abort(); +} + #endif =20 #endif /* XEN_MAPCACHE_H */ --=20 2.7.4 From nobody Sun May 19 18:35:13 2024 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.zohomail.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 1499183382322851.9169571682216; Tue, 4 Jul 2017 08:49:42 -0700 (PDT) Received: from localhost ([::1]:42005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSQ57-0007eX-8a for importer@patchew.org; Tue, 04 Jul 2017 11:49:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSQ3r-0006sn-Ht for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSQ3q-00083S-7Q for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:23 -0400 Received: from smtp.eu.citrix.com ([185.25.65.24]:24123) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1dSQ3p-00080X-Ne for qemu-devel@nongnu.org; Tue, 04 Jul 2017 11:48:22 -0400 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) 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 v2 4/4] xen: don't use xenstore to save/restore physmap anymore 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" 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; } =20 +#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, XenPhys= map *physmap) } return 0; } +#else +static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) +{ + return 0; +} +#endif =20 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); =20 + mr_name =3D memory_region_name(mr); + + physmap =3D g_malloc(sizeof (XenPhysmap)); + + physmap->start_addr =3D start_addr; + physmap->size =3D size; + physmap->name =3D mr_name; + physmap->phys_offset =3D 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 =3D xen_replace_cache_entry(phys_offset, start_addr, si= ze); + assert(p && p =3D=3D memory_region_get_ram_ptr(mr)); + + return 0; + } + pfn =3D phys_offset >> TARGET_PAGE_BITS; start_gpfn =3D start_addr >> TARGET_PAGE_BITS; for (i =3D 0; i < size >> TARGET_PAGE_BITS; i++) { @@ -382,17 +409,6 @@ go_physmap: } } =20 - mr_name =3D memory_region_name(mr); - - physmap =3D g_malloc(sizeof (XenPhysmap)); - - physmap->start_addr =3D start_addr; - physmap->size =3D size; - physmap->name =3D mr_name; - physmap->phys_offset =3D 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); } =20 +#ifdef XEN_COMPAT_PHYSMAP static void xen_read_physmap(XenIOState *state) { XenPhysmap *physmap =3D NULL; @@ -1205,6 +1222,11 @@ static void xen_read_physmap(XenIOState *state) } free(entries); } +#else +static void xen_read_physmap(XenIOState *state) +{ +} +#endif =20 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 =3D rc; =20 /* 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); =20 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; =20 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41000 =20 +#define XEN_COMPAT_PHYSMAP #define xenforeignmemory_map2(h, d, a, p, f, ps, ar, e) \ xenforeignmemory_map(h, d, p, ps, ar, e) =20 --=20 2.7.4