vdpa: Consider device id larger than 31
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.
--- drivers/vdpa/vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/vdpa.c +1 -1
@@ -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
Quoted 8 lines · Parav Pandit
virtio device id value can be more than 31. Hence, use
BIT_ULLin assignment.Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Parav Pandit <[email protected]>
Quoted 20 lines
--- drivers/vdpa/vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/vdpa/vdpa.c +1
-2@@ -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
Quoted 23 lines · Jason Wang
Quoted 8 lines · Parav Pandit
virtio device id value can be more than 31. Hence, use
BIT_ULLin assignment.Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Parav Pandit <[email protected]>Acked-by Jason Wang <[email protected]>Quoted 11 lines
--- drivers/vdpa/vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)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 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
-1while (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
Michael S. Tsirkin
maintainerQuoted 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_ULLin assignment.Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Parav Pandit <[email protected]>Acked-by Jason Wang <[email protected]>Quoted 11 lines
--- drivers/vdpa/vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)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 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
-1while (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
__u32so 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
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_ULLin assignment.Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Parav Pandit <[email protected]>Acked-by Jason Wang <[email protected]>Quoted 11 lines
--- drivers/vdpa/vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)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 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
-1while (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
__u32so 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
Quoted 46 lines
From: Dan Carpenter <[email protected]>
Sent: Monday, November 29, 2021 12:29 PMQuoted 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_ULLin assignment.Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and anetlink interface")
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Parav Pandit <[email protected]>Acked-by Jason Wang <[email protected]>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..e91c71aeeddf100644drivers/vdpa/vdpa.c +0
-0@@ -404,7 +404,7 @@ static int vdpa_mgmtdev_fill(const struct
vdpa_mgmt_dev*mdev, structsk_buff*mQuoted 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
-1goto 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
__u32so 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.