Article View: linux.kernel.netdev
Article #7311[PATCH nf] netfilter: flowtable: remove hardware flows before unbinding
From: Paul-Louis Charrière
Date: Mon, 26 Oct 2026 03:56
Date: Mon, 26 Oct 2026 03:56
68 lines
14490 bytes
14490 bytes
Since commit 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable
binding"), FLOW_BLOCK_UNBIND is called when the flowtable hooks are
unregistered, in the commit phase, and nf_flow_table_free() only tears
the flows down later. Their FLOW_CLS_DESTROY requests then find no
block callback, so the rules stay in hardware: the flows keep being
forwarded, and drivers such as mtk_eth_soc and mlx5 keep their entries
and reject a later flow with the same cookie with -EEXIST.
Commit 5acab91458ce ("netfilter: nf_tables: unbind callbacks from
flowtable destroy path") had placed the unbind after nf_flow_table_free()
for this reason.
Remove the flows of the device from the hardware in
nf_flow_table_offload_setup() before unbinding it, as
nf_flow_table_indr_cleanup() does for indirect blocks. The GC run that
nf_flow_table_gc_cleanup() waits for may skip flows with pending offload
work, or have started before the teardown, so queue the GC work once
more, wait for it and flush the delete work again. A direct
nf_flow_table_gc_run() would race with the GC worker. No BIND or
UNBIND call is added.
Found on a router with mtk_eth_soc flow offloading, where each firewall
reload left the flows of the old flowtable bound in the PPE. Jalen
reproduced it on mainline with mtk_eth_soc and mlx5 and tested this
change on both, see the report. Build-tested with W=1 and sparse on
arm64 and x86_64. In an arm64 guest with lockdep and KASAN, with TCP
flows through an offload flowtable on netdevsim ports, the delete work
of a deleted flowtable now runs before FLOW_BLOCK_UNBIND returns instead
of after it, and nft_offload.sh passes.
Fixes: 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable binding")
Reported-by: Jalen <jalen.lin@gmail.com>
Closes: https://lore.kernel.org/netfilter-devel/CAHqkChbVoGHrWtaFyGFaLQDiAunWw1qOpW-vKSgkKxWEfQ_tCg@mail.gmail.com/
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Paul-Louis Charrière <plcharriere@gmail.com>
---
net/netfilter/nf_flow_table_offload.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 4365859220e..3844a23af5b 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -1279,6 +1279,19 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,
if (!nf_flowtable_hw_offload(flowtable))
return nf_flow_offload_xdp_setup(flowtable, dev, cmd);
+ /* Hardware rules are deleted through the block callbacks, so delete
+ * the rules of this device's flows before unbinding it. Run the GC
+ * twice: the first run may skip flows with pending offload work, or
+ * have started before the teardown.
+ */
+ if (cmd == FLOW_BLOCK_UNBIND) {
+ nf_flow_table_gc_cleanup(flowtable, dev);
+ mod_delayed_work(system_power_efficient_wq,
+ &flowtable->gc_work, 0);
+ flush_delayed_work(&flowtable->gc_work);
+ flush_workqueue(nf_flow_offload_del_wq);
+ }
+
if (dev->netdev_ops->ndo_setup_tc)
err = nf_flow_table_offload_cmd(&bo, flowtable, dev, cmd,
&extack);
base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b
--
2.39.5
Technical Details
Message-ID:
<20261026035651.40052-1-plcharriere@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351680-linux-kernel-netdev=dewy.ruReferences:
<CAHqkChbVoGHrWtaFyGFaLQDiAunWw1qOpW-vKSgkKxWEfQ_tCg@mail.gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351680-linux-kernel-netdev=dewy.ru
From: plcharriere@gmail.com (Paul-Louis Charrière)
Newsgroups: linux.kernel.netdev
Subject: [PATCH nf] netfilter: flowtable: remove hardware flows before unbinding
Date: Mon, 26 Oct 2026 12:56:51 +0900
Organization: Usenet Network
Message-ID: <20261026035651.40052-1-plcharriere@gmail.com>
References: <CAHqkChbVoGHrWtaFyGFaLQDiAunWw1qOpW-vKSgkKxWEfQ_tCg@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1216472"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:RvgLtVlg1FCvXsdvBON3wf8ZWfc= sha256:N7G2zgCYpfnZrvRXkNg0wInCB4tfkMjogavuRKyEi5s=
sha1:ASOuJYJBfzkHK5yWceYWJoGxBGE= sha256:U1LsJ0UtDLxvFYLvTVRnWO7+gQmJ3kbPkvzhuGVNv7Y=
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 B4745125B88; Mon, 26 Oct 2026 06:58:07 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
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=gmail.com
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 cd8FgBeOA-o0;
Mon, 26 Oct 2026 06:57:59 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-351680-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 4CBF8125B87; Mon, 26 Oct 2026 06:57:49 +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 80E0B27DB4; Mon, 26 Oct 2026 03:57:16 +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=1792987036;
b=340/naXL6uXps1eSPnbzG7A4Pt0e/AlNUp9r5vh+HXTYzuzzH8sqkz6aCdjyYLHuEahl
RxYIzL1zMhNeu1EVKtVvk6c+rbnonewQKLAKnzn4ngxeBO9w3J9OBcXBsVM+oPCE2N+BF
uFUPLJuM0DhrytVaYs66otOt/6sa4TnNdXCIVLq/MY5uS3O0FdQHp6Nxd7xFQHlVAH6+c
2COGmgHy0JaLjOZr4pImw7VBIOff4Qk2X1RvuAMM1WH8vB95FJU3NcnOH9jy9g8c+uNsD
SuxTs5AR+msmyUv3xYv4UiFX3NcKI+RaXVpoLjCQIPoYt9Qn+maJbPEMaUgwslOwKaA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792987036;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:List-Post:
List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
MIME-Version:Content-Type:Content-Transfer-Encoding;
bh=+ScCUUWyJM//qpTpz7tt0Fdxp9XvYrNhMa0jbjZM+Ng=;
b=R2WlUcJUZ1ebJuae6FOdaBZOefCL9gYW4EVcO+LWHvc3Za3H897dBlXXooTmhgszfHra
9wsFAauaWOLdoKy+8jKNRggs+urPQfsv0S7GSNOYBQlHj2gHxhi+OS3ORdCgPmgfiQLoJ
dbthMClAMevT0XgZJ/TBSvnrq4ThwB2FoH/8fV8j0Xivnd0WSEpUmEDcXb8hqANY3h+R9
jNrPDm1lBlHtbMskS7nLyvzd0HfGiPoGrnJHYOe1zOxzHS9rK0SBLxhDWZphE8iBJ8uI+
CseqVDdmWoRw2VEq+X6btOff7AJ5EVIcQpg3l2C4vRRxWmOHqWiZDs61G0kxvbemRsw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=CzHL8JAA;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
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 57944606A323;
Mon, 26 Oct 2026 03:57:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=CzHL8JAA
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1792987035;
b=WpPU0QqRJqcd9llw8b6+r1XS5XfQoe2z0Yjzv3C6q0+Xu+LLM2w9ImfHh2cOm5XlVJoa
CQZtKlkElds8CpZ9t/7aHE6vVPRYpFKhYCfP35nkmDcByHtCswVE3dMiRu0UEoqYO7Ejw
A1kkdSiuyUJ9jFyi/nURRo6b6Oh0sgI09+s/Im/a4q9lNHds1mKTIR2nMCudMrB8vNgLD
MAKl1H7Nju4777HARgtdXrELaeU7FnsThCGWLsGIye18Xe+w+7Keb/sig6hEFT8R/Wd3a
4J7gj20yHWP1XjaC/2H6wwutp8zqXgLqdeep797Q+SkLuI4+sPXKwHaRmtNAjTYDJxg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792987035;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
MIME-Version:Content-Type:Content-Transfer-Encoding;
bh=+ScCUUWyJM//qpTpz7tt0Fdxp9XvYrNhMa0jbjZM+Ng=;
b=K6yx027O44JRBlNp28TMQHCcenR+hoFflksCtzNdwNskBD7+NLY7ldlLNP6K964nRSIP
J91emMmRTQsflOLSTSQesD+XtZf0gyKgwzPl1++HwQdk75DxrcqVN1oTdwEnFBpu3ekgZ
hSLP7+28rLfbzXafECErnpocgQd+gFsGQ6JNwd3EeWxrSQvi0GiMiybhyVdYU0A+ogV9L
a98krUJAkUHAhC/+IOIFaMgQxE9WNnOhHMfIfSjhFEChDT2PX2PMd/icQcc8+dMDOnIPk
cs6vVuTmbfKG9+pxtkyzUE+TDTfBsArQvQr1mdD8669Z/PMpo30amMg1+Z2gM36PIZQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=none smtp.remote-ip=74.125.82.170
X-Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 923C8606A31B
for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 03:57:09 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 923C8606A31B
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-35b2c599f43so467828eec.0
for <netdev@vger.kernel.org>; Sun, 25 Oct 2026 20:57:09 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792987029; x=1793591829; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=+ScCUUWyJM//qpTpz7tt0Fdxp9XvYrNhMa0jbjZM+Ng=;
b=CzHL8JAAhVXZp+BFIea6XXS5CXvIdKyvTb9rotyb9xP51zqNOdUyULSyK62QT2G7qO
7v7qzFb4ekjP8THGtkchX7EdobigL2eBQbw+WhyrhbXrSIQnzUg+mhL33OKcdQw/kCOl
zq1zDO6mrkZUzmX7FZqHcqcNncLTFdoz8LPdi0HLuB1F1rfz8enfQHRYXYoq422/oXFK
mPtlgYSvIeU9kcWQBdlA3APCubO0DXLc4kb8YveBwZWFD9FPg86N0L1cKM2rfH9DDam2
E2jObCINjT2AdecrPCYLiQbyEsbP7oepRFvC9D5xQPmCjEWHmKY3xEsXTQ/XabPJaAj2
pxDA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792987029; x=1793591829;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content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r5IIj9DkZiqitBALHyh7
2keqWQEXszbPTtxwJyetXmok1h+S1xYgQe6nqDlaXAsOm4XgUc4MzgFryLmjKp0NOtyloPCNlY5
ViQhFw633X7ar4+nUCi0z92T5MlRvxCz22Hn6nm3SgasneGfua8Wz2fsCoEyviL7lrvRVORZdG/
THMCz9VUeDmnwFllAE9SRrQvIRr0F3l0TN/yf4Uc1FMqkqInH4OybDvFvrxwVbbm/Jgk1Ry0
X-Received: by 2002:a05:7300:f0ce:b0:366:846a:e21d with SMTP id 5a478bee46e88-369e84d35c0mr9182619eec.33.1792987028486;
Sun, 25 Oct 2026 20:57:08 -0700 (PDT)
X-Received: from MacBookPro.lan (113x35x113x191.ap113.ftth.ucom.ne.jp. [113.35.113.191])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-369e8d93663sm24441240eec.13.2026.10.25.20.57.05
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Sun, 25 Oct 2026 20:57:08 -0700 (PDT)
X-Cc: Phil Sutter <phil@nwl.cc>,
netfilter-devel@vger.kernel.org,
coreteam@netfilter.org,
netdev@vger.kernel.org,
Jalen <jalen.lin@gmail.com>,
Felix Fietkau <nbd@nbd.name>,
Lorenzo Bianconi <lorenzo@kernel.org>,
Saeed Mahameed <saeedm@nvidia.com>,
Leon Romanovsky <leon@kernel.org>,
Tariq Toukan <tariqt@nvidia.com>,
Mark Bloch <mbloch@nvidia.com>,
regressions@lists.linux.dev,
Paul-Louis Charrière <plcharriere@gmail.com>,
stable@vger.kernel.org
X-Mailer: git-send-email 2.50.1
X-In-Reply-To: <CAHqkChbVoGHrWtaFyGFaLQDiAunWw1qOpW-vKSgkKxWEfQ_tCg@mail.gmail.com>
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