Allocate MAX_SKB_FRAGS - 2 full chunks of PAGE_ALLOC_COSTLY_ORDER plus a 7 page tail. Rounding the tail down to 4 + 2 + 1 pages would need one frag more than MAX_SKB_FRAGS, which made the allocation fail with -ENOBUFS before the previous patch. Signed-off-by: Haishuang Yan --- net/core/net_test.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/net/core/net_test.c b/net/core/net_test.c index 2b5080c22663..5a451aaf37c9 100644 --- a/net/core/net_test.c +++ b/net/core/net_test.c @@ -1721,7 +1721,31 @@ static void netmem_ref_test_tcp_devmem_recv(struct kunit *test) #endif #endif +static void alloc_skb_with_frags_test_tail(struct kunit *test) +{ + /* MAX_SKB_FRAGS - 2 full chunks plus a 7 page tail: rounding the + * tail down to 4 + 2 + 1 pages would need one frag too many. + */ + unsigned long len = (MAX_SKB_FRAGS - 2) * + (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) + + 7 * PAGE_SIZE; + unsigned long frags_len = 0; + struct sk_buff *skb; + int err, i; + + skb = alloc_skb_with_frags(0, len, PAGE_ALLOC_COSTLY_ORDER, &err, + GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL_MSG(test, skb, "err %d", err); + + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) + frags_len += skb_frag_size(&skb_shinfo(skb)->frags[i]); + KUNIT_EXPECT_EQ(test, frags_len, len); + + kfree_skb(skb); +} + static struct kunit_case net_test_cases[] = { + KUNIT_CASE(alloc_skb_with_frags_test_tail), KUNIT_CASE_PARAM(gso_test_func, gso_test_gen_params), KUNIT_CASE_PARAM(ip_tunnel_flags_test_run, ip_tunnel_flags_test_gen_params), -- 2.43.0