๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20432

Re: [PATCH net v6] af_packet: avoid waiting for TPACKET_V3 copies at retirement

#20432
From: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 14:04
179 lines
14044 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 2

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] On PREEMPT_RT, __packet_lookup_frame_in_block() can now return
  NULL while the current block is still TP_STATUS_KERNEL.
- [Low] The patch changelog says a review tag carries over, but the tag
  block does not contain one.
- [Low] The new comments describe only the PREEMPT_RT behaviour, and one
  of them is wrong for the default (non-RT) build.

--

af_packet: avoid waiting for TPACKET_V3 copies at retirement

On PREEMPT_RT, this patch uses write_trylock() on blk_fill_in_prog_lock
when retiring a TPACKET_V3 block. The packet path and the retirement
hrtimer then no longer block on an in-flight skb_copy_bits() while
holding sk_receive_queue.lock. If the trylock fails, the timer re-arms
and the packet path drops the capture record, while non-RT kernels keep
the blocking write_lock().

> Fixes: 632ca50f2cbd ("af_packet: TPACKET_V3: replace busy-wait loop")
> Signed-off-by: Jingxuan Xie <jingxuanxie@deeproute.ai>
>
> ---
> Changes in v6:

[ ... ]

> Changes in v5:
> - Rebase onto net/main; no functional change, so the v4 Reviewed-by
>   still applies.

[Severity: Low]
The tag block has only the Fixes: and Signed-off-by: lines and no
Reviewed-by. Was the v4 Reviewed-by lost when v6 was reposted? If so,
could it be added back? If not, could the changelog note be corrected?

> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 73222563fb704..e0ebd0627509f 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c

[ ... ]

> @@ -677,6 +677,24 @@ static void init_prb_bdqc(struct packet_sock *po,
>  	prb_open_block(p1, pbd);
>  }
>  
> +/*
> + * Wait for an in-flight skb_copy_bits() before retiring the current block.
> + * On PREEMPT_RT the read lock can be held by a task that has been preempted
> + * or is running on another CPU, so do not block while holding
> + * sk_receive_queue.lock; return false and let the caller retry.
> + */
> +static bool prb_wait_for_copy_bits(struct tpacket_kbdq_core *pkc)
> +{
> +	if (IS_ENABLED(CONFIG_PREEMPT_RT)) {
> +		if (!write_trylock(&pkc->blk_fill_in_prog_lock))
> +			return false;
> +	} else {
> +		write_lock(&pkc->blk_fill_in_prog_lock);
> +	}
> +	write_unlock(&pkc->blk_fill_in_prog_lock);
> +	return true;
> +}
> +

[ ... ]

> @@ -963,13 +982,13 @@ static void prb_retire_current_block(struct tpacket_kbdq_core *pkc,
>  		 * the timer-handler already handled this case.
>  		 */
>  		if (!(status & TP_STATUS_BLK_TMO)) {
> -			/* Waiting for skb_copy_bits to finish... */
> -			write_lock(&pkc->blk_fill_in_prog_lock);
> -			write_unlock(&pkc->blk_fill_in_prog_lock);
> +			/* Do not wait for copies while holding the queue lock. */
> +			if (!prb_wait_for_copy_bits(pkc))
> +				return false;

[Severity: Low]
This isn't a bug, but does this comment hold for non-RT builds?

There, prb_wait_for_copy_bits() takes the else branch and blocks in
write_lock(&pkc->blk_fill_in_prog_lock). Both callers hold
sk_receive_queue.lock at that point: tpacket_rcv() takes it before
packet_current_rx_frame(), and prb_retire_rx_blk_timer_expired() takes
it on entry.

The helper's comment also says "return false and let the caller retry".
Only the hrtimer path retries, through goto refresh_timer. On the packet
path, __packet_lookup_frame_in_block() returns NULL and tpacket_rcv()
goes to drop_n_account, so that record is never retried.

The name prb_wait_for_copy_bits() also doesn't fit the RT case, where
it doesn't wait.

Could the comments, and maybe the helper name, cover both
configurations?

>  		}
>  		prb_close_block(pkc, pbd, po, status);
> -		return;
>  	}
> +	return true;
>  }

[ ... ]

> @@ -1097,7 +1116,8 @@ static void *__packet_lookup_frame_in_block(struct packet_sock *po,
>  	}
>  
>  	/* Ok, close the current block */
> -	prb_retire_current_block(pkc, po, 0);
> +	if (!prb_retire_current_block(pkc, po, 0))
> +		return NULL;

