Skip to contentSkip to conversation

virtio_net: Improve RSS key size validation and use NETDEV_RSS_KEY_LEN

PATCH In review Srujana Challa 4 participants 29 messages Feb 24 – Feb 26

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 virtio_net: Improve RSS key size validation and use NETDEV_RSS_KEY_LEN

Replace hardcoded RSS max key size limit with NETDEV_RSS_KEY_LEN to align with kernel's standard RSS key length. Add validation for RSS key size against spec minimum (40 bytes) and driver maximum. When validation fails, gracefully disable RSS features and continue initialization rather than failing completely.

Fixes 3f7d9c1964fc ("virtio_net: Add hash_key_length check")

v3:
- Moved RSS key validation checks to virtnet_validate.
- Add fixes: tag and CC -stable
v4:
- Use NETDEV_RSS_KEY_LEN instead of type_max for the maximum rss key size.

---
 drivers/net/virtio_net.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
drivers/net/virtio_net.c +24 -10
index db88dcaefb20..eeefe8abc122 100644
@@ -381,8 +381,6 @@ struct receive_queue {
 	struct xdp_buff **xsk_buffs;
 };
 
-#define VIRTIO_NET_RSS_MAX_KEY_SIZE     40
-
 /* Control VQ buffers: protected by the rtnl lock */
 struct control_buf {
 	struct virtio_net_ctrl_hdr hdr;
@@ -486,7 +484,7 @@ struct virtnet_info {
 
 	/* Must be last as it ends in a flexible-array member. */
 	TRAILING_OVERLAP(struct virtio_net_rss_config_trailer, rss_trailer, hash_key_data,
-		u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE];
+		u8 rss_hash_key_data[NETDEV_RSS_KEY_LEN];
 	);
 };
 static_assert(offsetof(struct virtnet_info, rss_trailer.hash_key_data) ==
@@ -6627,6 +6625,29 @@ static int virtnet_validate(struct virtio_device *vdev)
 		__virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY);
 	}
 
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS) ||
+	    virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) {
+		u8 key_sz = virtio_cread8(vdev,
+					  offsetof(struct virtio_net_config,
+						   rss_max_key_size));
+		/* Spec requires at least 40 bytes */
+#define VIRTIO_NET_RSS_MIN_KEY_SIZE 40
+		if (key_sz < VIRTIO_NET_RSS_MIN_KEY_SIZE) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u is less than spec minimum %u, disabling RSS\n",
+				 key_sz, VIRTIO_NET_RSS_MIN_KEY_SIZE);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
+		}
+		if (key_sz > NETDEV_RSS_KEY_LEN) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
+				 key_sz, NETDEV_RSS_KEY_LEN);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
+		}
+	}
+
 	return 0;
 }
 
@@ -6839,13 +6860,6 @@ static int virtnet_probe(struct virtio_device *vdev)
 	if (vi->has_rss || vi->has_rss_hash_report) {
 		vi->rss_key_size =
 			virtio_cread8(vdev, offsetof(struct virtio_net_config, rss_max_key_size));
-		if (vi->rss_key_size > VIRTIO_NET_RSS_MAX_KEY_SIZE) {
-			dev_err(&vdev->dev, "rss_max_key_size=%u exceeds the limit %u.\n",
-				vi->rss_key_size, VIRTIO_NET_RSS_MAX_KEY_SIZE);
-			err = -EINVAL;
-			goto free;
-		}
-
 		vi->rss_hash_types_supported =
 		    virtio_cread32(vdev, offsetof(struct virtio_net_config, supported_hash_types));
 		vi->rss_hash_types_supported &=
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 virtio_net: replace RSS key size max check with BUILD_BUG_ON

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +1 -7
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);
 	}
 
 	return 0;
Signature · 1 line
2.25.1
reviewer
#2 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 15 lines · Srujana Challa

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

Do we really need this check?

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines this.

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce the intended limit correctly.

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

#3 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 29 lines · Xuan Zhuo
Quoted 15 lines · Srujana Challa

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

Do we really need this check?

Quoted 4 lines

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines this.

That's why it's BUILD_BUG_ON. It checks it has the right type.

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 2 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce the intended limit correctly.

then it would fail build.

Quoted 15 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

reviewer
#4 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 37 lines · Michael S. Tsirkin
Quoted 29 lines · Xuan Zhuo
Quoted 15 lines · Srujana Challa

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

Do we really need this check?

Quoted 4 lines

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines this.

That's why it's BUILD_BUG_ON. It checks it has the right type.

Quoted 8 lines

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 2 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce the intended limit correctly.

then it would fail build.

So, does this mean we don't need to account for the case where NETDEV_RSS_KEY_LEN is 128, but the key_sz reported by the device is 64?

Thanks.

Quoted 17 lines
Quoted 16 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

#5 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 45 lines · Xuan Zhuo
Quoted 44 lines · Michael S. Tsirkin
Quoted 29 lines · Xuan Zhuo
Quoted 15 lines · Srujana Challa

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

Do we really need this check?

Quoted 4 lines

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines this.

That's why it's BUILD_BUG_ON. It checks it has the right type.

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 2 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce the intended limit correctly.

Quoted 7 lines
Quoted 1 line

then it would fail build.

So, does this mean we don't need to account for the case where NETDEV_RSS_KEY_LEN is 128, but the key_sz reported by the device is 64?

Thanks.

yes. the code makes assumptions but it documents them and not just documents them, build will fail if they are violated.

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

reviewer
#6 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 48 lines · Michael S. Tsirkin
Quoted 47 lines · Xuan Zhuo
Quoted 45 lines · Michael S. Tsirkin
Quoted 29 lines · Xuan Zhuo
Quoted 15 lines · Srujana Challa

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

Do we really need this check?

Quoted 4 lines

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines this.

That's why it's BUILD_BUG_ON. It checks it has the right type.

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 2 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce the intended limit correctly.

then it would fail build.

Quoted 7 lines
Quoted 5 lines

So, does this mean we don't need to account for the case where NETDEV_RSS_KEY_LEN is 128, but the key_sz reported by the device is 64?

Thanks.

yes.

Why?

If NETDEV_RSS_KEY_LEN is 128 but the device reports a key_sz of 64, does this violate the spec?

Quoted 2 lines

the code makes assumptions but it documents them and not just documents them, build will fail if they are violated.

About this, I am ok.

Thanks.

Quoted 20 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

#7 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 55 lines · Xuan Zhuo
Quoted 54 lines · Michael S. Tsirkin
Quoted 52 lines · Xuan Zhuo
Quoted 37 lines · Michael S. Tsirkin
Quoted 29 lines · Xuan Zhuo
Quoted 15 lines · Srujana Challa

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

Do we really need this check?

Quoted 4 lines

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines this.

That's why it's BUILD_BUG_ON. It checks it has the right type.

Quoted 8 lines

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 2 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce the intended limit correctly.

then it would fail build.

So, does this mean we don't need to account for the case where NETDEV_RSS_KEY_LEN is 128, but the key_sz reported by the device is 64?

Thanks.

Quoted 6 lines
Quoted 1 line

yes.

Why?

If NETDEV_RSS_KEY_LEN is 128 but the device reports a key_sz of 64, does this violate the spec?

not the value of key_sz. If type of key_sz

i actually do not understand the question. this is not what BUILD_BUG_ON checks.

Quoted 28 lines
Quoted 2 lines

the code makes assumptions but it documents them and not just documents them, build will fail if they are violated.

About this, I am ok.

Thanks.

Quoted 20 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

reviewer
#8 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Xuan Zhuo
Quoted 48 lines · Michael S. Tsirkin
Quoted 47 lines · Xuan Zhuo
Quoted 45 lines · Michael S. Tsirkin
Quoted 29 lines · Xuan Zhuo
Quoted 15 lines · Srujana Challa

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

Do we really need this check?

Quoted 4 lines

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines this.

That's why it's BUILD_BUG_ON. It checks it has the right type.

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 2 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce the intended limit correctly.

then it would fail build.

Quoted 7 lines
Quoted 5 lines

So, does this mean we don't need to account for the case where NETDEV_RSS_KEY_LEN is 128, but the key_sz reported by the device is 64?

Thanks.

yes.

Why?

Quoted 8 lines
Quoted 2 lines

If NETDEV_RSS_KEY_LEN is 128 but the device reports a key_sz of 64, does this violate the spec?

not the value of key_sz. If type of key_sz

i actually do not understand the question. this is not what BUILD_BUG_ON checks.

So this is the issue. Originally, the code checked whether the value of key_sz was less than NETDEV_RSS_KEY_LEN. However, switching to a type_max check means it no longer covers the scenario I described. Therefore, I think this is unreasonable.

Thanks

Quoted 30 lines
Quoted 29 lines
Quoted 3 lines

the code makes assumptions but it documents them and not just documents them, build will fail if they are violated.

About this, I am ok.

Thanks.

Quoted 20 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

#9 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 64 lines · Xuan Zhuo
Quoted 63 lines · Michael S. Tsirkin
Quoted 61 lines · Xuan Zhuo
Quoted 48 lines · Michael S. Tsirkin
Quoted 47 lines · Xuan Zhuo
Quoted 45 lines · Michael S. Tsirkin
Quoted 29 lines · Xuan Zhuo
Quoted 15 lines · Srujana Challa

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

Do we really need this check?

Quoted 4 lines

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines this.

That's why it's BUILD_BUG_ON. It checks it has the right type.

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 2 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce the intended limit correctly.

then it would fail build.

Quoted 7 lines
Quoted 5 lines

So, does this mean we don't need to account for the case where NETDEV_RSS_KEY_LEN is 128, but the key_sz reported by the device is 64?

Thanks.

yes.

Why?

If NETDEV_RSS_KEY_LEN is 128 but the device reports a key_sz of 64, does this violate the spec?

Quoted 8 lines
Quoted 5 lines

not the value of key_sz. If type of key_sz

