Skip to content

Commit e44699d

Browse files
mkubecekdavem330
authored andcommitted
net: handle NAPI_GRO_FREE_STOLEN_HEAD case also in napi_frags_finish()
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 c21b48c ("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: d7e8883 ("net: make GRO aware of skb->head_frag") Signed-off-by: Michal Kubecek <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6bdf6ab commit e44699d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

net/core/dev.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4767,6 +4767,13 @@ struct packet_offload *gro_find_complete_by_type(__be16 type)
47674767
}
47684768
EXPORT_SYMBOL(gro_find_complete_by_type);
47694769

4770+
static void napi_skb_free_stolen_head(struct sk_buff *skb)
4771+
{
4772+
skb_dst_drop(skb);
4773+
secpath_reset(skb);
4774+
kmem_cache_free(skbuff_head_cache, skb);
4775+
}
4776+
47704777
static gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)
47714778
{
47724779
switch (ret) {
@@ -4780,13 +4787,10 @@ static gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)
47804787
break;
47814788

47824789
case GRO_MERGED_FREE:
4783-
if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD) {
4784-
skb_dst_drop(skb);
4785-
secpath_reset(skb);
4786-
kmem_cache_free(skbuff_head_cache, skb);
4787-
} else {
4790+
if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD)
4791+
napi_skb_free_stolen_head(skb);
4792+
else
47884793
__kfree_skb(skb);
4789-
}
47904794
break;
47914795

47924796
case GRO_HELD:
@@ -4858,10 +4862,16 @@ static gro_result_t napi_frags_finish(struct napi_struct *napi,
48584862
break;
48594863

48604864
case GRO_DROP:
4861-
case GRO_MERGED_FREE:
48624865
napi_reuse_skb(napi, skb);
48634866
break;
48644867

4868+
case GRO_MERGED_FREE:
4869+
if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD)
4870+
napi_skb_free_stolen_head(skb);
4871+
else
4872+
napi_reuse_skb(napi, skb);
4873+
break;
4874+
48654875
case GRO_MERGED:
48664876
case GRO_CONSUMED:
48674877
break;

0 commit comments

Comments
 (0)