[Severity: Medium]
On PREEMPT_RT, can this new NULL return break fanout rollover? At this
point the current block is full, but it stays TP_STATUS_KERNEL because
write_trylock() failed.

__tpacket_v3_has_room() only checks the block status:

net/packet/af_packet.c:__tpacket_v3_has_room() {
	...
	idx = READ_ONCE(po->rx_ring.prb_bdqc.kactive_blk_num);
	...
	return prb_lookup_block(po, &po->rx_ring, idx, TP_STATUS_KERNEL);
}

So packet_rcv_has_room() still returns ROOM_NORMAL or ROOM_LOW for this
socket, and PACKET_SOCK_PRESSURE is not set. fanout_demux_rollover()
then keeps sending packets to this socket:

	if (try_self) {
		room = packet_rcv_has_room(po, skb);
		if (room == ROOM_NORMAL ||
		    (room == ROOM_LOW && !fanout_flow_is_huge(po, skb)))
			return idx;
		...

With try_self=false, it can also choose this socket as a rollover
target.

Each of those packets then takes this path:

tpacket_rcv()
  __packet_lookup_frame_in_block()
    returns NULL
  goto drop_n_account

The packet is counted in tp_drops instead of going to a sibling socket
with space. This lasts as long as the copier holds the read lock, which
the commit message puts at hundreds of milliseconds.

Before this patch, the room check and the allocator agreed in this
state, because the allocator blocked and then succeeded.

The commit message accepts a higher capture drop rate. Should it also
say that PACKET_FANOUT_ROLLOVER and PACKET_FANOUT_FLAG_ROLLOVER no
longer move packets away from this socket in this state?

>  
>  	/* Now, try to dispatch the next block */
>  	curr = (char *)prb_dispatch_next_block(pkc, po);

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118135443.24767-1-jingxuanxie%40deeproute.ai
Technical Details
Message-ID: <179535625471.3135.1055757479714455404@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368701-linux-kernel-netdev=dewy.ru
References: <20261118135443.24767-1-jingxuanxie@deeproute.ai>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368701-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v6] af_packet: avoid waiting for TPACKET_V3 copies at
 retirement
