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().
Unified · Split
| @@ -4767,6 +4767,13 @@ struct packet_offload *gro_find_complete_by_type(__be16 type) · 4766 unmodified lines | ||
| 4767 | 4767 | } |
| 4768 | 4768 | EXPORT_SYMBOL(gro_find_complete_by_type); |
| 4769 | 4769 | |
| 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 | + | |
| 4770 | 4777 | static gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb) |
| 4771 | 4778 | { |
| 4772 | 4779 | switch (ret) { |
| @@ -4780,13 +4787,10 @@ static gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb) · 7 unmodified lines | ||
| 4780 | 4787 | break; |
| 4781 | 4788 | |
| 4782 | 4789 | 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 | |
| 4788 | 4793 | __kfree_skb(skb); |
| 4789 | − } | |
| 4790 | 4794 | break; |
| 4791 | 4795 | |
| 4792 | 4796 | case GRO_HELD: |
| @@ -4858,10 +4862,16 @@ static gro_result_t napi_frags_finish(struct napi_struct *napi, · 65 unmodified lines | ||
| 4858 | 4862 | break; |
| 4859 | 4863 | |
| 4860 | 4864 | case GRO_DROP: |
| 4861 | − case GRO_MERGED_FREE: | |
| 4862 | 4865 | napi_reuse_skb(napi, skb); |
| 4863 | 4866 | break; |
| 4864 | 4867 | |
| 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 | + | |
| 4865 | 4875 | case GRO_MERGED: |
| 4866 | 4876 | case GRO_CONSUMED: |
| 4867 | 4877 | break; |