i actually do not understand the question. this is not what BUILD_BUG_ON checks.

So this is the issue. Originally, the code checked whether the value of key_sz was less than NETDEV_RSS_KEY_LEN.

No, and the check was plain wrong:

- if (key_sz > NETDEV_RSS_KEY_LEN) {
-

so if device supports a larger key then .... we disable the feature completely? Silly.

But the issue is present in net just the same.

So I think the commit log should be rewritten to explain the real issue, and target net, not net-next.

Quoted 39 lines

However, switching to a type_max check means
it no longer covers the scenario I described. Therefore, I think this is unreasonable.

Thanks

Quoted 30 lines
Quoted 29 lines
Quoted 3 lines

the code makes assumptions but it documents them and not just documents them, build will fail if they are violated.

About this, I am ok.

Thanks.

Quoted 20 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

#10 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

In reply to Xuan Zhuo
Quoted 70 lines · Xuan Zhuo
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Xuan Zhuo
Quoted 48 lines · Michael S. Tsirkin
Quoted 47 lines · Xuan Zhuo
Quoted 45 lines · Michael S. Tsirkin
Quoted 29 lines · Xuan Zhuo
Quoted 15 lines · Srujana Challa

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

Do we really need this check?

Quoted 4 lines

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines this.

That's why it's BUILD_BUG_ON. It checks it has the right type.

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 2 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce the intended limit correctly.

then it would fail build.

Quoted 7 lines
Quoted 5 lines

So, does this mean we don't need to account for the case where NETDEV_RSS_KEY_LEN is 128, but the key_sz reported by the device is 64?

Thanks.

yes.

Why?

Quoted 8 lines
Quoted 2 lines

If NETDEV_RSS_KEY_LEN is 128 but the device reports a key_sz of 64, does this violate the spec?

not the value of key_sz. If type of key_sz

i actually do not understand the question. this is not what BUILD_BUG_ON checks.

Quoted 6 lines

So this is the issue. Originally, the code checked whether the value of key_sz was less than NETDEV_RSS_KEY_LEN. However, switching to a type_max check means it no longer covers the scenario I described. Therefore, I think this is unreasonable.

Thanks

patch 1 is unreasonable i think.

which is why patchsets should have a cover letter btw so one can reply to just patch 1.

Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 3 lines

the code makes assumptions but it documents them and not just documents them, build will fail if they are violated.

About this, I am ok.

Thanks.

Quoted 20 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

#11 lore raw

RE: [EXTERNAL] Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 116 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, February 25, 2026 3:35 PM
To: Xuan Zhuo <[email protected]>
Cc: Srujana Challa <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nithin Kumar Dabilpuram <[email protected]>; Shiva Shankar Kommula <[email protected]>; [email protected]; [email protected]
Subject: [EXTERNAL] Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 1 line · Michael S. Tsirkin
Quoted 1 line

On Wed, Feb 25, 2026 at 05: 36: 06PM +0800, Xuan Zhuo wrote: > > > On

Wed, ZjQcmQRYFpfptBannerStart Prioritize security for external emails:
Confirm sender and content safety before clicking links or opening attachments <https://us-phishalarm-
ewt.proofpoint.com/EWT/v1/CRVmXkqW!tc3Z1f8UYnWatK- 8Gd3a7iLAAhjzwNasdLDRrDCP-M_xUEAECz9j2fwxWlWq3EugFfzY8uKAhQ- Q2XIdQs89ldnlzrpsl9A$>
Report Suspicious

ZjQcmQRYFpfptBannerEnd

Quoted 1 line · Xuan Zhuo

On Wed, 25 Feb 2026 04:47:22 -0500, "Michael S. Tsirkin"

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines · Xuan Zhuo
Quoted 1 line

On Wed, 25 Feb 2026 04:33:57 -0500, "Michael S. Tsirkin"

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Xuan Zhuo
Quoted 1 line

On Wed, 25 Feb 2026 04:24:14 -0500, "Michael S. Tsirkin"

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Xuan Zhuo
Quoted 1 line

On Tue, 24 Feb 2026 12:28:50 +0530, Srujana Challa

Quoted 9 lines · <[email protected]> wrote:
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/net/virtio_net.c static int virtnet_validate(struct

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/net/virtio_net.c index
eeefe8abc122..768ad5523dfa 100644

drivers/net/virtio_net.c +0 -0
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct

virtio_device *vdev)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/net/virtio_net.c static int virtnet_validate(struct · line 6640

Quoted 2 lines
drivers/net/virtio_net.c +0 -0
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
 			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/net/virtio_net.c static int virtnet_validate(struct · line 6644

Quoted 4 lines
drivers/net/virtio_net.c +0 -3
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver

limit %u, disabling RSS\n",

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/net/virtio_net.c static int virtnet_validate(struct · line 6647

Quoted 3 lines
drivers/net/virtio_net.c +0 -3
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/net/virtio_net.c static int virtnet_validate(struct · line 6642

Quoted 2 lines
drivers/net/virtio_net.c +1 -1
-		}
+		BUILD_BUG_ON(type_max(key_sz) >=

NETDEV_RSS_KEY_LEN);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Do we really need this check?

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines

this.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

That's why it's BUILD_BUG_ON. It checks it has the right type.

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 2 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce

the intended limit correctly.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

then it would fail build.

So, does this mean we don't need to account for the case where NETDEV_RSS_KEY_LEN is 128, but the key_sz reported by the device is

64?

Quoted 22 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Thanks.

yes.

Why?

Quoted 8 lines
Quoted 2 lines

If NETDEV_RSS_KEY_LEN is 128 but the device reports a key_sz of 64, does this violate the spec?

not the value of key_sz. If type of key_sz

i actually do not understand the question. this is not what BUILD_BUG_ON checks.

So this is the issue. Originally, the code checked whether the value of key_sz was less than NETDEV_RSS_KEY_LEN. However, switching to a type_max check means it no longer covers the scenario I described. Therefore, I think this is unreasonable.

Quoted 4 lines
Quoted 1 line

Thanks

patch 1 is unreasonable i think.

Patch 1 is targeted for net, addressing an issue where VIRTIO_NET_RSS_MAX_KEY_SIZE is fixed at 40, which is only the minimum required by the spec. This led to virtio‑net probe failures when devices reported an RSS key size greater than 40. However, the driver also cannot handle keys larger than NETDEV_RSS_KEY_LEN (previously 52) due to the BUG_ON(len > sizeof(netdev_rss_key)) in netdev_rss_key_fill. To resolve both issues, VIRTIO_NET_RSS_MAX_KEY_SIZE has been replaced with NETDEV_RSS_KEY_LEN.

Patch 2 is added as per your suggestion to address following warning in net-next after NETDEV_RSS_KEY_LEN
was increased to 256.
+../drivers/net/virtio_net.c:6642:14: warning: result of comparison of constant 256 with expression of type 'u8' (aka 'unsigned char') is always false [-Wtautological-constant-out-of-range-compare]
+ 6642 | if (key_sz > NETDEV_RSS_KEY_LEN) {
+ | ~~~~~~ ^ ~~~~~~~~~~~~~~~~~~
+1 warning generated.
Sorry, I forgot the cover page.

Thanks!

Quoted 35 lines

which is why patchsets should have a cover letter btw so one can reply to just patch 1.

Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 3 lines

the code makes assumptions but it documents them and not just documents them, build will fail if they are violated.

About this, I am ok.

Thanks.

Quoted 20 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

#12 lore raw

Re: [EXTERNAL] Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 119 lines · Srujana Challa
Quoted 119 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, February 25, 2026 3:35 PM
To: Xuan Zhuo <[email protected]>
Cc: Srujana Challa <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nithin Kumar Dabilpuram <[email protected]>; Shiva Shankar Kommula <[email protected]>; [email protected]; [email protected]
Subject: [EXTERNAL] Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 1 line · Michael S. Tsirkin
Quoted 1 line

On Wed, Feb 25, 2026 at 05: 36: 06PM +0800, Xuan Zhuo wrote: > > > On

Wed, ZjQcmQRYFpfptBannerStart Prioritize security for external emails:
Confirm sender and content safety before clicking links or opening attachments <https://us-phishalarm-
ewt.proofpoint.com/EWT/v1/CRVmXkqW!tc3Z1f8UYnWatK- 8Gd3a7iLAAhjzwNasdLDRrDCP-M_xUEAECz9j2fwxWlWq3EugFfzY8uKAhQ- Q2XIdQs89ldnlzrpsl9A$>
Report Suspicious

ZjQcmQRYFpfptBannerEnd

Quoted 1 line · Xuan Zhuo

On Wed, 25 Feb 2026 04:47:22 -0500, "Michael S. Tsirkin"

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines · Xuan Zhuo
Quoted 1 line

On Wed, 25 Feb 2026 04:33:57 -0500, "Michael S. Tsirkin"

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Xuan Zhuo
Quoted 1 line

On Wed, 25 Feb 2026 04:24:14 -0500, "Michael S. Tsirkin"

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Xuan Zhuo
Quoted 1 line

On Tue, 24 Feb 2026 12:28:50 +0530, Srujana Challa

Quoted 9 lines · <[email protected]> wrote:
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/net/virtio_net.c static int virtnet_validate(struct

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/net/virtio_net.c index
eeefe8abc122..768ad5523dfa 100644

drivers/net/virtio_net.c +0 -0
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct

virtio_device *vdev)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/net/virtio_net.c static int virtnet_validate(struct · line 6640

Quoted 2 lines
drivers/net/virtio_net.c +0 -0
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
 			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/net/virtio_net.c static int virtnet_validate(struct · line 6644

Quoted 4 lines
drivers/net/virtio_net.c +0 -3
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver

limit %u, disabling RSS\n",

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/net/virtio_net.c static int virtnet_validate(struct · line 6647

Quoted 3 lines
drivers/net/virtio_net.c +0 -3
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/net/virtio_net.c static int virtnet_validate(struct · line 6642

Quoted 2 lines
drivers/net/virtio_net.c +1 -1
-		}
+		BUILD_BUG_ON(type_max(key_sz) >=

NETDEV_RSS_KEY_LEN);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Do we really need this check?

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines

this.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

That's why it's BUILD_BUG_ON. It checks it has the right type.

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 2 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce

the intended limit correctly.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

then it would fail build.

So, does this mean we don't need to account for the case where NETDEV_RSS_KEY_LEN is 128, but the key_sz reported by the device is

64?

Quoted 23 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Thanks.

yes.

Why?

Quoted 8 lines
Quoted 2 lines

If NETDEV_RSS_KEY_LEN is 128 but the device reports a key_sz of 64, does this violate the spec?

not the value of key_sz. If type of key_sz

i actually do not understand the question. this is not what BUILD_BUG_ON checks.

So this is the issue. Originally, the code checked whether the value of key_sz was less than NETDEV_RSS_KEY_LEN. However, switching to a type_max check means it no longer covers the scenario I described. Therefore, I think this is unreasonable.

Thanks

Quoted 8 lines
Quoted 1 line

patch 1 is unreasonable i think.

Patch 1 is targeted for net, addressing an issue where VIRTIO_NET_RSS_MAX_KEY_SIZE is fixed at 40, which is only the minimum required by the spec. This led to virtio‑net probe failures when devices reported an RSS key size greater than 40. However, the driver also cannot handle keys larger than NETDEV_RSS_KEY_LEN (previously 52) due to the BUG_ON(len > sizeof(netdev_rss_key)) in netdev_rss_key_fill. To resolve both issues, VIRTIO_NET_RSS_MAX_KEY_SIZE has been replaced with NETDEV_RSS_KEY_LEN.

but where would driver *get* keys larger than sizeof(netdev_rss_key), even if device supports more.

Quoted 45 lines

Patch 2 is added as per your suggestion to address following warning in net-next after NETDEV_RSS_KEY_LEN
was increased to 256.
+../drivers/net/virtio_net.c:6642:14: warning: result of comparison of constant 256 with expression of type 'u8' (aka 'unsigned char') is always false [-Wtautological-constant-out-of-range-compare]
+ 6642 | if (key_sz > NETDEV_RSS_KEY_LEN) {
+ | ~~~~~~ ^ ~~~~~~~~~~~~~~~~~~
+1 warning generated.
Sorry, I forgot the cover page.

Thanks!

Quoted 35 lines

which is why patchsets should have a cover letter btw so one can reply to just patch 1.

Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 3 lines

the code makes assumptions but it documents them and not just documents them, build will fail if they are violated.

About this, I am ok.

Thanks.

Quoted 20 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

#13 lore raw

RE: [EXTERNAL] Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 110 lines
Quoted 30 lines
Quoted 30 lines

ZjQcmQRYFpfptBannerEnd

Quoted 1 line · Xuan Zhuo

On Wed, 25 Feb 2026 04:47:22 -0500, "Michael S. Tsirkin"

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines · Xuan Zhuo
Quoted 1 line

On Wed, 25 Feb 2026 04:33:57 -0500, "Michael S. Tsirkin"

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Xuan Zhuo
Quoted 1 line

On Wed, 25 Feb 2026 04:24:14 -0500, "Michael S. Tsirkin"

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Xuan Zhuo
Quoted 1 line

On Tue, 24 Feb 2026 12:28:50 +0530, Srujana Challa

Quoted 9 lines · <[email protected]> wrote:
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +0 -0

b/drivers/net/virtio_net.c index
eeefe8abc122..768ad5523dfa 100644

drivers/net/virtio_net.c +0 -0
@@ -6639,13 +6639,7 @@ static int

virtnet_validate(struct

virtio_device *vdev)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

__virtio_clear_bit(vdev,

VIRTIO_NET_F_RSS);

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/net/virtio_net.c

Quoted 4 lines
drivers/net/virtio_net.c +0 -3
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u

exceeds driver

Quoted 2 lines
Quoted 2 lines

limit %u, disabling RSS\n",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-				 key_sz,

NETDEV_RSS_KEY_LEN);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-			__virtio_clear_bit(vdev,

VIRTIO_NET_F_RSS);

Quoted 46 lines
Quoted 46 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/net/virtio_net.c

Quoted 2 lines
drivers/net/virtio_net.c +1 -1
-		}
+		BUILD_BUG_ON(type_max(key_sz) >=

NETDEV_RSS_KEY_LEN);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Do we really need this check?

If I understand correctly, the intention is to cap key_sz at 256. However, since key_sz is of type u8, its maximum value is inherently 255, making this check redundant. This is not only limited by this kernel code, the virtio-net spec defines

this.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

That's why it's BUILD_BUG_ON. It checks it has the right type.

We never *need* BUILD_BUG_ON by definition, what this does is document the assumption.

Quoted 3 lines

Moreover, if NETDEV_RSS_KEY_LEN is ever reduced to a value smaller than 256 in the future, this check would no longer enforce

the intended limit correctly.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

then it would fail build.

So, does this mean we don't need to account for the case where NETDEV_RSS_KEY_LEN is 128, but the key_sz reported by the device is

64?

Quoted 14 lines
Quoted 14 lines
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

Thanks.

yes.

Why?

If NETDEV_RSS_KEY_LEN is 128 but the device reports a key_sz of 64, does this violate the spec?

not the value of key_sz. If type of key_sz

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

i actually do not understand the question. this is not what BUILD_BUG_ON checks.

So this is the issue. Originally, the code checked whether the value of key_sz was less than NETDEV_RSS_KEY_LEN. However, switching to a type_max check means it no longer covers the scenario I

described.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Therefore, I think this is unreasonable.

Thanks

Quoted 8 lines
Quoted 1 line

patch 1 is unreasonable i think.

Patch 1 is targeted for net, addressing an issue where VIRTIO_NET_RSS_MAX_KEY_SIZE is fixed at 40, which is only the minimum required by the spec. This led to virtio‑net probe failures when devices reported an RSS key size greater than 40. However, the driver also cannot handle keys larger than NETDEV_RSS_KEY_LEN (previously 52) due to the BUG_ON(len > sizeof(netdev_rss_key)) in netdev_rss_key_fill. To

Quoted 5 lines

resolve both issues, VIRTIO_NET_RSS_MAX_KEY_SIZE has been replaced with NETDEV_RSS_KEY_LEN.

but where would driver *get* keys larger than sizeof(netdev_rss_key), even if device supports more.

In virtio‑net, we rely on netdev_rss_key_fill() during virtnet_init_default_rss() to populate the RSS hash key, which uses device supported length.
The code path is:
static void virtnet_init_default_rss(struct virtnet_info *vi)

{
        vi->rss_hdr->hash_types = cpu_to_le32(vi->rss_hash_types_supported);
        vi->rss_hash_types_saved = vi->rss_hash_types_supported;
        vi->rss_hdr->indirection_table_mask = vi->rss_indir_table_size
                                                ? cpu_to_le16(vi->rss_indir_table_size - 1) : 0;
        vi->rss_hdr->unclassified_queue = 0;

        virtnet_rss_update_by_qpairs(vi, vi->curr_queue_pairs);

        vi->rss_trailer.hash_key_length = vi->rss_key_size;

        netdev_rss_key_fill(vi->rss_hash_key_data, vi->rss_key_size);
}
Quoted 50 lines
Quoted 6 lines

Patch 2 is added as per your suggestion to address following warning in net-next after NETDEV_RSS_KEY_LEN was increased to 256. +../drivers/net/virtio_net.c:6642:14: warning: result of comparison of

constant 256 with expression of type 'u8' (aka 'unsigned char') is always false [-Wtautological-constant-out-of-range-compare]

Quoted 42 lines

+ 6642 | if (key_sz > NETDEV_RSS_KEY_LEN) {
+ | ~~~~~~ ^ ~~~~~~~~~~~~~~~~~~
+1 warning generated.
Sorry, I forgot the cover page.

Thanks!

Quoted 35 lines

which is why patchsets should have a cover letter btw so one can reply to just patch 1.

Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 3 lines

the code makes assumptions but it documents them and not just documents them, build will fail if they are violated.

About this, I am ok.

Thanks.

Quoted 20 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Moreover, you should add a cover letter.

Thanks.

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	}
 
 	return 0;
--

2.25.1

#14 lore raw

Re: [EXTERNAL] Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 17 lines · Srujana Challa
Quoted 8 lines
Quoted 8 lines
Quoted 1 line

patch 1 is unreasonable i think.

Patch 1 is targeted for net, addressing an issue where VIRTIO_NET_RSS_MAX_KEY_SIZE is fixed at 40, which is only the minimum required by the spec. This led to virtio‑net probe failures when devices reported an RSS key size greater than 40. However, the driver also cannot handle keys larger than NETDEV_RSS_KEY_LEN (previously 52) due to the BUG_ON(len > sizeof(netdev_rss_key)) in netdev_rss_key_fill. To

Quoted 5 lines

resolve both issues, VIRTIO_NET_RSS_MAX_KEY_SIZE has been replaced with NETDEV_RSS_KEY_LEN.

but where would driver *get* keys larger than sizeof(netdev_rss_key), even if device supports more.

In virtio‑net, we rely on netdev_rss_key_fill() during virtnet_init_default_rss() to populate the RSS hash key, which uses device supported length.
The code path is:
static void virtnet_init_default_rss(struct virtnet_info *vi)

Quoted 13 lines
{
        vi->rss_hdr->hash_types = cpu_to_le32(vi->rss_hash_types_supported);
        vi->rss_hash_types_saved = vi->rss_hash_types_supported;
        vi->rss_hdr->indirection_table_mask = vi->rss_indir_table_size
                                                ? cpu_to_le16(vi->rss_indir_table_size - 1) : 0;
        vi->rss_hdr->unclassified_queue = 0;

        virtnet_rss_update_by_qpairs(vi, vi->curr_queue_pairs);

        vi->rss_trailer.hash_key_length = vi->rss_key_size;

        netdev_rss_key_fill(vi->rss_hash_key_data, vi->rss_key_size);
}

Is there a point you are trying to make? disabling features because user bought a stronger device is counter intuitive. Make it work in a sane way pls.

Signature · 1 line
MST
#15 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

In reply to Srujana Challa
Quoted 15 lines · On Tue, 24 Feb 2026 12:28:50 +0530 Srujana Challa <[email protected]> wrote:

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

type_max is horrid.
I did read the later discussion (but it has fallen out of my brain) but isn't that check broken and/or backwards anyway?

I'd also question why you are using u8 for a local (I didn't find this version of the file), it will generate worse code that [unsigned] int.

David

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 	}
 
 	return 0;
#16 lore raw

Re: [PATCH net-next,2/2] virtio_net: replace RSS key size max check with BUILD_BUG_ON

Quoted 24 lines · David Laight
Quoted 21 lines · On Tue, 24 Feb 2026 12:28:50 +0530 Srujana Challa <[email protected]> wrote:

Since NETDEV_RSS_KEY_LEN was increased to 256 in net-next, use BUILD_BUG_ON to enforce the limit at compile time and remove the redundant runtime max check.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -4
index eeefe8abc122..768ad5523dfa 100644
@@ -6639,13 +6639,7 @@ static int virtnet_validate(struct virtio_device *vdev)
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
 			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
 		}
-		if (key_sz > NETDEV_RSS_KEY_LEN) {
-			dev_warn(&vdev->dev,
-				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
-				 key_sz, NETDEV_RSS_KEY_LEN);
Quoted 8 lines

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6642

Quoted 4 lines
drivers/net/virtio_net.c +1 -3
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
-			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
-		}
+		BUILD_BUG_ON(type_max(key_sz) >= NETDEV_RSS_KEY_LEN);

type_max is horrid.
I did read the later discussion (but it has fallen out of my brain) but isn't that check broken and/or backwards anyway?

it is just trying to say "i check at build time that hardware key size will never exceed NETDEV_RSS_KEY_LEN just because it's not large enough".

Quoted 2 lines

I'd also question why you are using u8 for a local (I didn't find this version of the file), it will generate worse code that [unsigned] int.

that's hardware format. but yes it should be config->max_key_size or whatever it is.

Quoted 5 lines

David

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 	}
 
 	return 0;
#17 lore raw
In reply to Srujana Challa
Quoted 9 lines · Srujana Challa

Replace hardcoded RSS max key size limit with NETDEV_RSS_KEY_LEN to align with kernel's standard RSS key length. Add validation for RSS key size against spec minimum (40 bytes) and driver maximum. When validation fails, gracefully disable RSS features and continue initialization rather than failing completely.

Fixes 3f7d9c1964fc ("virtio_net: Add hash_key_length check")

--- should come here before changelog.

Quoted 45 lines

v3:
- Moved RSS key validation checks to virtnet_validate.
- Add fixes: tag and CC -stable
v4:
- Use NETDEV_RSS_KEY_LEN instead of type_max for the maximum rss key size.

---
 drivers/net/virtio_net.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
drivers/net/virtio_net.c +11 -3
index db88dcaefb20..eeefe8abc122 100644
@@ -381,8 +381,6 @@ struct receive_queue {
 	struct xdp_buff **xsk_buffs;
 };
 
-#define VIRTIO_NET_RSS_MAX_KEY_SIZE     40
-
 /* Control VQ buffers: protected by the rtnl lock */
 struct control_buf {
 	struct virtio_net_ctrl_hdr hdr;
@@ -486,7 +484,7 @@ struct virtnet_info {
 
 	/* Must be last as it ends in a flexible-array member. */
 	TRAILING_OVERLAP(struct virtio_net_rss_config_trailer, rss_trailer, hash_key_data,
-		u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE];
+		u8 rss_hash_key_data[NETDEV_RSS_KEY_LEN];
 	);
 };
 static_assert(offsetof(struct virtnet_info, rss_trailer.hash_key_data) ==
@@ -6627,6 +6625,29 @@ static int virtnet_validate(struct virtio_device *vdev)
 		__virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY);
 	}
 
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS) ||
+	    virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) {
+		u8 key_sz = virtio_cread8(vdev,
+					  offsetof(struct virtio_net_config,
+						   rss_max_key_size));
+		/* Spec requires at least 40 bytes */
+#define VIRTIO_NET_RSS_MIN_KEY_SIZE 40
+		if (key_sz < VIRTIO_NET_RSS_MIN_KEY_SIZE) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u is less than spec minimum %u, disabling RSS\n",

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev) · line 6647

