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" <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> --- 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

