From nobody Mon Feb 9 02:27:29 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.zoho.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 1487363740212408.3594473927982; Fri, 17 Feb 2017 12:35:40 -0800 (PST) Received: from localhost ([::1]:55764 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepFh-0007QL-7x for importer@patchew.org; Fri, 17 Feb 2017 15:35:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceoc4-0004H0-CK for qemu-devel@nongnu.org; Fri, 17 Feb 2017 14:54:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceobz-0005fU-DV for qemu-devel@nongnu.org; Fri, 17 Feb 2017 14:54:40 -0500 Received: from mail.kernel.org ([198.145.29.136]:34414) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ceobz-0005es-3B for qemu-devel@nongnu.org; Fri, 17 Feb 2017 14:54:35 -0500 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 14D722021A; Fri, 17 Feb 2017 19:54:33 +0000 (UTC) Received: from redhat.com (pool-96-237-235-121.bstnma.fios.verizon.net [96.237.235.121]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AD71C201FE; Fri, 17 Feb 2017 19:54:31 +0000 (UTC) Date: Fri, 17 Feb 2017 21:54:30 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1487361200-29966-11-git-send-email-mst@redhat.com> References: <1487361200-29966-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1487361200-29966-1-git-send-email-mst@redhat.com> X-Mailer: git-send-email 2.8.0.287.g0deeb61 X-Mutt-Fcc: =sent X-Virus-Scanned: ClamAV using ClamSMTP X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 198.145.29.136 Subject: [Qemu-devel] [PULL 10/23] virtio: use VRingMemoryRegionCaches for descriptor ring 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: Peter Maydell , Stefan Hajnoczi , Paolo Bonzini 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 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index b75cb52..d62509d 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -491,25 +491,24 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigne= d int *in_bytes, VirtIODevice *vdev =3D vq->vdev; unsigned int max, idx; unsigned int total_bufs, in_total, out_total; - MemoryRegionCache vring_desc_cache; + VRingMemoryRegionCaches *caches; MemoryRegionCache indirect_desc_cache =3D MEMORY_REGION_CACHE_INVALID; int64_t len =3D 0; int rc; =20 + rcu_read_lock(); idx =3D vq->last_avail_idx; total_bufs =3D in_total =3D out_total =3D 0; =20 max =3D vq->vring.num; - len =3D address_space_cache_init(&vring_desc_cache, vdev->dma_as, - vq->vring.desc, max * sizeof(VRingDesc), - false); - if (len < max * sizeof(VRingDesc)) { + caches =3D atomic_rcu_read(&vq->vring.caches); + if (caches->desc.len < max * sizeof(VRingDesc)) { virtio_error(vdev, "Cannot map descriptor ring"); goto err; } =20 while ((rc =3D virtqueue_num_heads(vq, idx)) > 0) { - MemoryRegionCache *desc_cache =3D &vring_desc_cache; + MemoryRegionCache *desc_cache =3D &caches->desc; unsigned int num_bufs; VRingDesc desc; unsigned int i; @@ -586,13 +585,13 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigne= d int *in_bytes, =20 done: address_space_cache_destroy(&indirect_desc_cache); - address_space_cache_destroy(&vring_desc_cache); if (in_bytes) { *in_bytes =3D in_total; } if (out_bytes) { *out_bytes =3D out_total; } + rcu_read_unlock(); return; =20 err: @@ -726,7 +725,7 @@ static void *virtqueue_alloc_element(size_t sz, unsigne= d out_num, unsigned in_nu void *virtqueue_pop(VirtQueue *vq, size_t sz) { unsigned int i, head, max; - MemoryRegionCache vring_desc_cache; + VRingMemoryRegionCaches *caches; MemoryRegionCache indirect_desc_cache =3D MEMORY_REGION_CACHE_INVALID; MemoryRegionCache *desc_cache; int64_t len; @@ -768,15 +767,14 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) =20 i =3D head; =20 - len =3D address_space_cache_init(&vring_desc_cache, vdev->dma_as, - vq->vring.desc, max * sizeof(VRingDesc), - false); - if (len < max * sizeof(VRingDesc)) { + rcu_read_lock(); + caches =3D atomic_rcu_read(&vq->vring.caches); + if (caches->desc.len < max * sizeof(VRingDesc)) { virtio_error(vdev, "Cannot map descriptor ring"); goto done; } =20 - desc_cache =3D &vring_desc_cache; + desc_cache =3D &caches->desc; vring_desc_read(vdev, &desc, desc_cache, i); if (desc.flags & VRING_DESC_F_INDIRECT) { if (desc.len % sizeof(VRingDesc)) { @@ -850,7 +848,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) trace_virtqueue_pop(vq, elem, elem->in_num, elem->out_num); done: address_space_cache_destroy(&indirect_desc_cache); - address_space_cache_destroy(&vring_desc_cache); + rcu_read_unlock(); =20 return elem; =20 --=20 MST