Quoted 10 lines
drivers/net/virtio_net.c +10 -0
+				 key_sz, VIRTIO_NET_RSS_MIN_KEY_SIZE);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);
+		}
+		if (key_sz > NETDEV_RSS_KEY_LEN) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u exceeds driver limit %u, disabling RSS\n",
+				 key_sz, NETDEV_RSS_KEY_LEN);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_HASH_REPORT);

you flipped the logic here and it makes no sense now.

Did you test this path?

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

Quoted 22 lines
drivers/net/virtio_net.c +3 -7
+		}
+	}
+
 	return 0;
 }
 
@@ -6839,13 +6860,6 @@ static int virtnet_probe(struct virtio_device *vdev)
 	if (vi->has_rss || vi->has_rss_hash_report) {
 		vi->rss_key_size =
 			virtio_cread8(vdev, offsetof(struct virtio_net_config, rss_max_key_size));
-		if (vi->rss_key_size > VIRTIO_NET_RSS_MAX_KEY_SIZE) {
-			dev_err(&vdev->dev, "rss_max_key_size=%u exceeds the limit %u.\n",
-				vi->rss_key_size, VIRTIO_NET_RSS_MAX_KEY_SIZE);
-			err = -EINVAL;
-			goto free;
-		}
-
 		vi->rss_hash_types_supported =
 		    virtio_cread32(vdev, offsetof(struct virtio_net_config, supported_hash_types));
 		vi->rss_hash_types_supported &=
Signature · 1 line
2.25.1
#18 lore raw
Quoted 71 lines · Srujana Challa
Quoted 9 lines

Replace hardcoded RSS max key size limit with NETDEV_RSS_KEY_LEN to align with kernel's standard RSS key length. Add validation for RSS key size against spec minimum (40 bytes) and driver maximum. When validation fails, gracefully disable RSS features and continue initialization rather than failing completely.

Fixes 3f7d9c1964fc ("virtio_net: Add hash_key_length check")

--- should come here before changelog.

Quoted 5 lines

v3:
- Moved RSS key validation checks to virtnet_validate.
- Add fixes: tag and CC -stable
v4:
- Use NETDEV_RSS_KEY_LEN instead of type_max for the maximum rss key

size.

Quoted 18 lines
---
 drivers/net/virtio_net.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
drivers/net/virtio_net.c index renamed from drivers/net/virtio_net.c +0 -0

db88dcaefb20..eeefe8abc122 100644

drivers/net/virtio_net.c +0 -2
@@ -381,8 +381,6 @@ struct receive_queue {
 	struct xdp_buff **xsk_buffs;
 };
 
-#define VIRTIO_NET_RSS_MAX_KEY_SIZE     40
-
 /* Control VQ buffers: protected by the rtnl lock */  struct
 control_buf {
 	struct virtio_net_ctrl_hdr hdr;

drivers/net/virtio_net.c struct virtnet_info { · line 486

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
@@ -486,7 +484,7 @@ struct virtnet_info {
 
 	/* Must be last as it ends in a flexible-array member. */
 	TRAILING_OVERLAP(struct virtio_net_rss_config_trailer, rss_trailer,

hash_key_data,

Quoted 6 lines
drivers/net/virtio_net.c +1 -1
-		u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE];
+		u8 rss_hash_key_data[NETDEV_RSS_KEY_LEN];
 	);
 };
 static_assert(offsetof(struct virtnet_info,

rss_trailer.hash_key_data) == @@ -6627,6 +6625,29 @@ static int

virtnet_validate(struct virtio_device *vdev)

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 13 lines
drivers/net/virtio_net.c +10 -0
 		__virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY);
 	}
 
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS) ||
+	    virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) {
+		u8 key_sz = virtio_cread8(vdev,
+					  offsetof(struct virtio_net_config,
+						   rss_max_key_size));
+		/* Spec requires at least 40 bytes */ #define
+VIRTIO_NET_RSS_MIN_KEY_SIZE 40
+		if (key_sz < VIRTIO_NET_RSS_MIN_KEY_SIZE) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u is less than spec

minimum %u, disabling RSS\n",

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +3 -0
+				 key_sz, VIRTIO_NET_RSS_MIN_KEY_SIZE);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 4 lines
drivers/net/virtio_net.c +4 -0
+		}
+		if (key_sz > NETDEV_RSS_KEY_LEN) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u exceeds driver limit

