History

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 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().

Michal Kubeček committed 9 years ago

Commit e44699d1 parent 6bdf6ab1 file · +17 −7Browse files

Unified · Split

net/core/dev.c+17−7
@@ -4767,6 +4767,13 @@ struct packet_offload *gro_find_complete_by_type(__be16 type) · 4766 unmodified lines
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) · 7 unmodified lines
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, · 65 unmodified lines
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;