From nobody Sun Oct 26 01:38:37 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.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 1516127808786398.05150598564353; Tue, 16 Jan 2018 10:36:48 -0800 (PST) Received: from localhost ([::1]:54696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebW6H-0005Mm-Tm for importer@patchew.org; Tue, 16 Jan 2018 13:36:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebVdL-0005cF-4c for qemu-devel@nongnu.org; Tue, 16 Jan 2018 13:06:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebVdG-0004Mz-Dw for qemu-devel@nongnu.org; Tue, 16 Jan 2018 13:06:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47994) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebVdG-0004M2-6H for qemu-devel@nongnu.org; Tue, 16 Jan 2018 13:06:46 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68E3E78522 for ; Tue, 16 Jan 2018 18:06:35 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-47.ams2.redhat.com [10.36.117.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9401F5E9D9; Tue, 16 Jan 2018 18:06:29 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, mst@redhat.com, imammedo@redhat.com Date: Tue, 16 Jan 2018 18:04:05 +0000 Message-Id: <20180116180408.11279-5-dgilbert@redhat.com> In-Reply-To: <20180116180408.11279-1-dgilbert@redhat.com> References: <20180116180408.11279-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 16 Jan 2018 18:06:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 4/7] vhost: Regenerate region list from changed sections list 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: maxime.coquelin@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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Compare the sections list that's just been generated, and if it's different from the old one regenerate the region list. Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/trace-events | 1 + hw/virtio/vhost.c | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index ab9da06244..606e4fc949 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -1,6 +1,7 @@ # See docs/devel/tracing.txt for syntax documentation. =20 # hw/virtio/vhost.c +vhost_commit(bool started, bool changed) "Started: %d Changed: %d" vhost_region_add_section(const char *name, uint64_t gpa, uint64_t size, ui= nt64_t host) "%s: 0x%"PRIx64"+0x%"PRIx64" @ 0x%"PRIx64 vhost_region_add_section_abut(const char *name, uint64_t new_size) "%s: 0x= %"PRIx64 =20 diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 15d466356e..cf8d5a0a92 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -637,21 +637,52 @@ static void vhost_commit(MemoryListener *listener) MemoryRegionSection *old_sections; int n_old_sections; uint64_t log_size; + size_t regions_size; int r; int i; + bool changed =3D false; =20 + /* Note we can be called before the device is started, but then + * starting the device calls set_mem_table, so we need to have + * built the data structures. + */ old_sections =3D dev->mem_sections; n_old_sections =3D dev->n_mem_sections; dev->mem_sections =3D dev->tmp_sections; dev->n_mem_sections =3D dev->n_tmp_sections; =20 - if (!dev->memory_changed) { - goto out; + if (dev->n_mem_sections !=3D n_old_sections) { + changed =3D true; + } else { + /* Same size, lets check the contents */ + changed =3D memcmp(dev->mem_sections, old_sections, + n_old_sections * sizeof(old_sections[0])) !=3D 0; } - if (!dev->started) { + + trace_vhost_commit(dev->started, changed); + if (!changed) { goto out; } - if (dev->mem_changed_start_addr > dev->mem_changed_end_addr) { + + /* Rebuild the regions list from the new sections list */ + regions_size =3D offsetof(struct vhost_memory, regions) + + dev->n_mem_sections * sizeof dev->mem->regions[0]; + dev->mem =3D g_realloc(dev->mem, regions_size); + dev->mem->nregions =3D dev->n_mem_sections; + used_memslots =3D dev->mem->nregions; + for (i =3D 0; i < dev->n_mem_sections; i++) { + struct vhost_memory_region *cur_vmr =3D dev->mem->regions + i; + struct MemoryRegionSection *mrs =3D dev->mem_sections + i; + + cur_vmr->guest_phys_addr =3D mrs->offset_within_address_space; + cur_vmr->memory_size =3D int128_get64(mrs->size); + cur_vmr->userspace_addr =3D + (uintptr_t)memory_region_get_ram_ptr(mrs->mr) + + mrs->offset_within_region; + cur_vmr->flags_padding =3D 0; + } + + if (!dev->started) { goto out; } =20 --=20 2.14.3