%u, disabling RSS\n",

Quoted 8 lines

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +3 -0
+				 key_sz, NETDEV_RSS_KEY_LEN);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

you flipped the logic here and it makes no sense now.

Did you test this path?

Yes, tested with Marvell's Octeon device.

Quoted 4 lines

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

The intent isn’t to disable the feature on capable devices, but to ensure the driver never advertises support for RSS key sizes larger than what the net device can actually handle. Even if a device reports a very large key size, the driver is constrained by NETDEV_RSS_KEY_LEN, since netdev_rss_key_fill() enforces:
BUG_ON(len > sizeof(netdev_rss_key));

Quoted 29 lines

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device

Quoted 9 lines
drivers/net/virtio_net.c +3 -0
+		}
+	}
+
 	return 0;
 }
@@ -6839,13 +6860,6 @@ static int virtnet_probe(struct virtio_device

*vdev)

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 	if (vi->has_rss || vi->has_rss_hash_report) {
 		vi->rss_key_size =
 			virtio_cread8(vdev, offsetof(struct virtio_net_config,

rss_max_key_size));

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device · line 6843

Quoted 2 lines
drivers/net/virtio_net.c +0 -2
-		if (vi->rss_key_size > VIRTIO_NET_RSS_MAX_KEY_SIZE) {
-			dev_err(&vdev->dev, "rss_max_key_size=%u exceeds

the limit %u.\n",

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device · line 6844

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-				vi->rss_key_size,

VIRTIO_NET_RSS_MAX_KEY_SIZE);

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)

Quoted 6 lines
drivers/net/virtio_net.c +0 -4
-			err = -EINVAL;
-			goto free;
-		}
-
 		vi->rss_hash_types_supported =
 		    virtio_cread32(vdev, offsetof(struct virtio_net_config,

supported_hash_types));

