All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] tun: fix ubuf refcount incorrectly on error path
@ 2020-12-03  8:00 wangyunjian
  2020-12-04  6:10   ` Jason Wang
  2020-12-09 12:41 ` [PATCH net v2] " wangyunjian
  0 siblings, 2 replies; 28+ messages in thread
From: wangyunjian @ 2020-12-03  8:00 UTC (permalink / raw)
  To: mst, jasowang
  Cc: virtualization, netdev, jerry.lilijun, xudingke, Yunjian Wang

From: Yunjian Wang <wangyunjian@huawei.com>

After setting callback for ubuf_info of skb, the callback
(vhost_net_zerocopy_callback) will be called to decrease
the refcount when freeing skb. But when an exception occurs
afterwards, the error handling in vhost handle_tx() will
try to decrease the same refcount again. This is wrong and
fix this by clearing ubuf_info when meeting errors.

Fixes: 4477138fa0ae ("tun: properly test for IFF_UP")
Fixes: 90e33d459407 ("tun: enable napi_gro_frags() for TUN/TAP driver")

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/tun.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 2dc1988a8973..3614bb1b6d35 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1861,6 +1861,12 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 	if (unlikely(!(tun->dev->flags & IFF_UP))) {
 		err = -EIO;
 		rcu_read_unlock();
+		if (zerocopy) {
+			skb_shinfo(skb)->destructor_arg = NULL;
+			skb_shinfo(skb)->tx_flags &= ~SKBTX_DEV_ZEROCOPY;
+			skb_shinfo(skb)->tx_flags &= ~SKBTX_SHARED_FRAG;
+		}
+
 		goto drop;
 	}
 
@@ -1874,6 +1880,11 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 
 		if (unlikely(headlen > skb_headlen(skb))) {
 			atomic_long_inc(&tun->dev->rx_dropped);
+			if (zerocopy) {
+				skb_shinfo(skb)->destructor_arg = NULL;
+				skb_shinfo(skb)->tx_flags &= ~SKBTX_DEV_ZEROCOPY;
+				skb_shinfo(skb)->tx_flags &= ~SKBTX_SHARED_FRAG;
+			}
 			napi_free_frags(&tfile->napi);
 			rcu_read_unlock();
 			mutex_unlock(&tfile->napi_mutex);
-- 
2.18.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2020-12-14  6:57 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03  8:00 [PATCH net-next] tun: fix ubuf refcount incorrectly on error path wangyunjian
2020-12-04  6:10 ` Jason Wang
2020-12-04  6:10   ` Jason Wang
2020-12-04 10:22   ` wangyunjian
2020-12-07  3:54     ` Jason Wang
2020-12-07  3:54       ` Jason Wang
2020-12-07 13:38       ` wangyunjian
2020-12-08  2:32         ` Jason Wang
2020-12-08  2:32           ` Jason Wang
2020-12-09  9:30           ` Jason Wang
2020-12-09  9:30             ` Jason Wang
2020-12-09 12:41 ` [PATCH net v2] " wangyunjian
2020-12-09 14:43   ` Willem de Bruijn
2020-12-09 14:43     ` Willem de Bruijn
2020-12-12  6:43     ` wangyunjian
2020-12-13  0:17       ` Willem de Bruijn
2020-12-13  0:17         ` Willem de Bruijn
2020-12-14  1:32         ` Willem de Bruijn
2020-12-14  1:32           ` Willem de Bruijn
2020-12-14  3:30           ` Jason Wang
2020-12-14  3:30             ` Jason Wang
2020-12-14  3:54             ` Willem de Bruijn
2020-12-14  3:54               ` Willem de Bruijn
2020-12-14  3:56               ` Willem de Bruijn
2020-12-14  3:56                 ` Willem de Bruijn
2020-12-14  4:06                 ` Jason Wang
2020-12-14  4:06                   ` Jason Wang
2020-12-14  6:56                   ` wangyunjian

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.