From nobody Sat Apr 27 07:28:01 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.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 1489509628846420.3315044938836; Tue, 14 Mar 2017 09:40:28 -0700 (PDT) Received: from localhost ([::1]:60681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnpUn-0004Qv-3p for importer@patchew.org; Tue, 14 Mar 2017 12:40:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnpQ0-0001Pl-NM for qemu-devel@nongnu.org; Tue, 14 Mar 2017 12:35:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnpPv-0008A5-Un for qemu-devel@nongnu.org; Tue, 14 Mar 2017 12:35:28 -0400 Received: from smtp.ctxuk.citrix.com ([185.25.65.24]:44932 helo=SMTP.EU.CITRIX.COM) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cnpPv-00089I-Im for qemu-devel@nongnu.org; Tue, 14 Mar 2017 12:35:23 -0400 X-IronPort-AV: E=Sophos;i="5.36,164,1486425600"; d="scan'208";a="42435037" From: Igor Druzhinin To: , Date: Tue, 14 Mar 2017 16:35:10 +0000 Message-ID: <1489509310-24166-1-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-ClientProxiedBy: FTLPEX02CAS01.citrite.net (10.13.99.120) 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 v4] xen: don't save/restore the physmap on VM save/restore 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: Igor Druzhinin , crosthwaite.peter@gmail.com, qemu-devel@nongnu.org, paul.durrant@citrix.com, pbonzini@redhat.com, xen-devel@lists.xenproject.org, rth@twiddle.net 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" Saving/restoring the physmap to/from xenstore was introduced to QEMU majorly in order to cover up the VRAM region restore issue. The sequence of restore operations implies that we should know the effective guest VRAM address *before* we have the VRAM region restored (which happens later). Unfortunately, in Xen environment VRAM memory does actually belong to a guest - not QEMU itself - which means the position of this region is unknown beforehand and can't be mapped into QEMU address space immediately. Previously, recreating xenstore keys, holding the physmap, by the toolstack helped to get this information in place at the right moment ready to be consumed by QEMU to map the region properly. The extraneous complexity of having those keys transferred by the toolstack and unnecessary redundancy prompted us to propose a solution which doesn't require any extra data in xenstore. The idea is to defer the VRAM region mapping till the point we actually know the effective address and able to map it. To that end, we initially just skip the mapping request for the framebuffer if we unable to map it now. Then, after the memory region restore phase, we perform the mapping again, this time successfully, and update the VRAM region metadata accordingly. Signed-off-by: Igor Druzhinin --- v4: * Use VGA post_load handler for vram_ptr update v3: * Modify qemu_ram_ptr_length similarly with qemu_map_ram_ptr * Add a comment explaining qemu_map_ram_ptr and qemu_ram_ptr_length=20 semantic change for Xen * Dropped some redundant changes v2: * Fix some building and coding style issues --- exec.c | 16 +++++++++ hw/display/vga.c | 5 +++ xen-hvm.c | 104 ++++++++++-----------------------------------------= ---- 3 files changed, 40 insertions(+), 85 deletions(-) diff --git a/exec.c b/exec.c index aabb035..a1ac8cd 100644 --- a/exec.c +++ b/exec.c @@ -2008,6 +2008,14 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr= _t addr) } =20 block->host =3D xen_map_cache(block->offset, block->max_length, 1); + if (block->host =3D=3D NULL) { + /* In case we cannot establish the mapping right away we might + * still be able to do it later e.g. on a later stage of resto= re. + * We don't touch the block and return NULL here to indicate + * that intention. + */ + return NULL; + } } return ramblock_ptr(block, addr); } @@ -2041,6 +2049,14 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block= , ram_addr_t addr, } =20 block->host =3D xen_map_cache(block->offset, block->max_length, 1); + if (block->host =3D=3D NULL) { + /* In case we cannot establish the mapping right away we might + * still be able to do it later e.g. on a later stage of resto= re. + * We don't touch the block and return NULL here to indicate + * that intention. + */ + return NULL; + } } =20 return ramblock_ptr(block, addr); diff --git a/hw/display/vga.c b/hw/display/vga.c index 69c3e1d..f8aebe3 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -2035,6 +2035,11 @@ static int vga_common_post_load(void *opaque, int ve= rsion_id) { VGACommonState *s =3D opaque; =20 + if (xen_enabled() && !s->vram_ptr) { + /* update VRAM region pointer in case we've failed + * the last time during init phase */ + s->vram_ptr =3D memory_region_get_ram_ptr(&s->vram); + } /* force refresh */ s->graphic_mode =3D -1; vbe_update_vgaregs(s); diff --git a/xen-hvm.c b/xen-hvm.c index 5043beb..8bedd9b 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -317,7 +317,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)) { @@ -340,6 +339,22 @@ 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)) { + /* If we are migrating the region has been already mapped */ + 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++) { @@ -350,49 +365,17 @@ go_physmap: if (rc) { DPRINTF("add_to_physmap MFN %"PRI_xen_pfn" to PFN %" PRI_xen_pfn" failed: %d (errno: %d)\n", idx, gpfn, rc,= errno); + + QLIST_REMOVE(physmap, list); + g_free(physmap); return -rc; } } =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, 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; } =20 @@ -1152,54 +1135,6 @@ static void xen_exit_notifier(Notifier *n, void *dat= a) xs_daemon_close(state->xenstore); } =20 -static void xen_read_physmap(XenIOState *state) -{ - XenPhysmap *physmap =3D NULL; - unsigned int len, num, i; - char path[80], *value =3D NULL; - char **entries =3D NULL; - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap", xen_domid); - entries =3D xs_directory(state->xenstore, 0, path, &num); - if (entries =3D=3D NULL) - return; - - for (i =3D 0; i < num; i++) { - physmap =3D g_malloc(sizeof (XenPhysmap)); - physmap->phys_offset =3D strtoull(entries[i], NULL, 16); - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%s/start_addr", - xen_domid, entries[i]); - value =3D xs_read(state->xenstore, 0, path, &len); - if (value =3D=3D NULL) { - g_free(physmap); - continue; - } - physmap->start_addr =3D strtoull(value, NULL, 16); - free(value); - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%s/size", - xen_domid, entries[i]); - value =3D xs_read(state->xenstore, 0, path, &len); - if (value =3D=3D NULL) { - g_free(physmap); - continue; - } - physmap->size =3D strtoull(value, NULL, 16); - free(value); - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%s/name", - xen_domid, entries[i]); - physmap->name =3D xs_read(state->xenstore, 0, path, &len); - - QLIST_INSERT_HEAD(&state->physmap, physmap, list); - } - free(entries); -} - static void xen_wakeup_notifier(Notifier *notifier, void *data) { xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); @@ -1339,7 +1274,6 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion = **ram_memory) goto err; } xen_be_register_common(); - xen_read_physmap(state); =20 /* Disable ACPI build because Xen handles it */ pcms->acpi_build_enabled =3D false; --=20 2.7.4