Quoted 3 lines
drivers/net/virtio_net.c +0 -1
 		vi->rss_hash_types_supported &=
--

2.25.1

#19 lore raw
Quoted 82 lines · Srujana Challa
Quoted 71 lines · Srujana Challa
Quoted 9 lines

Replace hardcoded RSS max key size limit with NETDEV_RSS_KEY_LEN to align with kernel's standard RSS key length. Add validation for RSS key size against spec minimum (40 bytes) and driver maximum. When validation fails, gracefully disable RSS features and continue initialization rather than failing completely.

Fixes 3f7d9c1964fc ("virtio_net: Add hash_key_length check")

--- should come here before changelog.

Quoted 5 lines

v3:
- Moved RSS key validation checks to virtnet_validate.
- Add fixes: tag and CC -stable
v4:
- Use NETDEV_RSS_KEY_LEN instead of type_max for the maximum rss key

size.

Quoted 18 lines
---
 drivers/net/virtio_net.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
drivers/net/virtio_net.c index renamed from drivers/net/virtio_net.c +0 -0

db88dcaefb20..eeefe8abc122 100644

drivers/net/virtio_net.c +0 -2
@@ -381,8 +381,6 @@ struct receive_queue {
 	struct xdp_buff **xsk_buffs;
 };
 
-#define VIRTIO_NET_RSS_MAX_KEY_SIZE     40
-
 /* Control VQ buffers: protected by the rtnl lock */  struct
 control_buf {
 	struct virtio_net_ctrl_hdr hdr;

drivers/net/virtio_net.c struct virtnet_info { · line 486

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
@@ -486,7 +484,7 @@ struct virtnet_info {
 
 	/* Must be last as it ends in a flexible-array member. */
 	TRAILING_OVERLAP(struct virtio_net_rss_config_trailer, rss_trailer,

hash_key_data,

Quoted 6 lines
drivers/net/virtio_net.c +1 -1
-		u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE];
+		u8 rss_hash_key_data[NETDEV_RSS_KEY_LEN];
 	);
 };
 static_assert(offsetof(struct virtnet_info,

rss_trailer.hash_key_data) == @@ -6627,6 +6625,29 @@ static int

virtnet_validate(struct virtio_device *vdev)

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 13 lines
drivers/net/virtio_net.c +10 -0
 		__virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY);
 	}
 
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS) ||
+	    virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) {
+		u8 key_sz = virtio_cread8(vdev,
+					  offsetof(struct virtio_net_config,
+						   rss_max_key_size));
+		/* Spec requires at least 40 bytes */ #define
+VIRTIO_NET_RSS_MIN_KEY_SIZE 40
+		if (key_sz < VIRTIO_NET_RSS_MIN_KEY_SIZE) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u is less than spec

minimum %u, disabling RSS\n",

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +3 -0
+				 key_sz, VIRTIO_NET_RSS_MIN_KEY_SIZE);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 4 lines
drivers/net/virtio_net.c +4 -0
+		}
+		if (key_sz > NETDEV_RSS_KEY_LEN) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u exceeds driver limit

%u, disabling RSS\n",

Quoted 8 lines

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +3 -0
+				 key_sz, NETDEV_RSS_KEY_LEN);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

you flipped the logic here and it makes no sense now.

Did you test this path?

Yes, tested with Marvell's Octeon device.

Quoted 2 lines
Quoted 6 lines
Quoted 2 lines

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

The intent isn’t to disable the feature on capable devices, but to ensure the driver never advertises support for RSS key sizes larger than what the net device can actually handle. Even if a device reports a very large key size, the driver is constrained by NETDEV_RSS_KEY_LEN, since netdev_rss_key_fill() enforces:
BUG_ON(len > sizeof(netdev_rss_key));

so cap it to NETDEV_RSS_KEY_LEN. Why is that a reason to clear the feature?

Quoted 30 lines
Quoted 29 lines

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device

Quoted 9 lines
drivers/net/virtio_net.c +3 -0
+		}
+	}
+
 	return 0;
 }
@@ -6839,13 +6860,6 @@ static int virtnet_probe(struct virtio_device

*vdev)

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 	if (vi->has_rss || vi->has_rss_hash_report) {
 		vi->rss_key_size =
 			virtio_cread8(vdev, offsetof(struct virtio_net_config,

rss_max_key_size));

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device · line 6843

Quoted 2 lines
drivers/net/virtio_net.c +0 -2
-		if (vi->rss_key_size > VIRTIO_NET_RSS_MAX_KEY_SIZE) {
-			dev_err(&vdev->dev, "rss_max_key_size=%u exceeds

the limit %u.\n",

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device · line 6844

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-				vi->rss_key_size,

VIRTIO_NET_RSS_MAX_KEY_SIZE);

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)

Quoted 6 lines
drivers/net/virtio_net.c +0 -4
-			err = -EINVAL;
-			goto free;
-		}
-
 		vi->rss_hash_types_supported =
 		    virtio_cread32(vdev, offsetof(struct virtio_net_config,

supported_hash_types));

Quoted 3 lines
drivers/net/virtio_net.c +0 -1
 		vi->rss_hash_types_supported &=
--

2.25.1

#20 lore raw
Quoted 87 lines
Quoted 87 lines
Quoted 74 lines · Srujana Challa
Quoted 9 lines

Replace hardcoded RSS max key size limit with NETDEV_RSS_KEY_LEN to align with kernel's standard RSS key length. Add validation for RSS key size against spec minimum (40 bytes) and driver maximum. When validation fails, gracefully disable RSS features and continue initialization rather than failing completely.

Fixes 3f7d9c1964fc ("virtio_net: Add hash_key_length check")

--- should come here before changelog.

Quoted 6 lines

v3:
- Moved RSS key validation checks to virtnet_validate.
- Add fixes: tag and CC -stable
v4:
- Use NETDEV_RSS_KEY_LEN instead of type_max for the maximum rss key

size.

Quoted 19 lines
---
 drivers/net/virtio_net.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
drivers/net/virtio_net.c +0 -0

index
db88dcaefb20..eeefe8abc122 100644

drivers/net/virtio_net.c +0 -2
@@ -381,8 +381,6 @@ struct receive_queue {
 	struct xdp_buff **xsk_buffs;
 };
 
-#define VIRTIO_NET_RSS_MAX_KEY_SIZE     40
-
 /* Control VQ buffers: protected by the rtnl lock */  struct
 control_buf {
 	struct virtio_net_ctrl_hdr hdr;

drivers/net/virtio_net.c struct virtnet_info { · line 487

Quoted 4 lines
drivers/net/virtio_net.c +0 -0
@@ -486,7 +484,7 @@ struct virtnet_info {
 
 	/* Must be last as it ends in a flexible-array member. */
 	TRAILING_OVERLAP(struct virtio_net_rss_config_trailer,
 rss_trailer,

hash_key_data,

Quoted 6 lines
drivers/net/virtio_net.c +1 -1
-		u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE];
+		u8 rss_hash_key_data[NETDEV_RSS_KEY_LEN];
 	);
 };

static_assert(offsetof(struct virtnet_info,
rss_trailer.hash_key_data) == @@ -6627,6 +6625,29 @@ static int

virtnet_validate(struct virtio_device *vdev)

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 13 lines
drivers/net/virtio_net.c +10 -0
 		__virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY);
 	}
 
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS) ||
+	    virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) {
+		u8 key_sz = virtio_cread8(vdev,
+					  offsetof(struct virtio_net_config,
+						   rss_max_key_size));
+		/* Spec requires at least 40 bytes */ #define
+VIRTIO_NET_RSS_MIN_KEY_SIZE 40
+		if (key_sz < VIRTIO_NET_RSS_MIN_KEY_SIZE) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u is less than spec

minimum %u, disabling RSS\n",

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +3 -0
+				 key_sz, VIRTIO_NET_RSS_MIN_KEY_SIZE);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 4 lines
drivers/net/virtio_net.c +4 -0
+		}
+		if (key_sz > NETDEV_RSS_KEY_LEN) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u exceeds driver limit

%u, disabling RSS\n",

Quoted 8 lines

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +3 -0
+				 key_sz, NETDEV_RSS_KEY_LEN);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

you flipped the logic here and it makes no sense now.

Did you test this path?

Yes, tested with Marvell's Octeon device.

Quoted 4 lines

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

Quoted 8 lines
Quoted 3 lines

The intent isn’t to disable the feature on capable devices, but to ensure the driver never advertises support for RSS key sizes larger than what the net device can actually handle. Even if a device reports a very

large key size, the driver is constrained by NETDEV_RSS_KEY_LEN, since netdev_rss_key_fill() enforces:

Quoted 1 line

BUG_ON(len > sizeof(netdev_rss_key));

so cap it to NETDEV_RSS_KEY_LEN. Why is that a reason to clear the feature?

Our device mandates that hash_key_length must be identical to rss_max_key_size to guarantee symmetric bidirectional flow hashing. If rss_max_key_size is larger than VIRTIO_NET_RSS_MAX_KEY_SIZE, clamping the value is not feasible.

Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Quoted 11 lines
drivers/net/virtio_net.c +3 -0
+		}
+	}
+
 	return 0;
 }
