[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5423d46e5c6f8a4204f8fe1bcea8bf1e21c10f39.1761058528.git.mst@redhat.com>
Date: Tue, 21 Oct 2025 10:56:57 -0400
From: "Michael S. Tsirkin" <mst@...hat.com>
To: linux-kernel@...r.kernel.org
Cc: Andrew Lunn <andrew@...n.ch>, 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 v2 2/2] 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 | 8 ++++++++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index afabc5cf31a6..e208bb0ca7da 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -76,8 +76,8 @@ static const u64 vhost_net_features[VIRTIO_FEATURES_ARRAY_SIZE] = {
(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 9c99014196ea..2eaee0b7c2df 100644
--- a/include/linux/virtio_features.h
+++ b/include/linux/virtio_features.h
@@ -8,6 +8,14 @@
#define VIRTIO_BIT(b) BIT_ULL((b) & 0x3f)
#define VIRTIO_U64(b) ((b) >> 6)
+/* Get a given feature bit in a given u64 entry. */
+#define VIRTIO_BIT_U64(bit, entry) \
+ (BUILD_BUG_ON_ZERO(const_true(VIRTIO_U64(bit) != (qword))) + \
+ BIT_ULL((bit) - 64 * (entry)))
+
+#define VIRTIO_BIT_LO(b) VIRTIO_BIT_U64(b, 0)
+#define VIRTIO_BIT_HI(b) VIRTIO_BIT_U64(b, 1)
+
#define VIRTIO_FEATURES_ARRAY_SIZE VIRTIO_U64(VIRTIO_FEATURES_BITS)
#define VIRTIO_DECLARE_FEATURES(name) \
--
MST
Powered by blists - more mailing lists