🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26705

Re: [PATCH net-next] sfc: wait for RCU readers before reclaiming failed CT entries

#26705
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 03:46
166 lines
14166 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

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

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] Nothing in the tree shows that the race this commit describes
  can happen, yet the patch carries a Fixes: tag and adds a blocking…
- [Medium] This finding only applies if the commit's premise is true; as
  shown in the previous finding, the nf_flowtable core currently…
- [Low] When conn->cnt is set, the reordered release path in
  efx_tc_ct_replace() waits for two grace periods back to back.

--

sfc: wait for RCU readers before reclaiming failed CT entries

This patch reorders the error path in efx_tc_ct_replace(). A newly
inserted CT entry is now removed from ct_ht and an RCU grace period is
allowed to elapse before its counter is released and the entry is
freed. The goal is to protect efx_tc_ct_stats() readers that may have
found the entry under RCU.

> diff --git a/drivers/net/ethernet/sfc/tc_conntrack.c b/drivers/net/ethernet/sfc/tc_conntrack.c
> index 77ce2eca43f25..38688ae4e292d 100644
> --- a/drivers/net/ethernet/sfc/tc_conntrack.c
> +++ b/drivers/net/ethernet/sfc/tc_conntrack.c
> @@ -443,11 +443,13 @@ static int efx_tc_ct_replace(struct efx_tc_ct_zone *ct_zone,
>  	mutex_unlock(&ct_zone->mutex);
>  	return 0;
>  release:
> -	if (conn->cnt)
> -		efx_tc_flower_release_counter(efx, conn->cnt);
> -	if (!old)
> +	if (!old) {
>  		rhashtable_remove_fast(&efx->tc->ct_ht, &conn->linkage,
>  				       efx_tc_ct_ht_params);
> +		synchronize_rcu();
> +	}

[Severity: Medium]
The commit message says:

  efx_tc_ct_stats() may already have found the entry under RCU and
  still be using conn->cnt.

Can this happen with the current callers?

efx_tc_flow_block() is only registered through
nf_flow_table_offload_add_cb() in efx_tc_ct_register_zone(). That means
FLOW_CLS_REPLACE, FLOW_CLS_STATS and FLOW_CLS_DESTROY all come from
flow_offload_work_handler(). Each of those work items is allocated by
nf_flow_offload_work_alloc():

net/netfilter/nf_flow_table_offload.c:nf_flow_offload_work_alloc() {
    ...
	if (test_and_set_bit(NF_FLOW_PENDING, &flow->flags))
		return NULL;
    ...
}

flow_offload_work_handler() clears the bit only after the add, del or
stats callback has returned:

	smp_mb__before_atomic();
	clear_bit(NF_FLOW_PENDING, &offload->flow->flags);

The cookie used as the ct_ht key is set in nf_flow_offload_init():

	cls_flow->cookie = (unsigned long)tuple;

This is the address of a tuple inside a single flow. The flow is freed
only after its destroy work has finished, via NF_FLOW_HW_DYING, then
NF_FLOW_HW_DEAD, then flow_offload_del(). nf_flow_table_do_purge() also
runs only after nf_flow_table_offload_flush().

>From that, a FLOW_CLS_STATS for a given cookie does not look like it
can overlap a FLOW_CLS_REPLACE for the same cookie. Is there another
path this commit has in mind? If not, should the change be described as
hardening, without the Fixes: tag?

Separately, some failures used to return without any wait and now
block for a full synchronize_rcu(). These include
efx_tc_ct_parse_match() errors, "NAT only supported for IPv4", CT
labels, and unhandled actions.

This runs on the nf_ft_offload_add workqueue, which all offloading
drivers share. flow_offload_refresh() re-queues a FLOW_CLS_REPLACE
about once per second for any flow that keeps hitting the software
path, and a flow the NIC cannot offload does exactly that. Is the extra
blocking on that shared kworker acceptable for these repeated failures?

[Severity: Medium]
If the premise in the commit message holds, and efx_tc_ct_stats() can
run at the same time as efx_tc_ct_replace() for the same cookie, is
this fix complete?

rhashtable_lookup_get_insert_fast() publishes conn into ct_ht while
conn->cnt is still NULL from kzalloc. conn->cnt is set only after all
match and action parsing, with a plain store:

	conn->cnt = cnt;

The reader does this:

drivers/net/ethernet/sfc/tc_conntrack.c:efx_tc_ct_stats() {
    ...
	cnt = conn->cnt;
	spin_lock_bh(&cnt->lock);
    ...
}

There is no NULL check and no READ_ONCE(). A stats lookup anywhere
between the insert and conn->cnt = cnt would dereference a NULL cnt.
That window covers every early error exit, and also successful setups
before the counter exists.

The new synchronize_rcu() only waits for readers once the entry has
been removed. It cannot help a reader that has already loaded a NULL
cnt.

If the race is real, would it be better to insert into ct_ht only after
conn is fully initialized? Another option is for efx_tc_ct_stats() to
tolerate an unfinished entry, using READ_ONCE(conn->cnt) plus a NULL
check, paired with a publishing store on the writer side.

This only matters if the commit's premise holds. As noted above, the
current tree appears to serialize these calls via NF_FLOW_PENDING.

> +	if (conn->cnt)
> +		efx_tc_flower_release_counter(efx, conn->cnt);

[Severity: Low]
When conn->cnt is set, does this path now wait for two grace periods
back to back? efx_tc_flower_release_counter() already does:

drivers/net/ethernet/sfc/tc_counters.c:efx_tc_flower_release_counter() {
    ...
	synchronize_rcu();
	flush_work(&cnt->work);
	EFX_WARN_ON_PARANOID(spin_is_locked(&cnt->lock));
	kfree(cnt);
}

That grace period starts after conn has been removed from ct_ht. On its
own, it ensures every efx_tc_ct_stats() reader holding conn or
conn->cnt has finished before cnt or conn is freed.

The explicit synchronize_rcu() seems to be needed only when conn->cnt
is NULL. Could it be made conditional on !conn->cnt? Then failures
after the counter is allocated, such as efx_mae_insert_ct() returning
an error when the hardware CT table is full, would wait for one grace
period instead of two.

>  	kfree(conn);
>  	return rc;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179626774776.1539442.17436520173285566977%40jaeyeong.cc
Technical Details
Message-ID: <179635601846.3146.4375554711670849772@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377023-linux-kernel-netdev=dewy.ru
References: <179626774776.1539442.17436520173285566977@jaeyeong.cc>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377023-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next] sfc: wait for RCU readers before reclaiming failed CT entries
Date: Fri, 04 Dec 2026 03:46:58 +0000
Organization: Usenet Network
Message-ID: <179635601846.3146.4375554711670849772@kernel.org>
References: <179626774776.1539442.17436520173285566977@jaeyeong.cc>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="2667461"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Z8Rwzji7QzyWnD30MXpV4GP5APQ= sha256:5mSojTDc7dh6Hm9bLqbpSwwxMGXRn4Rx5iVOHRkQaRI= sha1:HTbXlcguc4kJzLBXMXTWXaNbWjo= sha256:iD2JjxgZyvTwPEah9SMzSllx9iOSZ6+NilBl3WbcLEs=
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 F37A8117ADA; Fri,  4 Dec 2026 06:47:27 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.639
X-Spam-Status: No, score=-3.639 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, 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 wFUuiTOaegCX; Fri,  4 Dec 2026 06:47:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377023-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 A4562117ABA; Fri,  4 Dec 2026 06:47:14 +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 32A0029ACC; Fri,  4 Dec 2026 03:47: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=1796356020; b=y5zSuAMVnaDlrGB0LZKpgJf9oBEm14gmWdqhrLPHtOSop6u+egU2RVP7BflMazNVh/JG 36fafjrHNATa8prGaJNEfKzMODBXIYCZoiDRY9JMAIysSLIzVHxYOMmuPqxl992LeK2v/ fVyXSW82MB8t5N2u67R7YZdYMpMpYmSdd0BQzIFTW+H5+BvGgrsDs8M5WSFklNhJcyDIU aHe1gaTDAJMMLEe5dKocABVzNIj9gSegvxD5kPMueSCHYRt+OXibRZwS4mceLSqpjrgL1 4iuurbz2FcQo7zgDNwkL5QJLSuDSzAcVz/DIBqsHq6eC9cumYrkjWHegWRdD0QgGMsA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796356020; 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=G4Vt1p0nrt0ZvzpSXikzs1Xh1DK1DAwLeI4V+sQSNa4=; b=Oe4OkxTU5lxod7QZm8r7hk28bstGB7ESV6iebZF29b99Zk/vjY/yNMajLMTYqk+EMmHi KaZFZAIPrrE/SvWly1ghWh9PzUZXUu0ByH9OhZxQKKEheKJ/kTUlUEQ5FGgBm72cNOnLs ikGSlygVauXaWiqUyZMjhYFLSRoGBm2tk2CNT1qzi2wCED+w0u4SGUAe2ZdgVqJBuzhYd kirNtZnGXjO2F5liVs11MOQcvcAb3VgulMSN5NrTw3CRjozP1ii6fmRNFiDnxRdDZz+mQ Dz0g1TnVQlAcbL8Bq/eqStEHAx+8T+wOerRpfH51TOv66X/fduWOwpRlH+a546kEncA==
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=HRs0MAPJ; 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 7CE18606A68A; Fri,  4 Dec 2026 03:47:00 +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=HRs0MAPJ
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=1796356019; b=bJA5VCyIiBcrFcTjErrlSI2j5rZMZrAY5aUXrcuVK9miCxjChHPQk+DMvGlDeTiwg/lR myGHcjLAdZjt89jslonUTPcYrZ76uZud8YTi3Ha4EZDUHMFbht8/5lr9ZfwF2tKAoxEKa ZWuJfMGd2cNjq8mvX/7SemotJWrVGcwk0BKdOBiFqmMLSUebhj3svX3jTMIvw2Jrt0L8P Z9vpz9PUTcwGdhIsZAWv4AEgcuWMbM2FbYzfKpptn9d9t6nEt0iL/lru3s0CdTIDJFxke ya5Xjc++Fo68l4ccYHF3UrtqEQ2V5nc7rHPxGFO8mLNuvXZvchJOWkoKoEBxOpn1n1Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796356019; 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=G4Vt1p0nrt0ZvzpSXikzs1Xh1DK1DAwLeI4V+sQSNa4=; b=uB9FGfzq0Z1p62UniUyw5X4LxpPERjValMOShzepGZFMiZvhuYafZmn4pb86eSff+xom 3Ni8MCrWwRlYEMTGiaA2CVA6+LjyhHBIOmpVQCekqS4bxBwrgODxUukt3pkgLDbSuIZdY JXSyHm7qTr0Geky18nD721tWD9yWqR+7r5h4RBhQIN2T1Pnyk1zbzYrQ1H/xeNoV46Y9J 9TKj0fkqCllwaqCS0sygwfl3OlubQ943gPN2mYcXmfmiSHUdeeDrmYULmI4mFlApoAW6q RQFKSXAzfZ63TkrPjDwWHUHO0kDcyOCLZlYwcGLvHaypJAR1+u1da6NkzGklnKKGdWw==
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=HRs0MAPJ; 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 9F251606A68F for <netdev@vger.kernel.org>; Fri,  4 Dec 2026 03:46:59 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2D0F1F00A0E; Fri,  4 Dec 2026 03:46:58 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796356019; bh=G4Vt1p0nrt0ZvzpSXikzs1Xh1DK1DAwLeI4V+sQSNa4=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=HRs0MAPJWmh6nwPiF7KeEubK35J+PJgKLkv/aaixnKcee4ojBXPCqKfKRyBqE9+QK T2dxQFxfp2xCLf++eTXVo2RM7Oi12AA1fG0ptlaOrF9Cw+AaNdV/ZyTClNnrWb3bBt hLzj0+EGrhZ1rY5Kd7CD3wH7ePKaC9qeB25aWDEk547CpIIQII/JwRAw7pqCeS2zmc fOtzg9tqWquUW5lvb9fiuaOzooUgQYM1j0TBIAp+t9wkPn4HgWcH/zSRLA1Ok+ZhaA vvPhp76SdZT8d0tY8zNgbuLg6Iy/Z9rOwc+ln77IhmV9YaTDabGOZV4gGPjECduifm cpO6zFq+anvoA==
X-Cc: andy.moreton@amd.com, alex.austin@amd.com, netdev@vger.kernel.org, linux-net-drivers@amd.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com
X-In-Reply-To: <179626774776.1539442.17436520173285566977@jaeyeong.cc>
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
X-Received-Bytes: 13969