🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19213

Re: [PATCH net v3 2/2] net: add a KUnit test for the alloc_skb_with_frags() tail split

#19213
From: netdev-bot+sashiko
Date: Thu, 19 Nov 2026 14:56
123 lines
12088 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The skip-or-fail decision in alloc_skb_with_frags_test_tail()
  (net/core/net_test.c) depends on a probe that only runs after…

--

net: add a KUnit test for the alloc_skb_with_frags() tail split

This adds a KUnit test that asks alloc_skb_with_frags() for
MAX_SKB_FRAGS - 2 full order-3 chunks plus a 7 page tail. It then checks
that the frags cover the full length. If the allocation fails, the test
checks whether MAX_SKB_FRAGS - 1 order-3 pages can be held at once, and
skips if they cannot.

> diff --git a/net/core/net_test.c b/net/core/net_test.c
> index 2b5080c226636..118866f3e28c3 100644
> --- a/net/core/net_test.c
> +++ b/net/core/net_test.c
> @@ -1721,7 +1721,58 @@ static void netmem_ref_test_tcp_devmem_recv(struct kunit *test)
>  #endif
>  #endif
>  
> +/* Can @nr pages of @order be allocated and held at the same time? */
> +static bool alloc_skb_with_frags_test_have_pages(unsigned int nr,
> +						 unsigned int order)
> +{
> +	struct page *pages[MAX_SKB_FRAGS];
> +	unsigned int i, n;
> +
> +	for (n = 0; n < nr; n++) {
> +		pages[n] = alloc_pages(GFP_KERNEL | __GFP_NOWARN |
> +				       __GFP_NORETRY, order);
> +		if (!pages[n])
> +			break;
> +	}

[ ... ]

> +static void alloc_skb_with_frags_test_tail(struct kunit *test)
> +{

[ ... ]

> +	skb = alloc_skb_with_frags(0, len, PAGE_ALLOC_COSTLY_ORDER, &err,
> +				   GFP_KERNEL);
> +	/* The full chunks can't fall back to smaller pages here, so the
> +	 * call needs up to MAX_SKB_FRAGS - 1 order-3 pages at once. Don't
> +	 * report a lack of them as a failure.
> +	 */
> +	if (!skb && !alloc_skb_with_frags_test_have_pages(MAX_SKB_FRAGS - 1,
> +							  PAGE_ALLOC_COSTLY_ORDER))
> +		kunit_skip(test, "not enough order-%d pages",
> +			   PAGE_ALLOC_COSTLY_ORDER);
> +	KUNIT_ASSERT_NOT_NULL_MSG(test, skb, "err %d", err);

[Severity: Medium]

Can this report a FAIL when alloc_skb_with_frags() only ran into a
temporary shortage of high-order pages?

The probe in alloc_skb_with_frags_test_have_pages() runs only after the
real allocation has failed, and by then memory is in a different state.
For this len, the full order-3 chunks can't drop to a lower order. So a
single failed __GFP_NORETRY retry ends the call:

net/core/skbuff.c:alloc_skb_with_frags() {
    ...
				page = alloc_pages(gfp_mask | __GFP_COMP |
						   __GFP_NOWARN | __GFP_NORETRY,
						   order);
				if (!page)
					goto failure;
    ...
failure:
	kfree_skb(skb);
	return NULL;
}

By the time the probe runs, three things have changed:

  - kfree_skb() has given the order-3 pages already taken back to the
    allocator.
  - The failed call has already done one round of direct reclaim and
    compaction.
  - kswapd and kcompactd have been woken for order 3.

The probe's GFP_KERNEL | __GFP_NORETRY order-3 allocations can then
succeed. In that case the test does not skip, and
KUNIT_ASSERT_NOT_NULL_MSG() fails.

The commit message says:

  so that fragmented memory is not reported as a failure.

Does this ordering guarantee that?

Also, the failure message prints err. That value is -ENOBUFS both for a
real frag exhaustion regression and for a page allocation failure, so the
log can't tell the two apart.

Would it be more robust to call alloc_skb_with_frags() again when the
probe succeeds, and fail only if the second call also returns NULL?

> +
> +	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);

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116115620.18151-1-yanhaishuang%40cmss.chinamobile.com
Technical Details
Message-ID: <179510021881.3136.3672843529450562064@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367098-linux-kernel-netdev=dewy.ru
References: <20261116115620.18151-3-yanhaishuang@cmss.chinamobile.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367098-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3 2/2] net: add a KUnit test for the
 alloc_skb_with_frags() tail split
