From nobody Tue Feb 10 04:29:53 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1512765735720216.0365041520805; Fri, 8 Dec 2017 12:42:15 -0800 (PST) Received: from localhost ([::1]:38973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNPSk-0000nt-2o for importer@patchew.org; Fri, 08 Dec 2017 15:41:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNPKh-0002YT-An for qemu-devel@nongnu.org; Fri, 08 Dec 2017 15:33:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eNPKg-0001Z9-Bf for qemu-devel@nongnu.org; Fri, 08 Dec 2017 15:33:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43080) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eNPKg-0001YD-3O for qemu-devel@nongnu.org; Fri, 08 Dec 2017 15:33:18 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56AFB30A09F; Fri, 8 Dec 2017 20:33:16 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-141.ams2.redhat.com [10.36.117.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 203A819E7B; Fri, 8 Dec 2017 20:33:14 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, imammedo@redhat.com Date: Fri, 8 Dec 2017 20:32:57 +0000 Message-Id: <20171208203257.13102-9-dgilbert@redhat.com> In-Reply-To: <20171208203257.13102-1-dgilbert@redhat.com> References: <20171208203257.13102-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 08 Dec 2017 20:33:16 +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] [RFC v2 8/8] vhost: Move mem_sections maintenance into commit/update routines 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, groug@kaod.org, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 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" Mvoe the maintenance of mem_sections into the vhost_update_mem routines, this removes the need for the vhost_region_add/del callbacks. Suggested-by: Igor Mammedov (and mostly written by Igor!) Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/vhost.c | 58 +++++++++++++++------------------------------------= ---- 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 2cfb13272f..79927ab93d 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -408,6 +408,13 @@ static int vhost_update_mem_cb(MemoryRegionSection *mr= s, void *opaque) if (!vhost_section(mrs)) { return 0; } + ++vtmp->dev->n_mem_sections; + vtmp->dev->mem_sections =3D g_renew(MemoryRegionSection, + vtmp->dev->mem_sections, + vtmp->dev->n_mem_sections); + vtmp->dev->mem_sections[vtmp->dev->n_mem_sections - 1] =3D *mrs; + memory_region_ref(mrs->mr); + mrs_size =3D int128_get64(mrs->size); mrs_gpa =3D mrs->offset_within_address_space; mrs_host =3D (uintptr_t)memory_region_get_ram_ptr(mrs->mr) + @@ -461,6 +468,7 @@ static int vhost_update_mem_cb(MemoryRegionSection *mrs= , void *opaque) static int vhost_update_mem(struct vhost_dev *dev, bool *changed) { int res; + unsigned i; struct vhost_update_mem_tmp vtmp; size_t mem_size; vtmp.regions =3D 0; @@ -469,6 +477,14 @@ static int vhost_update_mem(struct vhost_dev *dev, boo= l *changed) =20 trace_vhost_update_mem(); *changed =3D false; + /* Clear out the section list, it'll get rebuilt */ + for (i =3D 0; i < dev->n_mem_sections; i++) { + memory_region_unref(dev->mem_sections[i].mr); + } + g_free(dev->mem_sections); + dev->mem_sections =3D NULL; + dev->n_mem_sections =3D 0; + res =3D address_space_iterate(&address_space_memory, vhost_update_mem_cb, &vtmp); if (res) { @@ -553,46 +569,6 @@ static void vhost_commit(MemoryListener *listener) } } =20 -static void vhost_region_add(MemoryListener *listener, - MemoryRegionSection *section) -{ - struct vhost_dev *dev =3D container_of(listener, struct vhost_dev, - memory_listener); - - if (!vhost_section(section)) { - return; - } - - ++dev->n_mem_sections; - dev->mem_sections =3D g_renew(MemoryRegionSection, dev->mem_sections, - dev->n_mem_sections); - dev->mem_sections[dev->n_mem_sections - 1] =3D *section; - memory_region_ref(section->mr); -} - -static void vhost_region_del(MemoryListener *listener, - MemoryRegionSection *section) -{ - struct vhost_dev *dev =3D container_of(listener, struct vhost_dev, - memory_listener); - int i; - - if (!vhost_section(section)) { - return; - } - - memory_region_unref(section->mr); - for (i =3D 0; i < dev->n_mem_sections; ++i) { - if (dev->mem_sections[i].offset_within_address_space - =3D=3D section->offset_within_address_space) { - --dev->n_mem_sections; - memmove(&dev->mem_sections[i], &dev->mem_sections[i+1], - (dev->n_mem_sections - i) * sizeof(*dev->mem_sections)= ); - break; - } - } -} - static void vhost_iommu_unmap_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotl= b) { struct vhost_iommu *iommu =3D container_of(n, struct vhost_iommu, n); @@ -1161,8 +1137,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, =20 hdev->memory_listener =3D (MemoryListener) { .commit =3D vhost_commit, - .region_add =3D vhost_region_add, - .region_del =3D vhost_region_del, .region_nop =3D vhost_region_nop, .log_start =3D vhost_log_start, .log_stop =3D vhost_log_stop, --=20 2.14.3