Re: [PATCH] virtio_net: Use NETDEV_TX_BUSY when has no buf to send
From: Yunsheng Lin
Date: Thu Mar 09 2023 - 05:52:43 EST
On 2023/3/9 15:49, Angus Chen wrote:
> Don't consume skb if virtqueue_add return -ENOSPC.
Is this fixing the same out of space problem caused by
xdp xmit as Xuan Zhuo is fixing, or it is fixing a different
case?
https://lore.kernel.org/netdev/20230308071921-mutt-send-email-mst@xxxxxxxxxx/T/#mc4c5766a59fb8be988bb6a4dfa48f49e58df3ea6
>
> Signed-off-by: Angus Chen <angus.chen@xxxxxxxxxxxxxxx>
> ---
> drivers/net/virtio_net.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index fb5e68ed3ec2..4096ea3d2eb6 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -1980,7 +1980,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
> qnum, err);
> dev->stats.tx_dropped++;
> dev_kfree_skb_any(skb);
Returning NETDEV_TX_BUSY will caused stack to requeue the skb
and send it again when space is available, but you have freed the skb here,
isn't this cause use-after-free problem?
> - return NETDEV_TX_OK;
> + return (err == -ENOSPC) ? NETDEV_TX_BUSY : NETDEV_TX_OK;
> }
>
> /* Don't wait up for transmitted skbs to be freed. */
>