From nobody Sun Feb 8 06:55:47 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513021946162951.975992935238; Mon, 11 Dec 2017 11:52:26 -0800 (PST) Received: from localhost ([::1]:55220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOU7V-00052k-Mh for importer@patchew.org; Mon, 11 Dec 2017 14:52:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOU23-00089C-4m for qemu-devel@nongnu.org; Mon, 11 Dec 2017 14:46:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOU20-0006lL-9w for qemu-devel@nongnu.org; Mon, 11 Dec 2017 14:46:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48018) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eOU20-0006kH-3n for qemu-devel@nongnu.org; Mon, 11 Dec 2017 14:46:28 -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 31199C0567A3; Mon, 11 Dec 2017 19:46:27 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-205.ams2.redhat.com [10.36.117.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id F113E60562; Mon, 11 Dec 2017 19:46:25 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, imammedo@redhat.com Date: Mon, 11 Dec 2017 19:46:08 +0000 Message-Id: <20171211194610.3962-7-dgilbert@redhat.com> In-Reply-To: <20171211194610.3962-1-dgilbert@redhat.com> References: <20171211194610.3962-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.32]); Mon, 11 Dec 2017 19:46:27 +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 v3 6/8] vhost: Compare and copy updated region data into device state 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" Compare the temporary region data with the original, and if it's different update the original in the device state. Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/trace-events | 2 ++ hw/virtio/vhost.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 92fadec192..fac89aaba5 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(void) "" +vhost_update_mem_changed(void) "" 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 diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 646a3480c1..c00d82f96a 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -707,10 +707,12 @@ static int vhost_update_mem(struct vhost_dev *dev, bo= ol *changed) { int res; struct vhost_update_mem_tmp vtmp; + size_t mem_size; vtmp.regions =3D 0; vtmp.nregions =3D 0; vtmp.dev =3D dev; =20 + trace_vhost_update_mem(); *changed =3D false; res =3D address_space_iterate(&address_space_memory, vhost_update_mem_cb, &vtmp); @@ -718,8 +720,21 @@ static int vhost_update_mem(struct vhost_dev *dev, boo= l *changed) goto out; } =20 - /* TODO */ - *changed =3D dev->mem_changed_start_addr < dev->mem_changed_end_addr; + mem_size =3D offsetof(struct vhost_memory, regions) + + (vtmp.nregions + 1) * sizeof dev->mem->regions[0]; + + if (vtmp.nregions !=3D dev->mem->nregions || + memcmp(vtmp.regions, dev->mem->regions, mem_size)) { + *changed =3D true; + /* Update the main regions list from our tmp */ + dev->mem =3D g_realloc(dev->mem, mem_size); + dev->mem->nregions =3D vtmp.nregions; + memcpy(dev->mem->regions, vtmp.regions, + vtmp.nregions * sizeof dev->mem->regions[0]); + used_memslots =3D vtmp.nregions; + trace_vhost_update_mem_changed(); + } + out: g_free(vtmp.regions); return res; --=20 2.14.3