Date: Thu, 19 Nov 2026 14:56:58 +0000
Organization: Usenet Network
Message-ID: <179510021881.3136.3672843529450562064@kernel.org>
References: <20261116115620.18151-3-yanhaishuang@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2905411"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:odL0HH77AQUo8URZs+H1Iwvg2PI= sha256:FtKSdA13pjPSzObA8LmaEXcPBxOdlexykNM4UxmLMXs=
	sha1:/tvTShvEfEjWhrKbt4OBfaCi3GM= sha256:NNp8ltCrBYOICTNTsZYscxfR/7e1JSvhd47I7H76pmg=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 436AD1156AD; Thu, 19 Nov 2026 17:57:29 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id QaZfHiwuEZuG;
	Thu, 19 Nov 2026 17:57:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-367098-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id A97A1115643; Thu, 19 Nov 2026 17:57:11 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 72F5A2CA337; Thu, 19 Nov 2026 14:57:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795100221;
	b=wJY89T2gGpMegrZiun0Qh1RMj1hlAdif6PfyJFiHBzoEENxVoF02tKzFCRZIh8sejwzO
	 SJbyfo6Qk9Ogz3hlIosz9euQqulQRbNdcf22KfaFJwM3MJRmAfbiMQ5fbSUC5I1TkBUMj
	 rNzEJD8lXduGEOheNi46vtJxqJSpZ82Yn0VNizcUsetYOQW1zF7W6ZMdjLx3oyjj2TGIS
	 HV5LSqMWeNbDqY+x3NeHYJgNOPYYZhGmEmSI1c3uW6B/KPsLHDtysYY8PZnbeKCN4pH4v
	 iQ2v9ss+b2j/hq/wv2J6OI42+erB2W6aGeA4DuOEy+czJW64SO9aZ3PQ3UgI2klUm8A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795100221;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=Cnsng9BOZcTR5dWhMhFYliiky1LEK8VCvuJn4fpPT3c=;
	b=xgIvYFr7gvPTek8xXgAjYXlwe91BiRzXveRkvxtBxZrVjCyDrQIwH+XrnYIvc9tSVT1Y
	 6FrkbYUvKR9NLWAR8POBihnIx9K+iXjc/ffxZiDEDc8zxfB4xGb7MNCxcjTFLkHrsuMeB
	 KVw6g/t8Y8Rv+yB0281gt12PadDo0H/iGx9pcAs/OCP0Cy+fAj+50ydCPuFhLzKM2GlB8
	 RF+l6nMGjmfyBy2WL2Txo+x67se1PXPMl8Pg0i5jUqjeF9ylI2FSJZyExRR7BSpc3NwSY
	 Z1ilyRqashcJfLKUCIsX4bSNI4xyEuJOA7a0Oy/XPYLu7K9M4tiWc0XKiJqYHxcVy7w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KflLY7xu;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A29A606A325;
	Thu, 19 Nov 2026 14:57:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KflLY7xu
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795100220;
	b=ZcJnqbtKlAayhqhv+djaGBUBWG5oVHtuoXs8vi1VOFvZarV5Q8SnB4Bw2Fj3GXlnIZOY
	 +OlZ/pWzHQIW7rQwd003PQez/AnK0V2Nyd1NDpyi/KO9cv3JrKud2oBdy6YdnwqQefM6S
	 uI+GSOT1PPmn75xBQ09eGXs6xjSxg74tMhBG+CXbagyjYklLq+rI491ADeuF+8urQs6fI
	 4Vx7UN5F5rSWK8mrCnWCp8odJMGEpWxqn5j5r1HdOeXLedmaeapj/kwtsHIKvwg153iBV
	 AXW3hCjIEYlvQfDToZMjz9MRk5zi00sQ5fObzMRD9PSgOThKWmbiDpaufPDd6vRSF5g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795100220;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=Cnsng9BOZcTR5dWhMhFYliiky1LEK8VCvuJn4fpPT3c=;
	b=hR/E9v4XOy2Tr+sMfd1oTLW4RqrJ3FFlImPrpjVRVJw4jbvs4weGoTu9qrvvYvOEwNg4
	 eH7WT6XpxPLx+7cQ1NX+INnQnLsNg6uGG29qx88noY3hqHUQTcdfSZUuUvYItt0HLIunH
	 aMZPKPgDtcuT3Psu7b1AF69ObpRrWwz1Wcl+WO/g0qtr2hsjfKs3r4Ka7s8EImteQ3gAw
	 rsadHGOjqsZdHhxguwJ67yeq5j79pXVn9KG1mxQ74q9wQ3vI/ToQ/eXHTtIW8W3+gtt7m
	 ZBeSE0O2dbAUyOKD2vXtxPdDxYdGLFVT4qy5L26r0hb8M+9k/mbQ2ikqVfiRdNtKdWw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KflLY7xu;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68688606A33D;
	Thu, 19 Nov 2026 14:57:00 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3954A1F000C7;
	Thu, 19 Nov 2026 14:56:59 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795100220;
	bh=Cnsng9BOZcTR5dWhMhFYliiky1LEK8VCvuJn4fpPT3c=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=KflLY7xupGFFOzPewH3Sp5A4e0j8KWo63PiYVCjDPg7YcU6PTpuCukYhLb2nOsdWU
	 EnOU6eXvEX5k8PpUahGEYOvOMB5wkGUSyUY/elGg9jk00tpt2Lsh3N1r7rKmqtAvnj
	 kY5VsLI/Q+Ybp0OnnAbWQrDUUHd8+Th+iT/3Kd7qpupLq3DZKy+uvJk1MpMcT+9Ifk
	 iJUZVXr7VuNKaSmB6d5uERxDTJuDGELAFmFD/wq1TireWos7rxvIY8dsthn5w0sKN2
	 wUZZ973JTBygJ14hlE/Et7A+gmK5qUizPDD7tZjJSOS+gqm+J06GbBnVp4SNTAAINI
	 /mnIXJ1azfIYA==
X-Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, almasrymina@google.com,
 daniel@iogearbox.net, willemb@google.com, willemdebruijn.kernel@gmail.com,
 mst@redhat.com, jasowangio@gmail.com, eperezma@redhat.com,
 narcisav.kernel@gmail.com, linux-kernel@vger.kernel.org
X-In-Reply-To: <20261116115620.18151-3-yanhaishuang@cmss.chinamobile.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list