@@ -6839,13 +6860,6 @@ static int virtnet_probe(struct

virtio_device

*vdev)

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 	if (vi->has_rss || vi->has_rss_hash_report) {
 		vi->rss_key_size =
 			virtio_cread8(vdev, offsetof(struct virtio_net_config,

rss_max_key_size));

drivers/net/virtio_net.c

Quoted 2 lines
drivers/net/virtio_net.c +0 -2
-		if (vi->rss_key_size > VIRTIO_NET_RSS_MAX_KEY_SIZE) {
-			dev_err(&vdev->dev, "rss_max_key_size=%u exceeds

the limit %u.\n",

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-				vi->rss_key_size,

VIRTIO_NET_RSS_MAX_KEY_SIZE);

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)

Quoted 6 lines
drivers/net/virtio_net.c +0 -4
-			err = -EINVAL;
-			goto free;
-		}
-
 		vi->rss_hash_types_supported =
 		    virtio_cread32(vdev, offsetof(struct virtio_net_config,

supported_hash_types));

Quoted 3 lines

vi->rss_hash_types_supported &=
--
2.25.1

#21 lore raw
Quoted 90 lines · Srujana Challa
Quoted 90 lines
Quoted 90 lines
Quoted 74 lines · Srujana Challa
Quoted 9 lines

Replace hardcoded RSS max key size limit with NETDEV_RSS_KEY_LEN to align with kernel's standard RSS key length. Add validation for RSS key size against spec minimum (40 bytes) and driver maximum. When validation fails, gracefully disable RSS features and continue initialization rather than failing completely.

Fixes 3f7d9c1964fc ("virtio_net: Add hash_key_length check")

--- should come here before changelog.

Quoted 6 lines

v3:
- Moved RSS key validation checks to virtnet_validate.
- Add fixes: tag and CC -stable
v4:
- Use NETDEV_RSS_KEY_LEN instead of type_max for the maximum rss key

size.

Quoted 19 lines
---
 drivers/net/virtio_net.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
drivers/net/virtio_net.c +0 -0

index
db88dcaefb20..eeefe8abc122 100644

drivers/net/virtio_net.c +0 -2
@@ -381,8 +381,6 @@ struct receive_queue {
 	struct xdp_buff **xsk_buffs;
 };
 
-#define VIRTIO_NET_RSS_MAX_KEY_SIZE     40
-
 /* Control VQ buffers: protected by the rtnl lock */  struct
 control_buf {
 	struct virtio_net_ctrl_hdr hdr;

drivers/net/virtio_net.c struct virtnet_info { · line 487

Quoted 4 lines
drivers/net/virtio_net.c +0 -0
@@ -486,7 +484,7 @@ struct virtnet_info {
 
 	/* Must be last as it ends in a flexible-array member. */
 	TRAILING_OVERLAP(struct virtio_net_rss_config_trailer,
 rss_trailer,

hash_key_data,

Quoted 6 lines
drivers/net/virtio_net.c +1 -1
-		u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE];
+		u8 rss_hash_key_data[NETDEV_RSS_KEY_LEN];
 	);
 };

static_assert(offsetof(struct virtnet_info,
rss_trailer.hash_key_data) == @@ -6627,6 +6625,29 @@ static int

virtnet_validate(struct virtio_device *vdev)

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 13 lines
drivers/net/virtio_net.c +10 -0
 		__virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY);
 	}
 
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS) ||
+	    virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) {
+		u8 key_sz = virtio_cread8(vdev,
+					  offsetof(struct virtio_net_config,
+						   rss_max_key_size));
+		/* Spec requires at least 40 bytes */ #define
+VIRTIO_NET_RSS_MIN_KEY_SIZE 40
+		if (key_sz < VIRTIO_NET_RSS_MIN_KEY_SIZE) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u is less than spec

minimum %u, disabling RSS\n",

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +3 -0
+				 key_sz, VIRTIO_NET_RSS_MIN_KEY_SIZE);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 4 lines
drivers/net/virtio_net.c +4 -0
+		}
+		if (key_sz > NETDEV_RSS_KEY_LEN) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u exceeds driver limit

%u, disabling RSS\n",

Quoted 8 lines

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +3 -0
+				 key_sz, NETDEV_RSS_KEY_LEN);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

you flipped the logic here and it makes no sense now.

Did you test this path?

Yes, tested with Marvell's Octeon device.

Quoted 4 lines

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

The intent isn’t to disable the feature on capable devices, but to ensure the driver never advertises support for RSS key sizes larger than what the net device can actually handle. Even if a device reports a very

Quoted 8 lines
Quoted 5 lines

large key size, the driver is constrained by NETDEV_RSS_KEY_LEN, since netdev_rss_key_fill() enforces:

Quoted 1 line

BUG_ON(len > sizeof(netdev_rss_key));

so cap it to NETDEV_RSS_KEY_LEN. Why is that a reason to clear the feature?

Our device mandates that hash_key_length must be identical to rss_max_key_size to guarantee symmetric bidirectional flow hashing. If rss_max_key_size is larger than VIRTIO_NET_RSS_MAX_KEY_SIZE, clamping the value is not feasible.

I don't know what to tell you. rss_max_key_size is just the max device supports. driver should be free to use a smaller size.

Quoted 33 lines
Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Quoted 11 lines
drivers/net/virtio_net.c +3 -0
+		}
+	}
+
 	return 0;
 }
@@ -6839,13 +6860,6 @@ static int virtnet_probe(struct

virtio_device

*vdev)

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 	if (vi->has_rss || vi->has_rss_hash_report) {
 		vi->rss_key_size =
 			virtio_cread8(vdev, offsetof(struct virtio_net_config,

rss_max_key_size));

drivers/net/virtio_net.c

Quoted 2 lines
drivers/net/virtio_net.c +0 -2
-		if (vi->rss_key_size > VIRTIO_NET_RSS_MAX_KEY_SIZE) {
-			dev_err(&vdev->dev, "rss_max_key_size=%u exceeds

the limit %u.\n",

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-				vi->rss_key_size,

VIRTIO_NET_RSS_MAX_KEY_SIZE);

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)

Quoted 6 lines
drivers/net/virtio_net.c +0 -4
-			err = -EINVAL;
-			goto free;
-		}
-
 		vi->rss_hash_types_supported =
 		    virtio_cread32(vdev, offsetof(struct virtio_net_config,

supported_hash_types));

Quoted 3 lines

vi->rss_hash_types_supported &=
--
2.25.1

#22 lore raw
Quoted 131 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, February 25, 2026 6:07 PM
To: Srujana Challa <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nithin Kumar Dabilpuram <[email protected]>; Shiva Shankar Kommula <[email protected]>; [email protected]
Subject: Re: [EXTERNAL] Re: [PATCH net,v4,1/2] virtio_net: Improve RSS key size validation and use NETDEV_RSS_KEY_LEN

On Wed, Feb 25, 2026 at 12: 34: 28PM +0000, Srujana Challa wrote: > > > > On Tue, Feb 24, 2026 at 12: 28: 49PM +0530, Srujana Challa wrote: > > > > > Replace hardcoded RSS max key size limit with NETDEV_RSS_KEY_LEN > ZjQcmQRYFpfptBannerStart Prioritize security for external emails:
Confirm sender and content safety before clicking links or opening attachments <https://us-phishalarm-
ewt.proofpoint.com/EWT/v1/CRVmXkqW!tc3Z1f8UYnWatK- 8Wb36Dpr9FJXZMBwEugHj1xCGwRl- dNXM_I8Yk7hbbjwCHe9WhgQwmGx2Ms85fIkSmKM2dBQeH9Dkzak$>
Report Suspicious

ZjQcmQRYFpfptBannerEnd

Quoted 4 lines · Srujana Challa
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · Srujana Challa
Quoted 3 lines

Replace hardcoded RSS max key size limit with NETDEV_RSS_KEY_LEN to align with kernel's standard RSS key length. Add validation for RSS key size against spec minimum (40

bytes) and driver maximum.

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 6 lines

When validation fails, gracefully disable RSS features and continue initialization rather than failing completely.

Fixes 3f7d9c1964fc ("virtio_net: Add hash_key_length check")

--- should come here before changelog.

Quoted 6 lines

v3:
- Moved RSS key validation checks to virtnet_validate.
- Add fixes: tag and CC -stable
v4:
- Use NETDEV_RSS_KEY_LEN instead of type_max for the maximum rss key

size.

Quoted 20 lines
---
 drivers/net/virtio_net.c | 34
++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/drivers/net/virtio_net.c index
db88dcaefb20..eeefe8abc122 100644

drivers/net/virtio_net.c +0 -2
@@ -381,8 +381,6 @@ struct receive_queue {
 	struct xdp_buff **xsk_buffs;  };
 
-#define VIRTIO_NET_RSS_MAX_KEY_SIZE     40
-
 /* Control VQ buffers: protected by the rtnl lock */  struct
 control_buf {
 	struct virtio_net_ctrl_hdr hdr; @@ -486,7 +484,7 @@ struct
 virtnet_info {
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 	/* Must be last as it ends in a flexible-array member. */
 	TRAILING_OVERLAP(struct virtio_net_rss_config_trailer,

rss_trailer,

hash_key_data,

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-		u8

rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE];

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/net/virtio_net.c +1 -0
+		u8 rss_hash_key_data[NETDEV_RSS_KEY_LEN];
 	);
 };
 static_assert(offsetof(struct virtnet_info,

rss_trailer.hash_key_data) == @@ -6627,6 +6625,29 @@ static int

virtnet_validate(struct virtio_device *vdev)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 7 lines
drivers/net/virtio_net.c +4 -0
 		__virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY);
 	}
 
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS) ||
+	    virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) {
+		u8 key_sz = virtio_cread8(vdev,
+					  offsetof(struct

virtio_net_config,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 6 lines
drivers/net/virtio_net.c +6 -0
+						   rss_max_key_size));
+		/* Spec requires at least 40 bytes */ #define
+VIRTIO_NET_RSS_MIN_KEY_SIZE 40
+		if (key_sz < VIRTIO_NET_RSS_MIN_KEY_SIZE) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u is less than

spec

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

minimum %u, disabling RSS\n",

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +1 -0
+				 key_sz,

VIRTIO_NET_RSS_MIN_KEY_SIZE);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/net/virtio_net.c

