Browse Source

tun/macvtap: use consume_skb() instead of kfree_skb() when needed

To be more friendly with drop monitor, we should only call kfree_skb() when
the packets were dropped and use consume_skb() in other cases.

Cc: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Jason Wang 10 years ago
parent
commit
f51a5e82ea
2 changed files with 8 additions and 2 deletions
  1. 4 1
      drivers/net/macvtap.c
  2. 4 1
      drivers/net/tun.c

+ 4 - 1
drivers/net/macvtap.c

@@ -859,7 +859,10 @@ static ssize_t macvtap_do_read(struct macvtap_queue *q,
 	}
 	}
 	if (skb) {
 	if (skb) {
 		ret = macvtap_put_user(q, skb, to);
 		ret = macvtap_put_user(q, skb, to);
-		kfree_skb(skb);
+		if (unlikely(ret < 0))
+			kfree_skb(skb);
+		else
+			consume_skb(skb);
 	}
 	}
 	if (!noblock)
 	if (!noblock)
 		finish_wait(sk_sleep(&q->sk), &wait);
 		finish_wait(sk_sleep(&q->sk), &wait);

+ 4 - 1
drivers/net/tun.c

@@ -1362,7 +1362,10 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
 		return 0;
 		return 0;
 
 
 	ret = tun_put_user(tun, tfile, skb, to);
 	ret = tun_put_user(tun, tfile, skb, to);
-	kfree_skb(skb);
+	if (unlikely(ret < 0))
+		kfree_skb(skb);
+	else
+		consume_skb(skb);
 
 
 	return ret;
 	return ret;
 }
 }