[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6629538adfd821c8626ab8b9def49c23781e6775.1760008798.git.mst@redhat.com>
Date: Thu, 9 Oct 2025 07:24:16 -0400
From: "Michael S. Tsirkin" <mst@...hat.com>
To: linux-kernel@...r.kernel.org
Cc: netdev@...r.kernel.org, Paolo Abeni <pabeni@...hat.com>,
Jason Wang <jasowang@...hat.com>,
Eugenio Pérez <eperezma@...hat.com>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>, kvm@...r.kernel.org,
virtualization@...ts.linux.dev
Subject: [PATCH 3/3] vhost: use checked versions of VIRTIO_BIT
This adds compile-time checked versions of VIRTIO_BIT that set bits in
low and high qword, respectively. Will prevent confusion when people
set bits in the wrong qword.
Cc: "Paolo Abeni" <pabeni@...hat.com>
Signed-off-by: Michael S. Tsirkin <mst@...hat.com>
---
drivers/vhost/net.c | 4 ++--
include/linux/virtio_features.h | 9 +++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 43d51fb1f8ea..8b98e1a8baaa 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -76,8 +76,8 @@ static const u64 vhost_net_features[VIRTIO_FEATURES_QWORDS] = {
(1ULL << VIRTIO_F_ACCESS_PLATFORM) |
(1ULL << VIRTIO_F_RING_RESET) |
(1ULL << VIRTIO_F_IN_ORDER),
- VIRTIO_BIT(VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) |
- VIRTIO_BIT(VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO),
+ VIRTIO_BIT_HI(VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) |
+ VIRTIO_BIT_HI(VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO),
};
enum {
diff --git a/include/linux/virtio_features.h b/include/linux/virtio_features.h
index f41acb035af9..466f7d8ed5ba 100644
--- a/include/linux/virtio_features.h
+++ b/include/linux/virtio_features.h
@@ -9,6 +9,15 @@
#define VIRTIO_FEATURES_DWORDS (VIRTIO_FEATURES_QWORDS * 2)
#define VIRTIO_BIT(b) BIT_ULL((b) & 0x3f)
#define VIRTIO_QWORD(b) ((b) >> 6)
+
+/* Get a given feature bit in a given qword. */
+#define VIRTIO_BIT_QWORD(bit, qword) \
+ (BUILD_BUG_ON_ZERO(const_true(VIRTIO_QWORD(bit) != (qword))) + \
+ BIT_ULL((bit) - 64 * (qword)))
+
+#define VIRTIO_BIT_LO(b) VIRTIO_BIT_QWORD(b, 0)
+#define VIRTIO_BIT_HI(b) VIRTIO_BIT_QWORD(b, 1)
+
#define VIRTIO_DECLARE_FEATURES(name) \
union { \
u64 name; \
--
MST
Powered by blists - more mailing lists