From nobody Wed Feb 11 06:03:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695823228775370.880001724644; Wed, 27 Sep 2023 07:00:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlV4k-0005Wp-63; Wed, 27 Sep 2023 09:59:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlV4f-0005SN-W9 for qemu-devel@nongnu.org; Wed, 27 Sep 2023 09:59:34 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlV4e-0007Bj-Ku for qemu-devel@nongnu.org; Wed, 27 Sep 2023 09:59:33 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 2821DC0008; Wed, 27 Sep 2023 13:59:29 +0000 (UTC) From: Ilya Maximets To: "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , Ilya Maximets Subject: [PATCH v2 1/2] virtio: remove unnecessary thread fence while reading next descriptor Date: Wed, 27 Sep 2023 15:59:41 +0200 Message-ID: <20230927140016.2317404-2-i.maximets@ovn.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230927140016.2317404-1-i.maximets@ovn.org> References: <20230927140016.2317404-1-i.maximets@ovn.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: i.maximets@ovn.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=217.70.183.198; envelope-from=i.maximets@ovn.org; helo=relay6-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1695823230405100001 Content-Type: text/plain; charset="utf-8" It was supposed to be a compiler barrier and it was a compiler barrier initially called 'wmb' when virtio core support was introduced. Later all the instances of 'wmb' were switched to smp_wmb to fix memory ordering issues on non-x86 platforms. However, this one doesn't need to be an actual barrier, as its only purpose was to ensure that the value is not read twice. And since commit aa570d6fb6bd ("virtio: combine the read of a descriptor") there is no need for a barrier at all, since we're no longer reading guest memory here, but accessing a local structure. Signed-off-by: Ilya Maximets Reviewed-by: Stefan Hajnoczi --- hw/virtio/virtio.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 4577f3f5b3..37584aaa74 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1050,8 +1050,6 @@ static int virtqueue_split_read_next_desc(VirtIODevic= e *vdev, VRingDesc *desc, =20 /* Check they're not leading us off end of descriptors. */ *next =3D desc->next; - /* Make sure compiler knows to grab that: we don't want it changing! */ - smp_wmb(); =20 if (*next >=3D max) { virtio_error(vdev, "Desc next is %u", *next); --=20 2.41.0 From nobody Wed Feb 11 06:03:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695823209675816.3107273426943; Wed, 27 Sep 2023 07:00:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlV4l-0005ag-2k; Wed, 27 Sep 2023 09:59:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlV4i-0005US-Nc for qemu-devel@nongnu.org; Wed, 27 Sep 2023 09:59:36 -0400 Received: from relay6-d.mail.gandi.net ([2001:4b98:dc4:8::226]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlV4h-0007CI-83 for qemu-devel@nongnu.org; Wed, 27 Sep 2023 09:59:36 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id AC796C0013; Wed, 27 Sep 2023 13:59:32 +0000 (UTC) From: Ilya Maximets To: "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , Ilya Maximets Subject: [PATCH v2 2/2] virtio: remove unused next argument from virtqueue_split_read_next_desc() Date: Wed, 27 Sep 2023 15:59:42 +0200 Message-ID: <20230927140016.2317404-3-i.maximets@ovn.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230927140016.2317404-1-i.maximets@ovn.org> References: <20230927140016.2317404-1-i.maximets@ovn.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: i.maximets@ovn.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2001:4b98:dc4:8::226; envelope-from=i.maximets@ovn.org; helo=relay6-d.mail.gandi.net X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_NEUTRAL=0.779 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1695823212615100003 Content-Type: text/plain; charset="utf-8" The 'next' was converted from a local variable to an output parameter in commit: 412e0e81b174 ("virtio: handle virtqueue_read_next_desc() errors") But all the actual uses of the 'i/next' as an output were removed a few months prior in commit: aa570d6fb6bd ("virtio: combine the read of a descriptor") Remove the unused argument to simplify the code. Also, adding a comment to the function to describe what it is actually doing, as it is not obvious that the 'desc' is both an input and an output argument. Signed-off-by: Ilya Maximets Reviewed-by: Stefan Hajnoczi --- hw/virtio/virtio.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 37584aaa74..bc0388d45b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1039,9 +1039,10 @@ enum { VIRTQUEUE_READ_DESC_MORE =3D 1, /* more buffers in chain */ }; =20 +/* Reads the 'desc->next' descriptor into '*desc'. */ static int virtqueue_split_read_next_desc(VirtIODevice *vdev, VRingDesc *d= esc, MemoryRegionCache *desc_cache, - unsigned int max, unsigned int *= next) + unsigned int max) { /* If this descriptor says it doesn't chain, we're done. */ if (!(desc->flags & VRING_DESC_F_NEXT)) { @@ -1049,14 +1050,12 @@ static int virtqueue_split_read_next_desc(VirtIODev= ice *vdev, VRingDesc *desc, } =20 /* Check they're not leading us off end of descriptors. */ - *next =3D desc->next; - - if (*next >=3D max) { - virtio_error(vdev, "Desc next is %u", *next); + if (desc->next >=3D max) { + virtio_error(vdev, "Desc next is %u", desc->next); return VIRTQUEUE_READ_DESC_ERROR; } =20 - vring_split_desc_read(vdev, desc, desc_cache, *next); + vring_split_desc_read(vdev, desc, desc_cache, desc->next); return VIRTQUEUE_READ_DESC_MORE; } =20 @@ -1134,7 +1133,7 @@ static void virtqueue_split_get_avail_bytes(VirtQueue= *vq, goto done; } =20 - rc =3D virtqueue_split_read_next_desc(vdev, &desc, desc_cache,= max, &i); + rc =3D virtqueue_split_read_next_desc(vdev, &desc, desc_cache,= max); } while (rc =3D=3D VIRTQUEUE_READ_DESC_MORE); =20 if (rc =3D=3D VIRTQUEUE_READ_DESC_ERROR) { @@ -1585,7 +1584,7 @@ static void *virtqueue_split_pop(VirtQueue *vq, size_= t sz) goto err_undo_map; } =20 - rc =3D virtqueue_split_read_next_desc(vdev, &desc, desc_cache, max= , &i); + rc =3D virtqueue_split_read_next_desc(vdev, &desc, desc_cache, max= ); } while (rc =3D=3D VIRTQUEUE_READ_DESC_MORE); =20 if (rc =3D=3D VIRTQUEUE_READ_DESC_ERROR) { @@ -4039,8 +4038,7 @@ VirtioQueueElement *qmp_x_query_virtio_queue_element(= const char *path, list =3D node; =20 ndescs++; - rc =3D virtqueue_split_read_next_desc(vdev, &desc, desc_cache, - max, &i); + rc =3D virtqueue_split_read_next_desc(vdev, &desc, desc_cache,= max); } while (rc =3D=3D VIRTQUEUE_READ_DESC_MORE); element->descs =3D list; done: --=20 2.41.0