Skip to contentSkip to conversation

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

PATCH Applied Jason Wang 3 participants 3 messages Dec 1, 2014 – Dec 6, 2014

Subsystems (3)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH v4 1/1 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.

---
Changes from V3:
- rebase to net-next.git
Changes from V2:
- use unlikely() when necessary
Changes from V1:
- check the return value of tun/macvtap_put_user()

---
 drivers/net/macvtap.c | 5 ++++-
 drivers/net/tun.c     | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/net/macvtap.c +4 -1
index 22b4cf2..ba1e5db 100644
@@ -859,7 +859,10 @@ static ssize_t macvtap_do_read(struct macvtap_queue *q,
 	}
 	if (skb) {
 		ret = macvtap_put_user(q, skb, to);
-		kfree_skb(skb);
+		if (unlikely(ret < 0))
+			kfree_skb(skb);
+		else
+			consume_skb(skb);
 	}
 	if (!noblock)
 		finish_wait(sk_sleep(&q->sk), &wait);
drivers/net/tun.c +4 -1
index 6d44da1..9c58286 100644
@@ -1362,7 +1362,10 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
 		return 0;
 
 	ret = tun_put_user(tun, tfile, skb, to);
-	kfree_skb(skb);
+	if (unlikely(ret < 0))
+		kfree_skb(skb);
+	else
+		consume_skb(skb);
 
 	return ret;
 }
Signature · 1 line
1.9.1
Acked-by on v4 1/1
#1 lore raw
Quoted 5 lines · Jason Wang

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.

Quoted 46 lines

---
Changes from V3:
- rebase to net-next.git
Changes from V2:
- use unlikely() when necessary
Changes from V1:
- check the return value of tun/macvtap_put_user()

---
 drivers/net/macvtap.c | 5 ++++-
 drivers/net/tun.c     | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/net/macvtap.c +4 -1
index 22b4cf2..ba1e5db 100644
@@ -859,7 +859,10 @@ static ssize_t macvtap_do_read(struct macvtap_queue *q,
 	}
 	if (skb) {
 		ret = macvtap_put_user(q, skb, to);
-		kfree_skb(skb);
+		if (unlikely(ret < 0))
+			kfree_skb(skb);
+		else
+			consume_skb(skb);
 	}
 	if (!noblock)
 		finish_wait(sk_sleep(&q->sk), &wait);
drivers/net/tun.c +4 -1
index 6d44da1..9c58286 100644
@@ -1362,7 +1362,10 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
 		return 0;
 
 	ret = tun_put_user(tun, tfile, skb, to);
-	kfree_skb(skb);
+	if (unlikely(ret < 0))
+		kfree_skb(skb);
+	else
+		consume_skb(skb);
 
 	return ret;
 }
Signature · 1 line
1.9.1