Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1677544 > unrolled thread

[PATCH net] net: handle NAPI_GRO_FREE_STOLEN_HEAD case also in napi_frags_finish()

Started byMichal Kubecek <mkubecek@suse.cz>
First post2017-06-29 11:20 +0200
Last post2017-06-29 22:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH net] net: handle NAPI_GRO_FREE_STOLEN_HEAD case also in  napi_frags_finish() Michal Kubecek <mkubecek@suse.cz> - 2017-06-29 11:20 +0200
    Re: [PATCH net] net: handle NAPI_GRO_FREE_STOLEN_HEAD case also in  napi_frags_finish() David Miller <davem@davemloft.net> - 2017-06-29 22:00 +0200

#1677544 — [PATCH net] net: handle NAPI_GRO_FREE_STOLEN_HEAD case also in napi_frags_finish()

FromMichal Kubecek <mkubecek@suse.cz>
Date2017-06-29 11:20 +0200
Subject[PATCH net] net: handle NAPI_GRO_FREE_STOLEN_HEAD case also in napi_frags_finish()
Message-ID<tXDMd-5II-1@gated-at.bofh.it>
Recently I started seeing warnings about pages with refcount -1. The
problem was traced to packets being reused after their head was merged into
a GRO packet by skb_gro_receive(). While bisecting the issue pointed to
commit c21b48cc1bbf ("net: adjust skb->truesize in ___pskb_trim()") and
I have never seen it on a kernel with it reverted, I believe the real
problem appeared earlier when the option to merge head frag in GRO was
implemented.

Handling NAPI_GRO_FREE_STOLEN_HEAD state was only added to GRO_MERGED_FREE
branch of napi_skb_finish() so that if the driver uses napi_gro_frags()
and head is merged (which in my case happens after the skb_condense()
call added by the commit mentioned above), the skb is reused including the
head that has been merged. As a result, we release the page reference
twice and eventually end up with negative page refcount.

To fix the problem, handle NAPI_GRO_FREE_STOLEN_HEAD in napi_frags_finish()
the same way it's done in napi_skb_finish().

Fixes: d7e8883cfcf4 ("net: make GRO aware of skb->head_frag")
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 net/core/dev.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 91bb55070533..416137c64bf8 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4767,6 +4767,13 @@ struct packet_offload *gro_find_complete_by_type(__be16 type)
 }
 EXPORT_SYMBOL(gro_find_complete_by_type);
 
+static void napi_skb_free_stolen_head(struct sk_buff *skb)
+{
+	skb_dst_drop(skb);
+	secpath_reset(skb);
+	kmem_cache_free(skbuff_head_cache, skb);
+}
+
 static gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)
 {
 	switch (ret) {
@@ -4780,13 +4787,10 @@ static gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)
 		break;
 
 	case GRO_MERGED_FREE:
-		if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD) {
-			skb_dst_drop(skb);
-			secpath_reset(skb);
-			kmem_cache_free(skbuff_head_cache, skb);
-		} else {
+		if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD)
+			napi_skb_free_stolen_head(skb);
+		else
 			__kfree_skb(skb);
-		}
 		break;
 
 	case GRO_HELD:
@@ -4858,10 +4862,16 @@ static gro_result_t napi_frags_finish(struct napi_struct *napi,
 		break;
 
 	case GRO_DROP:
-	case GRO_MERGED_FREE:
 		napi_reuse_skb(napi, skb);
 		break;
 
+	case GRO_MERGED_FREE:
+		if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD)
+			napi_skb_free_stolen_head(skb);
+		else
+			napi_reuse_skb(napi, skb);
+		break;
+
 	case GRO_MERGED:
 	case GRO_CONSUMED:
 		break;
-- 
2.13.2

[toc] | [next] | [standalone]


#1678143

FromDavid Miller <davem@davemloft.net>
Date2017-06-29 22:00 +0200
Message-ID<tXNLA-3oJ-15@gated-at.bofh.it>
In reply to#1677544
From: Michal Kubecek <mkubecek@suse.cz>
Date: Thu, 29 Jun 2017 11:13:36 +0200 (CEST)

> Recently I started seeing warnings about pages with refcount -1. The
> problem was traced to packets being reused after their head was merged into
> a GRO packet by skb_gro_receive(). While bisecting the issue pointed to
> commit c21b48cc1bbf ("net: adjust skb->truesize in ___pskb_trim()") and
> I have never seen it on a kernel with it reverted, I believe the real
> problem appeared earlier when the option to merge head frag in GRO was
> implemented.
> 
> Handling NAPI_GRO_FREE_STOLEN_HEAD state was only added to GRO_MERGED_FREE
> branch of napi_skb_finish() so that if the driver uses napi_gro_frags()
> and head is merged (which in my case happens after the skb_condense()
> call added by the commit mentioned above), the skb is reused including the
> head that has been merged. As a result, we release the page reference
> twice and eventually end up with negative page refcount.
> 
> To fix the problem, handle NAPI_GRO_FREE_STOLEN_HEAD in napi_frags_finish()
> the same way it's done in napi_skb_finish().
> 
> Fixes: d7e8883cfcf4 ("net: make GRO aware of skb->head_frag")
> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>

Applied and queued up for -stable, thanks.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web