Skip to contentSkip to conversation

vdpa: Consider device id larger than 31

PATCH In review Parav Pandit 5 participants 6 messages Nov 25, 2021 – Nov 29, 2021 virtio core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vdpa: Consider device id larger than 31

virtio device id value can be more than 31. Hence, use BIT_ULL in assignment.

Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")
---
 drivers/vdpa/vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/vdpa.c +1 -1
index 7332a74a4b00..e91c71aeeddf 100644
@@ -404,7 +404,7 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m
 		goto msg_err;
 
 	while (mdev->id_table[i].device) {
-		supported_classes |= BIT(mdev->id_table[i].device);
+		supported_classes |= BIT_ULL(mdev->id_table[i].device);
 		i++;
 	}
 
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Parav Pandit

virtio device id value can be more than 31. Hence, use BIT_ULL in assignment.

Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")
Quoted 20 lines
---
 drivers/vdpa/vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/vdpa.c +1 -2
index 7332a74a4b00..e91c71aeeddf 100644
@@ -404,7 +404,7 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m
                goto msg_err;
 
        while (mdev->id_table[i].device) {
-               supported_classes |= BIT(mdev->id_table[i].device);
+               supported_classes |= BIT_ULL(mdev->id_table[i].device);
                i++;
        }
 
--

2.26.2

#2 lore raw
Quoted 23 lines · Jason Wang
Quoted 8 lines · Parav Pandit

virtio device id value can be more than 31. Hence, use BIT_ULL in assignment.

Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")
Quoted 11 lines
---
 drivers/vdpa/vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/vdpa.c +0 -0
index 7332a74a4b00..e91c71aeeddf 100644
@@ -404,7 +404,7 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m
                goto msg_err;
 
Quoted 6 lines

drivers/vdpa/vdpa.c static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m · line 410

Quoted 6 lines
drivers/vdpa/vdpa.c +1 -1
        while (mdev->id_table[i].device) {
-               supported_classes |= BIT(mdev->id_table[i].device);
+               supported_classes |= BIT_ULL(mdev->id_table[i].device);
                i++;
        }
 

type of mdev->id_table[i].device is __u32 so in theory you're limited to device ID's up to 63.
Maybe add assert here?

Quoted 4 lines
Quoted 3 lines

--
2.26.2

#3 lore raw
Quoted 24 lines · Eli Cohen
Quoted 23 lines · Jason Wang
Quoted 8 lines · Parav Pandit

virtio device id value can be more than 31. Hence, use BIT_ULL in assignment.

Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")
Quoted 11 lines
---
 drivers/vdpa/vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/vdpa.c +0 -0
index 7332a74a4b00..e91c71aeeddf 100644
@@ -404,7 +404,7 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m
                goto msg_err;
 
Quoted 10 lines
Quoted 6 lines

drivers/vdpa/vdpa.c static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m · line 410

Quoted 6 lines
drivers/vdpa/vdpa.c +1 -1
        while (mdev->id_table[i].device) {
-               supported_classes |= BIT(mdev->id_table[i].device);
+               supported_classes |= BIT_ULL(mdev->id_table[i].device);
                i++;
        }
 

type of mdev->id_table[i].device is __u32 so in theory you're limited to device ID's up to 63.
Maybe add assert here?

I think 1 << 63 is illegal though.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

--
2.26.2

#4 lore raw
In reply to Eli Cohen
Quoted 24 lines · Eli Cohen
Quoted 23 lines · Jason Wang
Quoted 8 lines · Parav Pandit

virtio device id value can be more than 31. Hence, use BIT_ULL in assignment.

Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")
Quoted 11 lines
---
 drivers/vdpa/vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/vdpa.c +0 -0
index 7332a74a4b00..e91c71aeeddf 100644
@@ -404,7 +404,7 @@ static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m
                goto msg_err;
 
Quoted 9 lines
Quoted 6 lines

drivers/vdpa/vdpa.c static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m · line 410

Quoted 6 lines
drivers/vdpa/vdpa.c +1 -1
        while (mdev->id_table[i].device) {
-               supported_classes |= BIT(mdev->id_table[i].device);
+               supported_classes |= BIT_ULL(mdev->id_table[i].device);
                i++;
        }
 

type of mdev->id_table[i].device is __u32 so in theory you're limited to device ID's up to 63.

A u32 can fit numbers up to 4 million? These .device numbers are normally hardcoded defines listed in usr/include/linux/virtio_ids.h

But sometimes they're not like in vp_modern_probe() which does:

	mdev->id.device = pci_dev->device - 0x1040;

I don't know if an assert is really worth it, considering how almost all of them are hardcoded. Also if we do want an assert maybe there is a better place to put it?

regards,
dan carpenter

#5 lore raw
Quoted 46 lines

From: Dan Carpenter <[email protected]>
Sent: Monday, November 29, 2021 12:29 PM

Quoted 18 lines · Eli Cohen
Quoted 17 lines · Jason Wang
Quoted 9 lines · Parav Pandit

virtio device id value can be more than 31. Hence, use BIT_ULL in assignment.

Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a

netlink interface")

Quoted 4 lines
---
 drivers/vdpa/vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 5 lines
Quoted 5 lines

drivers/vdpa/vdpa.c static int vdpa_mgmtdev_fill(const struct

Quoted 5 lines
drivers/vdpa/vdpa.c index renamed from drivers/vdpa/vdpa.c +0 -0

7332a74a4b00..e91c71aeeddf 100644

drivers/vdpa/vdpa.c +0 -0
@@ -404,7 +404,7 @@ static int vdpa_mgmtdev_fill(const struct

vdpa_mgmt_dev *mdev, struct sk_buff *m

Quoted 10 lines
Quoted 9 lines

drivers/vdpa/vdpa.c static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *m · line 409

Quoted 9 lines
drivers/vdpa/vdpa.c +2 -1
                goto msg_err;
 
        while (mdev->id_table[i].device) {
-               supported_classes |= BIT(mdev->id_table[i].device);
+               supported_classes |=
+ BIT_ULL(mdev->id_table[i].device);
                i++;
        }
Quoted 2 lines

type of mdev->id_table[i].device is __u32 so in theory you're limited to device ID's up to 63.

A u32 can fit numbers up to 4 million? These .device numbers are normally hardcoded defines listed in usr/include/linux/virtio_ids.h

Quoted 7 lines

But sometimes they're not like in vp_modern_probe() which does:

	mdev->id.device = pci_dev->device - 0x1040;

I don't know if an assert is really worth it, considering how almost all of them are hardcoded. Also if we do want an assert maybe there is a better place to put it?

I am changing above fix to report device id only upto 63.
Others higher values (which are not part of the current spec) will be ignored. There is no need for assert for any undefined value anyway.