Skip to content

Commit b4e5f04

Browse files
SruChallakuba-moo
authored andcommitted
virtio_net: clamp rss_max_key_size to NETDEV_RSS_KEY_LEN
rss_max_key_size in the virtio spec is the maximum key size supported by the device, not a mandatory size the driver must use. Also the value 40 is a spec minimum, not a spec maximum. The current code rejects RSS and can fail probe when the device reports a larger rss_max_key_size than the driver buffer limit. Instead, clamp the effective key length to min(device rss_max_key_size, NETDEV_RSS_KEY_LEN) and keep RSS enabled. This keeps probe working on devices that advertise larger maximum key sizes while respecting the netdev RSS key buffer size limit. Fixes: 3f7d9c1 ("virtio_net: Add hash_key_length check") Cc: [email protected] Signed-off-by: Srujana Challa <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d64cb81 commit b4e5f04

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

drivers/net/virtio_net.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,6 @@ struct receive_queue {
381381
struct xdp_buff **xsk_buffs;
382382
};
383383

384-
#define VIRTIO_NET_RSS_MAX_KEY_SIZE 40
385-
386384
/* Control VQ buffers: protected by the rtnl lock */
387385
struct control_buf {
388386
struct virtio_net_ctrl_hdr hdr;
@@ -486,7 +484,7 @@ struct virtnet_info {
486484

487485
/* Must be last as it ends in a flexible-array member. */
488486
TRAILING_OVERLAP(struct virtio_net_rss_config_trailer, rss_trailer, hash_key_data,
489-
u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE];
487+
u8 rss_hash_key_data[NETDEV_RSS_KEY_LEN];
490488
);
491489
};
492490
static_assert(offsetof(struct virtnet_info, rss_trailer.hash_key_data) ==
@@ -6708,6 +6706,7 @@ static int virtnet_probe(struct virtio_device *vdev)
67086706
struct virtnet_info *vi;
67096707
u16 max_queue_pairs;
67106708
int mtu = 0;
6709+
u16 key_sz;
67116710

67126711
/* Find if host supports multiqueue/rss virtio_net device */
67136712
max_queue_pairs = 1;
@@ -6842,14 +6841,13 @@ static int virtnet_probe(struct virtio_device *vdev)
68426841
}
68436842

68446843
if (vi->has_rss || vi->has_rss_hash_report) {
6845-
vi->rss_key_size =
6846-
virtio_cread8(vdev, offsetof(struct virtio_net_config, rss_max_key_size));
6847-
if (vi->rss_key_size > VIRTIO_NET_RSS_MAX_KEY_SIZE) {
6848-
dev_err(&vdev->dev, "rss_max_key_size=%u exceeds the limit %u.\n",
6849-
vi->rss_key_size, VIRTIO_NET_RSS_MAX_KEY_SIZE);
6850-
err = -EINVAL;
6851-
goto free;
6852-
}
6844+
key_sz = virtio_cread8(vdev, offsetof(struct virtio_net_config, rss_max_key_size));
6845+
6846+
vi->rss_key_size = min_t(u16, key_sz, NETDEV_RSS_KEY_LEN);
6847+
if (key_sz > vi->rss_key_size)
6848+
dev_warn(&vdev->dev,
6849+
"rss_max_key_size=%u exceeds driver limit %u, clamping\n",
6850+
key_sz, vi->rss_key_size);
68536851

68546852
vi->rss_hash_types_supported =
68556853
virtio_cread32(vdev, offsetof(struct virtio_net_config, supported_hash_types));

0 commit comments

Comments
 (0)