Quoted 2 lines
drivers/net/virtio_net.c +2 -0
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 4 lines
drivers/net/virtio_net.c +4 -0
+		}
+		if (key_sz > NETDEV_RSS_KEY_LEN) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u exceeds driver

limit

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 9 lines

%u, disabling RSS\n",

drivers/net/virtio_net.c static int virtnet_validate(struct virtio_device *vdev)

Quoted 3 lines
drivers/net/virtio_net.c +3 -0
+				 key_sz, NETDEV_RSS_KEY_LEN);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

you flipped the logic here and it makes no sense now.

Did you test this path?

Yes, tested with Marvell's Octeon device.

Quoted 4 lines

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

The intent isn’t to disable the feature on capable devices, but to ensure the driver never advertises support for RSS key sizes larger than what the net device can actually handle. Even if a device reports a very

Quoted 6 lines
Quoted 6 lines

large key size, the driver is constrained by NETDEV_RSS_KEY_LEN, since
netdev_rss_key_fill() enforces:

Quoted 1 line

BUG_ON(len > sizeof(netdev_rss_key));

so cap it to NETDEV_RSS_KEY_LEN. Why is that a reason to clear the

Quoted 8 lines

feature?

Quoted 3 lines

Our device mandates that hash_key_length must be identical to rss_max_key_size to guarantee symmetric bidirectional flow hashing. If rss_max_key_size is larger than VIRTIO_NET_RSS_MAX_KEY_SIZE, clamping

the value is not feasible.

I don't know what to tell you. rss_max_key_size is just the max device supports. driver should be free to use a smaller size.

My understanding is that this patch prevents the probe from failing by disabling the feature instead. Given the current implementation, the driver becomes unusable when this condition is hit.

Quoted 39 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/virtio_net.c +3 -0
+		}
+	}
+
 	return 0;
 }
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
drivers/net/virtio_net.c +0 -0
@@ -6839,13 +6860,6 @@ static int virtnet_probe(struct

virtio_device

*vdev)

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 	if (vi->has_rss || vi->has_rss_hash_report) {
 		vi->rss_key_size =
 			virtio_cread8(vdev, offsetof(struct

virtio_net_config,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

rss_max_key_size));

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-		if (vi->rss_key_size >

VIRTIO_NET_RSS_MAX_KEY_SIZE) {

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-			dev_err(&vdev->dev, "rss_max_key_size=%u

exceeds

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

the limit %u.\n",

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-				vi->rss_key_size,

VIRTIO_NET_RSS_MAX_KEY_SIZE);

drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)

Quoted 6 lines
drivers/net/virtio_net.c +0 -4
-			err = -EINVAL;
-			goto free;
-		}
-
 		vi->rss_hash_types_supported =
 		    virtio_cread32(vdev, offsetof(struct

virtio_net_config,

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

supported_hash_types));

Quoted 3 lines

vi->rss_hash_types_supported &=
--
2.25.1

#23 lore raw
Quoted 4 lines · Srujana Challa
Quoted 2 lines

I don't know what to tell you. rss_max_key_size is just the max device supports. driver should be free to use a smaller size.

My understanding is that this patch prevents the probe from failing by disabling the feature instead. Given the current implementation, the driver becomes unusable when this condition is hit.

current implementation even more broken. but the real fix is to intepret max key size as max.

#24 lore raw
In reply to Srujana Challa
Quoted 137 lines
Quoted 12 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, February 25, 2026 6:07 PM
To: Srujana Challa <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nithin Kumar Dabilpuram <[email protected]>; Shiva Shankar Kommula <[email protected]>; [email protected]
Subject: Re: [EXTERNAL] Re: [PATCH net,v4,1/2] virtio_net: Improve RSS key size validation and use NETDEV_RSS_KEY_LEN

Quoted 4 lines

On Wed, Feb 25, 2026 at 12: 34: 28PM +0000, Srujana Challa wrote: > >

Quoted 2 lines
Quoted 2 lines · Srujana Challa
Quoted 1 line
Quoted 1 line
Quoted 1 line

Replace hardcoded RSS max key size limit with

NETDEV_RSS_KEY_LEN > ZjQcmQRYFpfptBannerStart Prioritize security for

external emails:

Quoted 120 lines

Confirm sender and content safety before clicking links or opening attachments <https://us-phishalarm-
ewt.proofpoint.com/EWT/v1/CRVmXkqW!tc3Z1f8UYnWatK- 8Wb36Dpr9FJXZMBwEugHj1xCGwRl- dNXM_I8Yk7hbbjwCHe9WhgQwmGx2Ms85fIkSmKM2dBQeH9Dkzak$> Report Suspicious

ZjQcmQRYFpfptBannerEnd

Quoted 5 lines · Srujana Challa
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Srujana Challa
Quoted 4 lines

Replace hardcoded RSS max key size limit with NETDEV_RSS_KEY_LEN to align with kernel's standard RSS key length. Add validation for RSS key size against spec minimum (40

bytes) and driver maximum.

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 7 lines

When validation fails, gracefully disable RSS features and continue initialization rather than failing completely.

Fixes 3f7d9c1964fc ("virtio_net: Add hash_key_length

check")

--- should come here before changelog.

Quoted 6 lines

v3:
- Moved RSS key validation checks to virtnet_validate.
- Add fixes: tag and CC -stable
v4:
- Use NETDEV_RSS_KEY_LEN instead of type_max for the maximum rss key

size.

Quoted 20 lines
---
 drivers/net/virtio_net.c | 34
++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/drivers/net/virtio_net.c index
db88dcaefb20..eeefe8abc122 100644

drivers/net/virtio_net.c +0 -2
@@ -381,8 +381,6 @@ struct receive_queue {
 	struct xdp_buff **xsk_buffs;  };
 
-#define VIRTIO_NET_RSS_MAX_KEY_SIZE     40
-
 /* Control VQ buffers: protected by the rtnl lock */
 struct control_buf {
 	struct virtio_net_ctrl_hdr hdr; @@ -486,7 +484,7 @@ struct
 virtnet_info {
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 	/* Must be last as it ends in a flexible-array member. */
 	TRAILING_OVERLAP(struct virtio_net_rss_config_trailer,

rss_trailer,

hash_key_data,

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-		u8

rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE];

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/net/virtio_net.c +1 -0
+		u8 rss_hash_key_data[NETDEV_RSS_KEY_LEN];
 	);
 };
 static_assert(offsetof(struct virtnet_info,

rss_trailer.hash_key_data) == @@ -6627,6 +6625,29 @@ static int

virtnet_validate(struct virtio_device *vdev)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/net/virtio_net.c

Quoted 7 lines
drivers/net/virtio_net.c +4 -0
 		__virtio_clear_bit(vdev, VIRTIO_NET_F_STANDBY);
 	}
 
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS) ||
+	    virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) {
+		u8 key_sz = virtio_cread8(vdev,
+					  offsetof(struct

virtio_net_config,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/net/virtio_net.c

Quoted 6 lines
drivers/net/virtio_net.c +6 -0
+						   rss_max_key_size));
+		/* Spec requires at least 40 bytes */ #define
+VIRTIO_NET_RSS_MIN_KEY_SIZE 40
+		if (key_sz < VIRTIO_NET_RSS_MIN_KEY_SIZE) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u is less than

spec

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

minimum %u, disabling RSS\n",

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +1 -0
+				 key_sz,

VIRTIO_NET_RSS_MIN_KEY_SIZE);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/net/virtio_net.c

Quoted 2 lines
drivers/net/virtio_net.c +2 -0
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

drivers/net/virtio_net.c

Quoted 4 lines
drivers/net/virtio_net.c +4 -0
+		}
+		if (key_sz > NETDEV_RSS_KEY_LEN) {
+			dev_warn(&vdev->dev,
+				 "rss_max_key_size=%u exceeds driver

limit

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 9 lines

%u, disabling RSS\n",

drivers/net/virtio_net.c

Quoted 3 lines
drivers/net/virtio_net.c +3 -0
+				 key_sz, NETDEV_RSS_KEY_LEN);
+			__virtio_clear_bit(vdev, VIRTIO_NET_F_RSS);
+			__virtio_clear_bit(vdev,

VIRTIO_NET_F_HASH_REPORT);

you flipped the logic here and it makes no sense now.

Did you test this path?

Yes, tested with Marvell's Octeon device.

Quoted 4 lines

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

The intent isn’t to disable the feature on capable devices, but to ensure the driver never advertises support for RSS key sizes larger than what the net device can actually handle. Even if a device reports a very

Quoted 6 lines
Quoted 6 lines

large key size, the driver is constrained by NETDEV_RSS_KEY_LEN, since
netdev_rss_key_fill() enforces:

Quoted 1 line

BUG_ON(len > sizeof(netdev_rss_key));

so cap it to NETDEV_RSS_KEY_LEN. Why is that a reason to clear the

feature?

Quoted 4 lines

Our device mandates that hash_key_length must be identical to rss_max_key_size to guarantee symmetric bidirectional flow hashing. If rss_max_key_size is larger than VIRTIO_NET_RSS_MAX_KEY_SIZE, clamping

Quoted 8 lines
Quoted 4 lines

the value is not feasible.

I don't know what to tell you. rss_max_key_size is just the max device supports. driver should be free to use a smaller size.

My understanding is that this patch prevents the probe from failing by disabling the feature instead.
Given the current implementation, the driver becomes unusable when this condition is hit.

I understand that the driver is allowed to use a smaller RSS key than the device’s advertised rss_max_key_size. But, our hardware does not behave correctly in that configuration. For symmetric bidirectional hashing, the device requires that the hash_key_length match rss_max_key_size exactly.
If the driver uses a smaller key, the hardware produces inconsistent hash values for forward vs reverse flows. Because of this device requirement, we cannot cap the key to NETDEV_RSS_KEY_LEN when the device advertises a larger rss_max_key_size.

Quoted 39 lines
Quoted 39 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/virtio_net.c +3 -0
+		}
+	}
+
 	return 0;
 }
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
drivers/net/virtio_net.c +0 -0
@@ -6839,13 +6860,6 @@ static int virtnet_probe(struct

virtio_device

*vdev)

