🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #15937

Re: [PATCH net] net/sched: sch_dualpi2: avoid double memory accounting on peek

#15937
From: Simon Horman
Date: Fri, 13 Nov 2026 18:00
75 lines
10852 bytes
On Mon, Nov 09, 2026 at 04:36:55PM +0000, shaos wrote:
> qdisc_dequeue_internal() removes skbs from gso_skb without invoking
> the qdisc dequeue callback. Their truesize was already subtracted
> when they were first dequeued for peek or requeued after a transmit
> failure. dualpi2_change() currently subtracts it again while trimming
> the queue, wrapping the u32 memory_used counter.
> 
> Skip the second decrement when the skb comes from gso_skb. Packets
> dequeued directly from the C-queue still need the accounting here;
> the L-queue path is unchanged.
> 
> The issue was identified by LLM-assisted source analysis and
> reproduced with a purpose-built rtnetlink/AF_PACKET test in QEMU.
> The test uses CAP_NET_ADMIN in a user-created network namespace and
> CAP_NET_RAW for its AF_PACKET sender. It does not modify the kernel
> or use error injection.
> 
> On Linux 7.4-rc2, the unpatched reproducer wrapped memory_used to
> 4294964992 and subsequent packets remained rejected after restoring
> the memory limit. With this patch, the counter remains valid and a
> packet is accepted after restoring the limit.
> 
> The modified sch_dualpi2.o builds with W=1 under allmodconfig and
> allyesconfig. Full-tree W=1 builds stop on unrelated warnings in
> lib/tests/stackinit_kunit.c, arch/x86/kernel/callthunks.c, and
> net/8021q/vlan.c. The QEMU regression passes; tc-testing was not run.
> 
> Fixes: 8f9516daedd6 ("sched: Add enqueue/dequeue of dualpi2 qdisc")
> Link: https://lkml.iu.edu/hypermail/linux/kernel/2610.2/16461.html
> Signed-off-by: shaos <shawnq1@163.com>
> ---
>  net/sched/sch_dualpi2.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sched/sch_dualpi2.c b/net/sched/sch_dualpi2.c
> index 4947def7c49ef..ccf6359eeebc3 100644
> --- a/net/sched/sch_dualpi2.c
> +++ b/net/sched/sch_dualpi2.c
> @@ -909,14 +909,20 @@ static int dualpi2_change(struct Qdisc *sch, struct nlattr *opt,
>  	while (qdisc_qlen(sch) > sch->limit ||
>  	       q->memory_used > q->memory_limit) {
>  		struct sk_buff *skb = NULL;
> +		bool already_dequeued;
>  
>  		if (qdisc_qlen(sch) > qdisc_qlen(q->l_queue)) {
> +			already_dequeued = skb_peek(&sch->gso_skb);
> +
>  			skb = qdisc_dequeue_internal(sch, true);
>  			if (unlikely(!skb)) {
>  				WARN_ON_ONCE(1);
>  				break;
>  			}
> -			WRITE_ONCE(q->memory_used, q->memory_used - skb->truesize);
> +			/* A peeked or requeued skb was already accounted. */
> +			if (!already_dequeued)
> +				WRITE_ONCE(q->memory_used,
> +					   q->memory_used - skb->truesize);

It strikes me that this change is incomplete.

I think the loads and stores of q->memory_used and q->memory_limit
should be consistently annotated, stashing the value of reads
in local variables to avoid re-reads as appropriate.

Perhaps the resulting change is too wide to be a strict fix for the bug
at hand. But that does at least seem necessary within this function.

>  			rtnl_qdisc_drop(skb, sch);
>  		} else if (qdisc_qlen(q->l_queue)) {
>  			skb = qdisc_dequeue_internal(q->l_queue, true);
> 

-- 
pw-bot: changes-requested
Technical Details
Message-ID: <20261113180029.GB18859@horms.kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362831-linux-kernel-netdev=dewy.ru
References: <20261022144758.65248-1-shawnq1@163.com> <20261109163655.301509-1-shawnq1@163.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362831-linux-kernel-netdev=dewy.ru
From: horms@kernel.org (Simon Horman)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net/sched: sch_dualpi2: avoid double memory
 accounting on peek
Date: Fri, 13 Nov 2026 18:00:29 +0000
Organization: Usenet Network
Message-ID: <20261113180029.GB18859@horms.kernel.org>
References: <20261022144758.65248-1-shawnq1@163.com>
 <20261109163655.301509-1-shawnq1@163.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="1423069"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:oDQvxOZTZThz2Ag6KVZcxy/8by8= sha256:oXEUFC2VcZdboCMS3cC7GkGUm8iLmIb3v10h94ei+HU=
	sha1:BK29b7YoCfLF4AoyHLDlCjeewFw= sha256:2e7eTj15i0V3WvKd8S2W/KDFGCOR6dawC175rot1qDo=
Content-Disposition: inline
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 E38C111463D; Fri, 13 Nov 2026 22:48:34 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 hzDH-F-JvPbX;
	Fri, 13 Nov 2026 22:48:30 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-362831-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 CD341114639; Fri, 13 Nov 2026 22:48:21 +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 075A438374C; Fri, 13 Nov 2026 18:03:01 +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=1794592840;
	b=eRYer+YqAWRqi2nI7BilYZwL7ZYjpXyfcYHy90OSLBzH/8LA+F1Kxug1IrsR0A/cnD7d
	 cnkG/Zh3wUtvPgU2gbYkz3dtm0f5lOrwP8MvutBKHrBbw1L+zbq60fY9NDpFPRyw1HSEG
	 MvPZ+r3Yq92hvj48tjhpw6QRMa32kc8PHruf/26O75PXK25zaGRSXQsqvw7FI8RZhCllk
	 prAq/b/HoLvgm1kNbvWCYvKpiSRzPG6W/OysKQxu+dMe5lQZDX82pzNORYqamgZaIjz2u
	 prqi63PZEpWAIEYs6hFJ8dwT2tSRwivj9AOR2ubdwKk5YDvxnVNLvA89lIZ+pRfUiIQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794592840;
	h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=Tw0lREbHvrQFePK47mNtizeFz33aFjFULtXTtRVDf8E=;
	b=Gmyik5UCFJsYMaArQ7X3NlRUkE1aGkhISQgdACHXwyVQegGq5Vv8hX4snTOLhpBKlgIL
	 NFc/xDosuZ29bLU2MiM5zbffIOpMPPWguowWYC50DVRo08BKYO6H0lviugUIrX795uwtK
	 FglobrPyfsHn5Bh5rQWuksJRKCDhFzqwp1hxLG+ATDtIX1Ns92zH9WRYcSGsYW8bjLnJo
	 VZtaq4S6XvgZ8vud+pELEFYZ1pUUFPtYwRKOuKa2dluuMrGH6imnklzlYde8z1fbTQvRF
	 GWNdwAzdSu2lgp2meZ+xmDL/C6DXc3ydU7zSX8EezspbB2IMxxWHraWt+v5JNtpKxwQ==
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=PZFf9qxK;
	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 33285606A8A4;
	Fri, 13 Nov 2026 18:00:40 +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=PZFf9qxK
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=1794592834;
	b=Z2NfqQ0D6q9ryP4z6zMdkztqKVtDA7FQF1dpJ/1jbuK1ZY3xGCwuGqCWOpuwC7qD/M50
	 4ksshtG6AzdyPOAxhKaVYaDnFIdPC9Ii6dlhGKIaJN1ERSdgDggNItMox9SOzdk9KJqG+
	 rmDkXiNxL8k8O4Pq8iCh0vzAWMByaJIFwyXhG8ASc2Y7tuNSmQ+urnqgw7jnGoXMBswVN
	 5tFjPFEt4dNtucPjgYZtszW0lcbnmD+zNxN4p/sGUmBLsXOBOG1J+mHumGCVmvtfkhekO
	 Gh7NW3N7Xs2fszbnliBPn0VJZ6Q0mA3esQmwkA7F3nhPaBrCbfdfgOsMbt1iKYOdBpw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794592834;
	h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=Tw0lREbHvrQFePK47mNtizeFz33aFjFULtXTtRVDf8E=;
	b=NKlPXegZ4E85AdIImdoaJrfo2haTNCn7LqBPZuG42jFzPqceWBR4+PvqX5f05vgN6c7v
	 RIFedawISy5Sqvr8Q4EcTqlg/s9LW7m4q/hJwhmJ0c66MUGT7c0sQVJSxs+dqs3xEEBCK
	 nNI0OHYQPqDOKojTgZ88IMQnT/vPGQ13Nc0zhtJ3EOTV7dppa+yl3h9xHLwnqalL+88rI
	 YGY5+HTtJJirO0cyOHsPg2TM1L2Dx0Gud8NtimXprrInzqeoGOE8p8LHzkoJYPxqwJz1x
	 6DXS2FzX7jfNQA75UCXS36zorMPwUtqq6KVfMvkqf8vNRCfymQ6+6OIJu7hBibRzmDg==
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=PZFf9qxK;
	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 53282606B440;
	Fri, 13 Nov 2026 18:00:34 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42FD21F00935;
	Fri, 13 Nov 2026 18:00:32 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794592834;
	bh=Tw0lREbHvrQFePK47mNtizeFz33aFjFULtXTtRVDf8E=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=PZFf9qxKTXcw96rvkG+t9eR71AToG06GLwSh4mGQZmF2a5CetWYzr/DfvvmtHpEv8
	 L0tNQLds0AVt0hk12a4EVSoFeVgnqvxHr8ovSmEVDzw3eAW/STAGGAZ0KW2F3geMM+
	 iJqunplwuIrCkvkPlNMzgH5ifiBUUFKlmf7T5CJGqDJ3qF/OOOKC5gRaZ7ZC4LIh+J
	 wbLVuNqs5JB8YBfI9igczSGzP/5aL91Q4N8oapp2WUbp2T53w4sgYEaTJrYpa/d9Or
	 wjWYzs+QqvvOPC3+j4Er4Fws0Rxfk9OWDH00eRsFXXFdT2b7uKXPbFfP53J77zuoIW
	 IDh3KRuBpRrfg==
X-Cc: jhs@mojatatu.com, Jiri Pirko <jiri@resnulli.us>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
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
X-In-Reply-To: <20261109163655.301509-1-shawnq1@163.com>