Date: Sun, 22 Nov 2026 14:04:14 +0000
Organization: Usenet Network
Message-ID: <179535625471.3135.1055757479714455404@kernel.org>
References: <20261118135443.24767-1-jingxuanxie@deeproute.ai>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3649155"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Nz/xmkKfzdBoIYnPKwleuJNDvN8= sha256:8Z4Rz/I4KA/BRJ7S5SxElBIaM+opJyS+laXIxQWQuT8=
	sha1:KbYJ97AfFl+1qGVy0YDgthK7924= sha256:1KBvwmJF+6GT/fcx74OUw/iR+Mzk4AxgEl04cZHlBCg=
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 0E5B6125D77; Sun, 22 Nov 2026 17:04:31 +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 Cf0G0jxorS_w;
	Sun, 22 Nov 2026 17:04:27 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368701-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 4EA9B125D6E; Sun, 22 Nov 2026 17:04:19 +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 B5E9C31B90; Sun, 22 Nov 2026 14:04:17 +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=1795356257;
	b=NXcwqHEwAJqVhBF4wOI/elqyC8G4Egiw5GWnVCl6LZR+PiU/6Xjw2mpkYBhqh1O0CdkA
	 X3o7qr0CwG8OcdbqLcfal1QZh0btCd/Nothp2hpLLxkRCXuxRLGWXA5aBFe2B+blit/6w
	 RTsmgKNLX8TSYxKEY1U2MOlF4z2eajVZFvraDgj8M0KaoX5CbUkXu4thYqoDdIeJxXUG8
	 mYEnYVKz3JOjGBa9ey5bAML2wZPzI2gN7dabW1cTeDSwQoSAgKxNOQGJIn2Vzja+Nb8zG
	 ATfkXwvkrZUCU36IrCaNtLPBI+tsbOsbwKzp20H1kr/NCoEwc5P3tzKfG0FAM65i4xg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795356257;
	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=IBCuwj024PZyyxNa9iO6/34HUfTL5JYDWrPTDTMA/YI=;
	b=HG2K+wZy/Dg63P1HN4HNK6GdA+vRG9Wm1ctQ0N+fX+yAfv4mKNbdUP6rLm+rdIoONCwa
	 DrrbGfCqm97UNjDV1SbQw8jDduapoJKLrhg/L2tclpIFNRsxGZPS65jXyj9Leo8lSn8J4
	 aNHpgJ2x0m0020XGcC/EAHkDMBS/EovWryh8G6z+jNak8KJMW29kN9LmJtfEFAolhBCgr
	 XI3B9Stnz5f9/cKMr2terMOUuJkJIvgwfO2wEqlWAjHZhMe99HokWCxa0nPgk9DXbp+dq
	 a5SuwRV5Vmr0HpLdfHHA79w48sXyl7FgsAzNgNHWk51B2Vhxf/8x7cwL5zD2R2CcjJA==
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="Oreqy/JK";
	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 5A582606A335;
	Sun, 22 Nov 2026 14:04:17 +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=Oreqy/JK
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=1795356256;
	b=22b5yTBaxpGaaFZHqpjxYfMig+95yiLZRXS1GZA5JAsO2J9jornVnoGrFYCJh2WHvjNP
	 Tg49WL2rxuJr1BWjvycLVB3xFA4n2Bk03LUQ3t/z29y8sA27WCNpQOSKPVp4hc0aAgOmU
	 OwAyaFXoQikPK6zTqzv91kVSr/MLjkUKuiTXu0zT1RJjZPwrfqe7jG8/QQZovyPAVEzuK
	 4XPcAYB4MxExW/uvcfVXfsscz58tqWosDNTDAwiQgD7a/VnHbDmoIvJ070+7yMeP7TrNo
	 QjpdsJta0+PcJobkNUT8lfpJ0a43lXvnc3DA5eR3VgHYgvgB7GuZ/2kfgFHEBJ+I09Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795356256;
	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=IBCuwj024PZyyxNa9iO6/34HUfTL5JYDWrPTDTMA/YI=;
	b=q1L7GoTjn6+RB0+klaixJtu0kndra5I6M2J36k1X9qUlo0aRlsMXOPCiEd7RY1y4TSI9
	 +q5VwTLMjmrkAzkkouTw8oXopRLBFbP6TQXDlBzOpp+erCIhu4JpjWug2s3x3t9SV6/Q7
	 /AAlhZVVDwcN1HF2bfaWm9bvN9PAHIlG82oNSYExzP81GW4blIIfTk3Xxp7jPe86ceIA4
	 sQ/tEeIOrFUwyKsc6OaSj2w+aMa+OUNZ3QCge8XRDDNX0i5Qo/rU2bOTvLhOi40xD1XYu
	 gi3IvhZd8S90Rifcu7p/CLFTYKqW4MuoCQp92537Kv0O51zwoWFkD7HiVsqHdtdRckQ==
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="Oreqy/JK";
	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 79C8A606A32A;
	Sun, 22 Nov 2026 14:04:16 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23DB01F000CA;
	Sun, 22 Nov 2026 14:04:15 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795356255;
	bh=IBCuwj024PZyyxNa9iO6/34HUfTL5JYDWrPTDTMA/YI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Oreqy/JKkJUHB/P5T1A2qq123KwJW2kMrDFFP6iYzL26BeVXrrW0Z1/9gpE8Jdm+Z
	 MK8eZhApAo3b/DztiH9PpTUAP1H1RDdZGcgwKZR8VEcbrgzdS7G+JC98JgUXsdR2tS
	 Zml+5Uw//5bLGCJKP1RqAYJp1TMnf0xtr3klMbEsJvI3f71FukmcStH5pr1QNrHu/Y
	 fR6wNYlKbHnvvq/1M3S0K7n2qYarGAobVkCHfEdWzd8IAv2VGliydyKLeJYmfv2e6F
	 xEbjzbb2lvTVT5XnuEC2wgGdpPIVz5FYhyi1FdjqsCXmh0DaK45oTFXGzVtA6DbJiA
	 vK+Yli61HhNFw==
X-Cc: netdev@vger.kernel.org, willemdebruijn.kernel@gmail.com,
 shaoyanghan@deeproute.ai, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, bigeasy@linutronix.de,
 clrkwllms@kernel.org, rostedt@goodmis.org, john.ogness@linutronix.de,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261118135443.24767-1-jingxuanxie@deeproute.ai>
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