Quoted 3 lines
drivers/net/virtio_net.c +0 -0
 	if (vi->has_rss || vi->has_rss_hash_report) {
 		vi->rss_key_size =
 			virtio_cread8(vdev, offsetof(struct

virtio_net_config,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

rss_max_key_size));

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-		if (vi->rss_key_size >

VIRTIO_NET_RSS_MAX_KEY_SIZE) {

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-			dev_err(&vdev->dev, "rss_max_key_size=%u

exceeds

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

the limit %u.\n",

drivers/net/virtio_net.c

Quoted 1 line
drivers/net/virtio_net.c +0 -1
-				vi->rss_key_size,

VIRTIO_NET_RSS_MAX_KEY_SIZE);

drivers/net/virtio_net.c

Quoted 6 lines
drivers/net/virtio_net.c +0 -4
-			err = -EINVAL;
-			goto free;
-		}
-
 		vi->rss_hash_types_supported =
 		    virtio_cread32(vdev, offsetof(struct

virtio_net_config,

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

supported_hash_types));

Quoted 3 lines

vi->rss_hash_types_supported &=
--
2.25.1

#25 lore raw
Quoted 28 lines · Srujana Challa
Quoted 19 lines
Quoted 19 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

The intent isn’t to disable the feature on capable devices, but to ensure the driver never advertises support for RSS key sizes larger than what the net device can actually handle. Even if a device reports a very

Quoted 6 lines
Quoted 6 lines

large key size, the driver is constrained by NETDEV_RSS_KEY_LEN, since
netdev_rss_key_fill() enforces:

Quoted 1 line

BUG_ON(len > sizeof(netdev_rss_key));

so cap it to NETDEV_RSS_KEY_LEN. Why is that a reason to clear the

feature?

Quoted 4 lines

Our device mandates that hash_key_length must be identical to rss_max_key_size to guarantee symmetric bidirectional flow hashing. If rss_max_key_size is larger than VIRTIO_NET_RSS_MAX_KEY_SIZE, clamping

Quoted 8 lines
Quoted 4 lines

the value is not feasible.

I don't know what to tell you. rss_max_key_size is just the max device supports. driver should be free to use a smaller size.

My understanding is that this patch prevents the probe from failing by disabling the feature instead.
Given the current implementation, the driver becomes unusable when this condition is hit.

Quoted 6 lines

I understand that the driver is allowed to use a smaller RSS key than the device’s advertised rss_max_key_size. But, our hardware does not behave correctly in that configuration. For symmetric bidirectional hashing, the device requires that the hash_key_length match rss_max_key_size exactly.
If the driver uses a smaller key, the hardware produces inconsistent hash values for forward vs reverse flows. Because of this device requirement, we cannot cap the key to NETDEV_RSS_KEY_LEN when the device advertises a larger rss_max_key_size.

Would you not say it's a buggy device then?

Signature · 1 line
MST
#26 lore raw
Quoted 34 lines · Srujana Challa
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

The intent isn’t to disable the feature on capable devices, but to ensure the driver never advertises support for RSS key sizes larger than what the net device can actually handle. Even if a device reports a very

Quoted 7 lines
Quoted 7 lines

large key size, the driver is constrained by
NETDEV_RSS_KEY_LEN, since
netdev_rss_key_fill() enforces:

Quoted 1 line

BUG_ON(len > sizeof(netdev_rss_key));

so cap it to NETDEV_RSS_KEY_LEN. Why is that a reason to clear the

feature?

Quoted 4 lines

Our device mandates that hash_key_length must be identical to rss_max_key_size to guarantee symmetric bidirectional flow hashing. If rss_max_key_size is larger than VIRTIO_NET_RSS_MAX_KEY_SIZE, clamping

the value is not feasible.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I don't know what to tell you. rss_max_key_size is just the max device supports. driver should be free to use a smaller size.

My understanding is that this patch prevents the probe from failing by disabling the feature instead.
Given the current implementation, the driver becomes unusable when this condition is hit.

I understand that the driver is allowed to use a smaller RSS key than the

device’s advertised rss_max_key_size.

Quoted 2 lines

But, our hardware does not behave correctly in that configuration. For symmetric bidirectional hashing, the device requires that the

Quoted 8 lines

hash_key_length match rss_max_key_size exactly.

Quoted 1 line

If the driver uses a smaller key, the hardware produces inconsistent hash

values for forward vs reverse flows.

Quoted 2 lines

Because of this device requirement, we cannot cap the key to NETDEV_RSS_KEY_LEN when the device advertises a larger

rss_max_key_size.

Would you not say it's a buggy device then?

No. The device works correctly when a smaller key is used. The limitation only affects symmetric bidirectional hashing. For the other use cases capping the key size is fine.

Quoted 3 lines

--
MST

#27 lore raw
Quoted 36 lines · Srujana Challa
Quoted 36 lines · Srujana Challa
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

The intent isn’t to disable the feature on capable devices, but to ensure the driver never advertises support for RSS key sizes larger than what the net device can actually handle. Even if a device reports a very

Quoted 7 lines
Quoted 7 lines

large key size, the driver is constrained by
NETDEV_RSS_KEY_LEN, since
netdev_rss_key_fill() enforces:

Quoted 1 line

BUG_ON(len > sizeof(netdev_rss_key));

so cap it to NETDEV_RSS_KEY_LEN. Why is that a reason to clear the

feature?

Quoted 4 lines

Our device mandates that hash_key_length must be identical to rss_max_key_size to guarantee symmetric bidirectional flow hashing. If rss_max_key_size is larger than VIRTIO_NET_RSS_MAX_KEY_SIZE, clamping

the value is not feasible.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I don't know what to tell you. rss_max_key_size is just the max device supports. driver should be free to use a smaller size.

My understanding is that this patch prevents the probe from failing by disabling the feature instead.
Given the current implementation, the driver becomes unusable when this condition is hit.

I understand that the driver is allowed to use a smaller RSS key than the

device’s advertised rss_max_key_size.

Quoted 2 lines

But, our hardware does not behave correctly in that configuration. For symmetric bidirectional hashing, the device requires that the

hash_key_length match rss_max_key_size exactly.

Quoted 1 line

If the driver uses a smaller key, the hardware produces inconsistent hash

Quoted 8 lines
Quoted 6 lines

values for forward vs reverse flows.

Quoted 2 lines

Because of this device requirement, we cannot cap the key to NETDEV_RSS_KEY_LEN when the device advertises a larger

rss_max_key_size.

Would you not say it's a buggy device then?

No. The device works correctly when a smaller key is used. The limitation only affects symmetric bidirectional hashing. For the other use cases capping the key size is fine.

yes the device seems buggy in that configuration, in that it has this requirement which does not seem to be in the spec.

so tell me, what is the actual rss_max_key_size of that device?

Quoted 4 lines
Quoted 3 lines

--
MST

#28 lore raw
Quoted 50 lines

ZjQcmQRYFpfptBannerEnd

Quoted 13 lines · Srujana Challa
Quoted 13 lines · Srujana Challa
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 9 lines
Quoted 4 lines

So if device is powerful and supports a very big key size then... we disable the feature? how does this make sense?

The intent isn’t to disable the feature on capable devices, but to ensure the driver never advertises support for RSS key sizes larger than what the net device can actually handle. Even if a device reports a very

large key size, the driver is constrained by
NETDEV_RSS_KEY_LEN, since
netdev_rss_key_fill() enforces:

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

BUG_ON(len > sizeof(netdev_rss_key));

so cap it to NETDEV_RSS_KEY_LEN. Why is that a reason to clear the

feature?

Quoted 2 lines

Our device mandates that hash_key_length must be identical to rss_max_key_size to guarantee symmetric bidirectional flow

hashing.

Quoted 19 lines
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

If rss_max_key_size is larger than
VIRTIO_NET_RSS_MAX_KEY_SIZE, clamping

the value is not feasible.

I don't know what to tell you. rss_max_key_size is just the max device supports. driver should be free to use a smaller size.

Quoted 7 lines
Quoted 4 lines

My understanding is that this patch prevents the probe from failing by disabling the feature instead.
Given the current implementation, the driver becomes unusable when this condition is hit.

I understand that the driver is allowed to use a smaller RSS key than the

device’s advertised rss_max_key_size.

Quoted 2 lines

But, our hardware does not behave correctly in that configuration. For symmetric bidirectional hashing, the device requires that the

hash_key_length match rss_max_key_size exactly.

Quoted 2 lines

If the driver uses a smaller key, the hardware produces inconsistent hash

Quoted 8 lines
Quoted 6 lines

values for forward vs reverse flows.

Quoted 2 lines

Because of this device requirement, we cannot cap the key to NETDEV_RSS_KEY_LEN when the device advertises a larger

rss_max_key_size.

Would you not say it's a buggy device then?

No. The device works correctly when a smaller key is used. The limitation only affects symmetric bidirectional hashing. For the other use

Quoted 8 lines

cases capping the key size is fine.

yes the device seems buggy in that configuration, in that it has this requirement which does not seem to be in the spec.

so tell me, what is the actual rss_max_key_size of that device?

We've confirmed our device works with clamping the key size. Our device's rss_max_key_size is 48 bytes. We will update the patch to use min(device rss_max_key_size, NETDEV_RSS_KEY_LEN) and drop the logic that disables RSS when "device rss_max_key_size > NETDEV_RSS_KEY_LEN" . And also drop the patch2. Will send a revised patch shortly.

Thanks!

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

--
MST