From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Fri, 4 Dec 2026 03:46:59 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2D0F1F00A0E; Fri, 4 Dec 2026 03:46:58 +0000 (UTC) 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== Subject: Re: [PATCH net-next] sfc: wait for RCU readers before reclaiming failed CT entries From: netdev-bot+sashiko@kernel.org To: lee@jaeyeong.cc 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 Date: Fri, 04 Dec 2026 03:46:58 +0000 Message-ID: <179635601846.3146.4375554711670849772@kernel.org> In-Reply-To: <179626774776.1539442.17436520173285566977@jaeyeong.cc> References: <179626774776.1539442.17436520173285566977@jaeyeong.cc> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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