From nobody Sat Feb 7 08:28:22 2026 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 1511981957244257.4362131016144; Wed, 29 Nov 2017 10:59:17 -0800 (PST) Received: from localhost ([::1]:44750 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK7ZN-0007l7-On for importer@patchew.org; Wed, 29 Nov 2017 13:58:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49107) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK7Rb-00016B-Ak for qemu-devel@nongnu.org; Wed, 29 Nov 2017 13:50:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eK7RY-0001T3-7g for qemu-devel@nongnu.org; Wed, 29 Nov 2017 13:50:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34608) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eK7RX-0001St-VB for qemu-devel@nongnu.org; Wed, 29 Nov 2017 13:50:48 -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 0DB4E3C34 for ; Wed, 29 Nov 2017 18:50:47 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BF936062D; Wed, 29 Nov 2017 18:50:44 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, imammedo@redhat.com Date: Wed, 29 Nov 2017 18:50:23 +0000 Message-Id: <20171129185026.23632-5-dgilbert@redhat.com> In-Reply-To: <20171129185026.23632-1-dgilbert@redhat.com> References: <20171129185026.23632-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, 29 Nov 2017 18:50:47 +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 4/7] vhost: update_mem_cb implementation 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, 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" Add the meat of update_mem_cb; this is called for each region, to add a region to our temporary list. Our temporary list is in order we look to see if this region can be merged with the current head of list. Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/trace-events | 2 ++ hw/virtio/vhost.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 4a493bcd46..92fadec192 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -2,6 +2,8 @@ =20 # hw/virtio/vhost.c vhost_section(const char *name, int r) "%s:%d" +vhost_update_mem_cb(const char *name, uint64_t gpa, uint64_t size, uint64_= t host) "%s: 0x%"PRIx64"+0x%"PRIx64" @ 0x%"PRIx64 +vhost_update_mem_cb_abut(const char *name, uint64_t new_size) "%s: 0x%"PRI= x64 =20 # hw/virtio/virtio.c virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned o= ut_num) "elem %p size %zd in_num %u out_num %u" diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index c959a59fb3..7e3c6ae032 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -638,11 +638,64 @@ struct vhost_update_mem_tmp { /* Called for each MRS from vhost_update_mem */ static int vhost_update_mem_cb(MemoryRegionSection *mrs, void *opaque) { + struct vhost_update_mem_tmp *vtmp =3D opaque; + struct vhost_memory_region *cur_vmr; + bool need_add =3D true; + uint64_t mrs_size; + uint64_t mrs_gpa; + uintptr_t mrs_host; + if (!vhost_section(mrs)) { return 0; } + 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) + + mrs->offset_within_region; + + trace_vhost_update_mem_cb(mrs->mr->name, mrs_gpa, mrs_size, + (uint64_t)mrs_host); + + if (vtmp->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 vtmp->regions + + (vtmp->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 && + (!vtmp->dev->vhost_ops->vhost_backend_can_merge || + vtmp->dev->vhost_ops->vhost_backend_can_merge(vtmp->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_update_mem_cb_abut(mrs->mr->name, mrs_size); + } + } + + if (need_add) { + vtmp->nregions++; + vtmp->regions =3D g_realloc_n(vtmp->regions, vtmp->nregions, + sizeof(vtmp->regions[0])); + cur_vmr =3D &vtmp->regions[vtmp->nregions - 1]; + 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; + } =20 - /* TODO */ return 0; } =20 --=20 2.14.3