diff mbox series

virtio_net: Use NETDEV_TX_BUSY when has no buf to send

Message ID 20230309074952.975-1-angus.chen@jaguarmicro.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series virtio_net: Use NETDEV_TX_BUSY when has no buf to send | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 20 this patch: 20
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 20 this patch: 20
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Angus Chen March 9, 2023, 7:49 a.m. UTC
Don't consume skb if virtqueue_add return -ENOSPC.

Signed-off-by: Angus Chen <angus.chen@jaguarmicro.com>
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yunsheng Lin March 9, 2023, 10:52 a.m. UTC | #1
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@kernel.org/T/#mc4c5766a59fb8be988bb6a4dfa48f49e58df3ea6

> 
> Signed-off-by: Angus Chen <angus.chen@jaguarmicro.com>
> ---
>  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. */
>
Angus Chen March 9, 2023, 12:26 p.m. UTC | #2
Hi 

> -----Original Message-----
> From: Yunsheng Lin <linyunsheng@huawei.com>
> Sent: Thursday, March 9, 2023 6:53 PM
> To: Angus Chen <angus.chen@jaguarmicro.com>; mst@redhat.com;
> jasowang@redhat.com; davem@davemloft.net; edumazet@google.com;
> kuba@kernel.org; pabeni@redhat.com; ast@kernel.org; daniel@iogearbox.net;
> hawk@kernel.org; john.fastabend@gmail.com
> Cc: virtualization@lists.linux-foundation.org; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org; bpf@vger.kernel.org; Xuan Zhuo
> <xuanzhuo@linux.alibaba.com>
> Subject: Re: [PATCH] virtio_net: Use NETDEV_TX_BUSY when has no buf to send
> 
> 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?
Yes, the same print info.
> 
> https://lore.kernel.org/netdev/20230308071921-mutt-send-email-mst@kernel.
> org/T/#mc4c5766a59fb8be988bb6a4dfa48f49e58df3ea6
> 
En,I haven't noticed this patch before.
> >
> > Signed-off-by: Angus Chen <angus.chen@jaguarmicro.com>
> > ---
> >  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?
Yes,you are right, would be crash after I tested more times .I will drop it,thank you.
> 
> > -		return NETDEV_TX_OK;
> > +		return (err == -ENOSPC) ? NETDEV_TX_BUSY : NETDEV_TX_OK;
> >  	}
> >
> >  	/* Don't wait up for transmitted skbs to be freed. */
> >
diff mbox series

Patch

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);
-		return NETDEV_TX_OK;
+		return (err == -ENOSPC) ? NETDEV_TX_BUSY : NETDEV_TX_OK;
 	}
 
 	/* Don't wait up for transmitted skbs to be freed. */