From nobody Wed Oct 29 06:36:50 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513189062600956.7376552031621; Wed, 13 Dec 2017 10:17:42 -0800 (PST) Received: from localhost ([::1]:36817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePBb9-0008N4-Kn for importer@patchew.org; Wed, 13 Dec 2017 13:17:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePBSH-0000z5-0b for qemu-devel@nongnu.org; Wed, 13 Dec 2017 13:08:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePBSE-0004FB-K8 for qemu-devel@nongnu.org; Wed, 13 Dec 2017 13:08:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53602) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePBSE-0004ER-AL for qemu-devel@nongnu.org; Wed, 13 Dec 2017 13:08:26 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53E5A356F6; Wed, 13 Dec 2017 18:08:25 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-87.ams2.redhat.com [10.36.117.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1AA5614F2; Wed, 13 Dec 2017 18:08:23 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, pbonzini@redhat.com, imammedo@redhat.com Date: Wed, 13 Dec 2017 18:08:05 +0000 Message-Id: <20171213180807.7066-5-dgilbert@redhat.com> In-Reply-To: <20171213180807.7066-1-dgilbert@redhat.com> References: <20171213180807.7066-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 13 Dec 2017 18:08:25 +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 v4 4/6] vhost: add regions to temporary 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, groug@kaod.org, mst@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" As regions are reported by the listener to the _nop and _add methods, add them to our new temporary list. Regions that abut can be merged if the backend allows. Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/trace-events | 2 ++ hw/virtio/vhost.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 72 insertions(+) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 4a493bcd46..7de0663652 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -1,6 +1,8 @@ # See docs/devel/tracing.txt for syntax documentation. =20 # hw/virtio/vhost.c +vhost_region_add_tmp(const char *name, uint64_t gpa, uint64_t size, uint64= _t host) "%s: 0x%"PRIx64"+0x%"PRIx64" @ 0x%"PRIx64 +vhost_region_add_tmp_abut(const char *name, uint64_t new_size) "%s: 0x%"PR= Ix64 vhost_section(const char *name, int r) "%s:%d" =20 # hw/virtio/virtio.c diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 4523f45587..2084888aa7 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -694,6 +694,67 @@ static void vhost_commit(MemoryListener *listener) dev->memory_changed =3D false; } =20 +/* Adds the section data to the tmp_mem structure. + * It relies on the listener calling us in memory address order + * and for each region (via the _add and _nop methods). + */ +static void vhost_region_add_tmp(struct vhost_dev *dev, + MemoryRegionSection *section) +{ + bool need_add =3D true; + uint64_t mrs_size =3D int128_get64(section->size); + uint64_t mrs_gpa =3D section->offset_within_address_space; + uintptr_t mrs_host =3D (uintptr_t)memory_region_get_ram_ptr(section->m= r) + + section->offset_within_region; + + trace_vhost_region_add_tmp(section->mr->name, mrs_gpa, mrs_size, mrs_h= ost); + + if (dev->tmp_mem->nregions) { + /* Since we already have at least one region, lets see if + * this extends it; since we're scanning in order, we only + * have to look at the last one, and the FlatView that calls + * us shouldn't have overlaps. + */ + struct vhost_memory_region *prev_vmr =3D dev->tmp_mem->regions + + (dev->tmp_mem->nregions - 1= ); + uint64_t prev_gpa_start =3D prev_vmr->guest_phys_addr; + uint64_t prev_gpa_end =3D range_get_last(prev_gpa_start, + prev_vmr->memory_size); + uint64_t prev_host_start =3D prev_vmr->userspace_addr; + uint64_t prev_host_end =3D range_get_last(prev_host_start, + prev_vmr->memory_size); + + if (prev_gpa_end + 1 =3D=3D mrs_gpa && + prev_host_end + 1 =3D=3D mrs_host && + (!dev->vhost_ops->vhost_backend_can_merge || + dev->vhost_ops->vhost_backend_can_merge(dev, + mrs_host, mrs_size, + prev_host_start, prev_vmr->memory_size))) { + /* The two regions abut */ + need_add =3D false; + mrs_size =3D mrs_size + prev_vmr->memory_size; + prev_vmr->memory_size =3D mrs_size; + trace_vhost_region_add_tmp_abut(section->mr->name, mrs_size); + } + } + + if (need_add) { + uint32_t nregions =3D dev->tmp_mem->nregions; + size_t s =3D offsetof(struct vhost_memory, regions) + + (nregions + 1) * sizeof dev->tmp_mem->regions[= 0]; + dev->tmp_mem =3D g_realloc(dev->tmp_mem, s); + dev->tmp_mem->nregions++; + struct vhost_memory_region *cur_vmr =3D &dev->tmp_mem->regions[nre= gions]; + + cur_vmr->guest_phys_addr =3D mrs_gpa; + cur_vmr->memory_size =3D mrs_size; + cur_vmr->userspace_addr =3D mrs_host; + cur_vmr->flags_padding =3D 0; + } + + +} + static void vhost_region_add(MemoryListener *listener, MemoryRegionSection *section) { @@ -703,6 +764,7 @@ static void vhost_region_add(MemoryListener *listener, if (!vhost_section(section)) { return; } + vhost_region_add_tmp(dev, section); =20 ++dev->n_mem_sections; dev->mem_sections =3D g_renew(MemoryRegionSection, dev->mem_sections, @@ -800,9 +862,17 @@ static void vhost_iommu_region_del(MemoryListener *lis= tener, } } =20 +/* Called on regions that have not changed */ static void vhost_region_nop(MemoryListener *listener, MemoryRegionSection *section) { + struct vhost_dev *dev =3D container_of(listener, struct vhost_dev, + memory_listener); + if (!vhost_section(section)) { + return; + } + + vhost_region_add_tmp(dev, section); } =20 static int vhost_virtqueue_set_addr(struct vhost_dev *dev, --=20 2.14.3