[RFC PATCH net 3/3] virtio-net: block ethtool from converting a ring to a small ring

From: Alvaro Karsz
Date: Sun Apr 30 2023 - 09:15:59 EST


Stop ethtool from resizing a TX/RX ring to size less than
MAX_SKB_FRAGS + 2, if the ring was initialized with a bigger size.

We cannot convert a "normal" ring to a "small" ring in runtime.

Signed-off-by: Alvaro Karsz <alvaro.karsz@xxxxxxxxxxxxx>
---
drivers/net/virtio_net.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index b4441d63890..b8238eaa1e4 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2071,6 +2071,12 @@ static int virtnet_rx_resize(struct virtnet_info *vi,
bool running = netif_running(vi->dev);
int err, qindex;

+ /* We cannot convert a ring to a small vring */
+ if (!vi->svring && IS_SMALL_VRING(ring_num)) {
+ netdev_err(vi->dev, "resize rx fail: size is too small..\n");
+ return -EINVAL;
+ }
+
qindex = rq - vi->rq;

if (running)
@@ -2097,6 +2103,12 @@ static int virtnet_tx_resize(struct virtnet_info *vi,

qindex = sq - vi->sq;

+ /* We cannot convert a ring to a small vring */
+ if (!vi->svring && IS_SMALL_VRING(ring_num)) {
+ netdev_err(vi->dev, "resize tx fail: size is too small..\n");
+ return -EINVAL;
+ }
+
if (running)
virtnet_napi_tx_disable(&sq->napi);

--
2.34.1