Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: skb: clean up dead code after skb_kfree_head() simplification

Since commit 0f42e3f4fe2a ("net: skb: fix cross-cache free of
KFENCE-allocated skb head"), skb_kfree_head() always calls kfree()
and no longer uses end_offset to distinguish between skb_small_head_cache
and generic kmalloc caches.

Clean up the leftovers:

- Remove the unused end_offset parameter from skb_kfree_head() and
update all callers.
- Remove the SKB_SMALL_HEAD_HEADROOM guard in __skb_unclone_keeptruesize()
which was protecting the old skb_kfree_head() logic.
- Update the SKB_SMALL_HEAD_CACHE_SIZE comment to reflect that the
non-power-of-2 sizing is no longer used for free-path disambiguation.

No functional change.

Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260410034736.297900-1-jiayuan.chen@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Jiayuan Chen and committed by
Jakub Kicinski
5758be28 e530b484

+9 -24
+9 -24
net/core/skbuff.c
··· 106 106 #define SKB_SMALL_HEAD_SIZE SKB_HEAD_ALIGN(max(MAX_TCP_HEADER, \ 107 107 GRO_MAX_HEAD_PAD)) 108 108 109 - /* We want SKB_SMALL_HEAD_CACHE_SIZE to not be a power of two. 110 - * This should ensure that SKB_SMALL_HEAD_HEADROOM is a unique 111 - * size, and we can differentiate heads from skb_small_head_cache 112 - * vs system slabs by looking at their size (skb_end_offset()). 109 + /* SKB_SMALL_HEAD_CACHE_SIZE is the size used for the skbuff_small_head 110 + * kmem_cache. The non-power-of-2 padding is kept for historical reasons and 111 + * to avoid potential collisions with generic kmalloc bucket sizes. 113 112 */ 114 113 #define SKB_SMALL_HEAD_CACHE_SIZE \ 115 114 (is_power_of_2(SKB_SMALL_HEAD_SIZE) ? \ ··· 1070 1071 return 0; 1071 1072 } 1072 1073 1073 - static void skb_kfree_head(void *head, unsigned int end_offset) 1074 + static void skb_kfree_head(void *head) 1074 1075 { 1075 1076 kfree(head); 1076 1077 } ··· 1084 1085 return; 1085 1086 skb_free_frag(head); 1086 1087 } else { 1087 - skb_kfree_head(head, skb_end_offset(skb)); 1088 + skb_kfree_head(head); 1088 1089 } 1089 1090 } 1090 1091 ··· 2360 2361 return 0; 2361 2362 2362 2363 nofrags: 2363 - skb_kfree_head(data, size); 2364 + skb_kfree_head(data); 2364 2365 nodata: 2365 2366 return -ENOMEM; 2366 2367 } ··· 2405 2406 2406 2407 if (likely(skb_end_offset(skb) == saved_end_offset)) 2407 2408 return 0; 2408 - 2409 - /* We can not change skb->end if the original or new value 2410 - * is SKB_SMALL_HEAD_HEADROOM, as it might break skb_kfree_head(). 2411 - */ 2412 - if (saved_end_offset == SKB_SMALL_HEAD_HEADROOM || 2413 - skb_end_offset(skb) == SKB_SMALL_HEAD_HEADROOM) { 2414 - /* We think this path should not be taken. 2415 - * Add a temporary trace to warn us just in case. 2416 - */ 2417 - pr_err_once("__skb_unclone_keeptruesize() skb_end_offset() %u -> %u\n", 2418 - saved_end_offset, skb_end_offset(skb)); 2419 - WARN_ON_ONCE(1); 2420 - return 0; 2421 - } 2422 2409 2423 2410 shinfo = skb_shinfo(skb); 2424 2411 ··· 6800 6815 if (skb_cloned(skb)) { 6801 6816 /* drop the old head gracefully */ 6802 6817 if (skb_orphan_frags(skb, gfp_mask)) { 6803 - skb_kfree_head(data, size); 6818 + skb_kfree_head(data); 6804 6819 return -ENOMEM; 6805 6820 } 6806 6821 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) ··· 6907 6922 memcpy((struct skb_shared_info *)(data + size), 6908 6923 skb_shinfo(skb), offsetof(struct skb_shared_info, frags[0])); 6909 6924 if (skb_orphan_frags(skb, gfp_mask)) { 6910 - skb_kfree_head(data, size); 6925 + skb_kfree_head(data); 6911 6926 return -ENOMEM; 6912 6927 } 6913 6928 shinfo = (struct skb_shared_info *)(data + size); ··· 6943 6958 /* skb_frag_unref() is not needed here as shinfo->nr_frags = 0. */ 6944 6959 if (skb_has_frag_list(skb)) 6945 6960 kfree_skb_list(skb_shinfo(skb)->frag_list); 6946 - skb_kfree_head(data, size); 6961 + skb_kfree_head(data); 6947 6962 return -ENOMEM; 6948 6963 } 6949 6964 skb_release_data(skb, SKB_CONSUMED);