From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alvaro Karsz <alvaro.karsz@solid-run.com>
Cc: jasowang@redhat.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com,
virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] virtio-net: reject small vring sizes
Date: Sun, 16 Apr 2023 16:38:11 -0400 [thread overview]
Message-ID: <20230416163751-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230416074607.292616-1-alvaro.karsz@solid-run.com>
On Sun, Apr 16, 2023 at 10:46:07AM +0300, Alvaro Karsz wrote:
> Check vring size and fail probe if a transmit/receive vring size is
> smaller than MAX_SKB_FRAGS + 2.
>
> At the moment, any vring size is accepted. This is problematic because
> it may result in attempting to transmit a packet with more fragments
> than there are descriptors in the ring.
>
> Furthermore, it leads to an immediate bug:
>
> The condition: (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) in
> virtnet_poll_cleantx and virtnet_poll_tx always evaluates to false,
> so netif_tx_wake_queue is not called, leading to TX timeouts.
>
> Signed-off-by: Alvaro Karsz <alvaro.karsz@solid-run.com>
> ---
> drivers/net/virtio_net.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 2396c28c012..59676252c5c 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -3745,6 +3745,26 @@ static int init_vqs(struct virtnet_info *vi)
> return ret;
> }
>
> +static int virtnet_validate_vqs(struct virtnet_info *vi)
> +{
> + u32 i, min_size = roundup_pow_of_two(MAX_SKB_FRAGS + 2);
why power of two?
> +
> + /* Transmit/Receive vring size must be at least MAX_SKB_FRAGS + 2
> + * (fragments + linear part + virtio header)
> + */
> + for (i = 0; i < vi->max_queue_pairs; i++) {
> + if (virtqueue_get_vring_size(vi->sq[i].vq) < min_size ||
> + virtqueue_get_vring_size(vi->rq[i].vq) < min_size) {
> + dev_warn(&vi->vdev->dev,
> + "Transmit/Receive virtqueue vring size must be at least %u\n",
> + min_size);
> + return -EINVAL;
> + }
> + }
> +
> + return 0;
> +}
> +
> #ifdef CONFIG_SYSFS
> static ssize_t mergeable_rx_buffer_size_show(struct netdev_rx_queue *queue,
> char *buf)
> @@ -4056,6 +4076,10 @@ static int virtnet_probe(struct virtio_device *vdev)
> if (err)
> goto free;
>
> + err = virtnet_validate_vqs(vi);
> + if (err)
> + goto free_vqs;
> +
> #ifdef CONFIG_SYSFS
> if (vi->mergeable_rx_bufs)
> dev->sysfs_rx_queue_group = &virtio_net_mrg_rx_group;
> --
> 2.34.1
next prev parent reply other threads:[~2023-04-16 20:40 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-16 7:46 [PATCH net] virtio-net: reject small vring sizes Alvaro Karsz
2023-04-16 16:54 ` Alvaro Karsz
2023-04-16 20:45 ` Michael S. Tsirkin
2023-04-17 3:24 ` Jason Wang
2023-04-17 6:20 ` Michael S. Tsirkin
2023-04-17 6:38 ` Alvaro Karsz
2023-04-17 6:41 ` Michael S. Tsirkin
2023-04-17 7:03 ` Alvaro Karsz
2023-04-17 7:10 ` Michael S. Tsirkin
2023-04-17 7:33 ` Alvaro Karsz
2023-04-17 9:20 ` Michael S. Tsirkin
2023-04-17 10:04 ` Alvaro Karsz
2023-04-17 11:40 ` Michael S. Tsirkin
2023-04-17 11:51 ` Alvaro Karsz
2023-04-17 11:57 ` Michael S. Tsirkin
2023-04-23 6:51 ` Alvaro Karsz
2023-04-23 7:19 ` Michael S. Tsirkin
2023-04-23 7:52 ` Alvaro Karsz
2023-04-23 11:06 ` Michael S. Tsirkin
2023-04-23 12:28 ` Alvaro Karsz
2023-04-23 20:17 ` Michael S. Tsirkin
2023-04-25 8:34 ` Michael S. Tsirkin
2023-04-25 9:41 ` Alvaro Karsz
2023-04-25 11:11 ` Alvaro Karsz
2023-04-25 12:33 ` Michael S. Tsirkin
2023-04-25 12:31 ` Michael S. Tsirkin
2023-04-25 13:02 ` Alvaro Karsz
2023-04-25 13:08 ` Michael S. Tsirkin
2023-04-23 8:01 ` Alvaro Karsz
2023-04-23 11:08 ` Michael S. Tsirkin
2023-04-17 6:44 ` Xuan Zhuo
2023-04-17 7:07 ` Alvaro Karsz
2023-04-17 7:11 ` Michael S. Tsirkin
2023-04-16 20:38 ` Michael S. Tsirkin [this message]
2023-04-17 6:43 ` Alvaro Karsz
2023-04-23 11:09 ` Michael S. Tsirkin
2023-04-17 1:53 ` Xuan Zhuo
2023-04-17 6:47 ` Alvaro Karsz
2023-04-17 3:34 ` Xuan Zhuo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230416163751-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=alvaro.karsz@solid-run.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).