* [PATCH net v3 1/5] net/sched: cls_u32: fix linked hash table refcount leak [not found] <20261130123028.516696-1-jedrzej.jagielski@intel.com> @ 2026-11-30 12:30 ` Jedrzej Jagielski 2026-11-30 19:07 ` Jamal Hadi Salim 2026-12-01 12:54 ` netdev-bot+sashiko 2026-11-30 12:30 ` [PATCH net v3 2/5] net/sched: cls_u32: remove erroneous refcount_inc() Jedrzej Jagielski ` (2 subsequent siblings) 3 siblings, 2 replies; 11+ messages in thread From: Jedrzej Jagielski @ 2026-11-30 12:30 UTC (permalink / raw) To: netdev Cc: anthony.l.nguyen, kuba, jhs, jiri, edumazet, Jedrzej Jagielski, stable, Sashiko When a new filter is created with TCA_U32_LINK, u32_set_parms() resolves the linked hash table and increments its reference count, storing it in n->ht_down. If u32_replace_hw_knode() subsequently fails, execution jumps to the errunbind label which frees the node with kfree(n) but never drops the reference on n->ht_down. This leaves the tc_u_hnode refcount permanently elevated, preventing it from being freed when the hash table is later deleted. Drop the ht_down reference at errunbind before freeing the node. This is a forward fix for currently dead code, which will be uncovered by the upcoming patch "net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags". Fixes: d34e3e181395 ("net: cls_u32: Add support for skip-sw flag to tc u32 classifier.") Cc: stable@vger.kernel.org Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://sashiko.dev/#/patchset/20260807100356.1083774-1-jedrzej.jagielski%40intel.com Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com> --- net/sched/cls_u32.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 91f4e6458785..c544c8e4e876 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -891,7 +891,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, struct netlink_ext_ack *extack) { struct tc_u_common *tp_c = tp->data; - struct tc_u_hnode *ht; + struct tc_u_hnode *ht, *ht_down; struct tc_u_knode *n; struct tc_u32_sel *s; struct nlattr *opt = tca[TCA_OPTIONS]; @@ -1221,6 +1221,9 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, errunbind: u32_unbind_filter(tp, n, tb); + ht_down = rtnl_dereference(n->ht_down); + if (ht_down && refcount_dec_and_test(&ht_down->refcnt)) + kfree(ht_down); #ifdef CONFIG_CLS_U32_MARK free_percpu(n->pcpu_success); -- 2.31.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH net v3 1/5] net/sched: cls_u32: fix linked hash table refcount leak 2026-11-30 12:30 ` [PATCH net v3 1/5] net/sched: cls_u32: fix linked hash table refcount leak Jedrzej Jagielski @ 2026-11-30 19:07 ` Jamal Hadi Salim 2026-12-01 12:54 ` netdev-bot+sashiko 1 sibling, 0 replies; 11+ messages in thread From: Jamal Hadi Salim @ 2026-11-30 19:07 UTC (permalink / raw) To: Jedrzej Jagielski Cc: netdev, anthony.l.nguyen, kuba, jiri, edumazet, stable, Sashiko On Mon, Nov 30, 2026 at 7:52 AM Jedrzej Jagielski <jedrzej.jagielski@intel.com> wrote: > > When a new filter is created with TCA_U32_LINK, u32_set_parms() resolves > the linked hash table and increments its reference count, storing it in > n->ht_down. > > If u32_replace_hw_knode() subsequently fails, execution jumps to the > errunbind label which frees the node with kfree(n) but never drops the > reference on n->ht_down. This leaves the tc_u_hnode refcount permanently > elevated, preventing it from being freed when the hash table is later > deleted. > > Drop the ht_down reference at errunbind before freeing the node. > > This is a forward fix for currently dead code, which will be uncovered > by the upcoming patch "net/sched: cls_u32: feed u32_replace_hw_knode() > with correct set of flags". > > Fixes: d34e3e181395 ("net: cls_u32: Add support for skip-sw flag to tc u32 classifier.") > Cc: stable@vger.kernel.org > Reported-by: Sashiko <sashiko-bot@kernel.org> > Closes: https://sashiko.dev/#/patchset/20260807100356.1083774-1-jedrzej.jagielski%40intel.com > Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com> Reviewed-by: Jamal Hadi Salim <jhs@mojatatu.com> cheers, jamal > --- > net/sched/cls_u32.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c > index 91f4e6458785..c544c8e4e876 100644 > --- a/net/sched/cls_u32.c > +++ b/net/sched/cls_u32.c > @@ -891,7 +891,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, > struct netlink_ext_ack *extack) > { > struct tc_u_common *tp_c = tp->data; > - struct tc_u_hnode *ht; > + struct tc_u_hnode *ht, *ht_down; > struct tc_u_knode *n; > struct tc_u32_sel *s; > struct nlattr *opt = tca[TCA_OPTIONS]; > @@ -1221,6 +1221,9 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, > > errunbind: > u32_unbind_filter(tp, n, tb); > + ht_down = rtnl_dereference(n->ht_down); > + if (ht_down && refcount_dec_and_test(&ht_down->refcnt)) > + kfree(ht_down); > > #ifdef CONFIG_CLS_U32_MARK > free_percpu(n->pcpu_success); > -- > 2.31.1 > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net v3 1/5] net/sched: cls_u32: fix linked hash table refcount leak 2026-11-30 12:30 ` [PATCH net v3 1/5] net/sched: cls_u32: fix linked hash table refcount leak Jedrzej Jagielski 2026-11-30 19:07 ` Jamal Hadi Salim @ 2026-12-01 12:54 ` netdev-bot+sashiko 1 sibling, 0 replies; 11+ messages in thread From: netdev-bot+sashiko @ 2026-12-01 12:54 UTC (permalink / raw) To: jedrzej.jagielski Cc: netdev, anthony.l.nguyen, kuba, jhs, jiri, edumazet, stable, sashiko-bot Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin. Low priority / nit picks for your consideration: - [Low] The commit message calls the fixed path "currently dead code" that only becomes live once "net/sched: cls_u32: feed… -- net/sched: cls_u32: fix linked hash table refcount leak This patch drops the reference on n->ht_down at the errunbind label in u32_change(). With it, a failed u32_replace_hw_knode() call no longer leaks the refcount on the linked tc_u_hnode. The commit message calls this a forward fix for an error path that can't be reached yet. > This is a forward fix for currently dead code, which will be uncovered > by the upcoming patch "net/sched: cls_u32: feed u32_replace_hw_knode() > with correct set of flags". > > Fixes: d34e3e181395 ("net: cls_u32: Add support for skip-sw flag to tc u32 classifier.") > Cc: stable@vger.kernel.org [Severity: Low] Is "currently dead code" accurate for every tree the Cc: stable tag will reach? In mainline the path does look unreachable. u32_change() passes the kernel request flags (TCA_ACT_FLAGS_*) instead of userflags: err = u32_replace_hw_knode(tp, n, flags, extack); So tc_skip_sw(flags) in u32_replace_hw_knode() is always false. That means tc_setup_cb_add() runs with err_stop=false and returns 0. Before 695176bfe5de ("net_sched: refactor TC action init API") in v5.15, u32_change() passed the user flags directly: flags = nla_get_u32(tb[TCA_U32_FLAGS]); ... err = u32_replace_hw_knode(tp, n, flags, extack); In a tree like 5.10, take a skip_sw filter with TCA_U32_LINK on a block that cannot offload. tc_setup_cb_add() then returns -EOPNOTSUPP. The errhw path frees n with kfree(n) but never drops the refcount on n->ht_down. After that, refcount_dec_if_one() fails in u32_delete(), so deleting the linked hash table returns -EBUSY. In those trees, anyone with CAP_NET_ADMIN in a network namespace can trigger the leak today. This patch also won't apply there as written. v5.10 has no errunbind label and no u32_unbind_filter() call, so it would need a manual backport. The enabling patch named here would carry Fixes: 695176bfe5de, so it won't reach pre-5.15 trees either. For v5.15 and later, the dependency on that companion patch is already stated clearly. Could the commit message mention that the leak is live in stable trees older than v5.15? Otherwise, someone handling a failed-to-apply stable report could drop this fix for 5.10, the one tree where it fixes a bug that can actually be reached. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130123028.516696-1-jedrzej.jagielski%40intel.com ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net v3 2/5] net/sched: cls_u32: remove erroneous refcount_inc() [not found] <20261130123028.516696-1-jedrzej.jagielski@intel.com> 2026-11-30 12:30 ` [PATCH net v3 1/5] net/sched: cls_u32: fix linked hash table refcount leak Jedrzej Jagielski @ 2026-11-30 12:30 ` Jedrzej Jagielski 2026-11-30 19:07 ` Jamal Hadi Salim 2026-11-30 12:30 ` [PATCH net v3 3/5] net/sched: cls_u32: don't remove old HW rule on failed knode replace Jedrzej Jagielski 2026-11-30 12:30 ` [PATCH net v3 4/5] net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags Jedrzej Jagielski 3 siblings, 1 reply; 11+ messages in thread From: Jedrzej Jagielski @ 2026-11-30 12:30 UTC (permalink / raw) To: netdev Cc: anthony.l.nguyen, kuba, jhs, jiri, edumazet, Jedrzej Jagielski, stable, Sashiko Remove the redundant refcount_inc(&ht_old->refcnt) in the u32_replace_hw_knode() error path during filter update. Commit e8d3d78c19be ("net: sched: cls_u32: Undo refcount decrement in case update failed") added this increment to "undo" a decrement performed by u32_set_parms() on the original node's linked hash table but apparently this decrement is already balanced by u32_init_knode(), which increments the same refcount when cloning the original node: u32_init_knode(): refcount_inc() on the old ht_down u32_set_parms(): refcount_dec() on ht_old __u32_destroy_key(new): drops new->ht_down These cancel out, leaving the original hash table's refcount unchanged. The additional refcount_inc in the error path has no matching decrement, leaving the tc_u_hnode refcount permanently elevated by 1. This prevents the hash table from ever being freed, leaking memory. __u32_destroy_key(new) already correctly drops new->ht_down's refcount (the new linked hash table set by u32_set_parms), so no manual refcount fixup is needed. This is a forward fix for currently dead code, which will be uncovered by the upcoming patch "net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags". Fixes: e8d3d78c19be ("net: sched: cls_u32: Undo refcount decrement in case update failed") Cc: stable@vger.kernel.org Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://sashiko.dev/#/patchset/20260807100356.1083774-1-jedrzej.jagielski%40intel.com Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com> --- net/sched/cls_u32.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index c544c8e4e876..ae1b6476f921 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -954,14 +954,6 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, err = u32_replace_hw_knode(tp, new, flags, extack); if (err) { u32_unbind_filter(tp, new, tb); - - if (tb[TCA_U32_LINK]) { - struct tc_u_hnode *ht_old; - - ht_old = rtnl_dereference(n->ht_down); - if (ht_old) - refcount_inc(&ht_old->refcnt); - } __u32_destroy_key(new); return err; } -- 2.31.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH net v3 2/5] net/sched: cls_u32: remove erroneous refcount_inc() 2026-11-30 12:30 ` [PATCH net v3 2/5] net/sched: cls_u32: remove erroneous refcount_inc() Jedrzej Jagielski @ 2026-11-30 19:07 ` Jamal Hadi Salim 0 siblings, 0 replies; 11+ messages in thread From: Jamal Hadi Salim @ 2026-11-30 19:07 UTC (permalink / raw) To: Jedrzej Jagielski Cc: netdev, anthony.l.nguyen, kuba, jiri, edumazet, stable, Sashiko On Mon, Nov 30, 2026 at 7:52 AM Jedrzej Jagielski <jedrzej.jagielski@intel.com> wrote: > > Remove the redundant refcount_inc(&ht_old->refcnt) in the > u32_replace_hw_knode() error path during filter update. > > Commit e8d3d78c19be ("net: sched: cls_u32: Undo refcount decrement in case update failed") > added this increment to "undo" a decrement performed by u32_set_parms() > on the original node's linked hash table but apparently this decrement > is already balanced by u32_init_knode(), which increments the same > refcount when cloning the original node: > > u32_init_knode(): refcount_inc() on the old ht_down > u32_set_parms(): refcount_dec() on ht_old > __u32_destroy_key(new): drops new->ht_down > > These cancel out, leaving the original hash table's refcount unchanged. > The additional refcount_inc in the error path has no matching decrement, > leaving the tc_u_hnode refcount permanently elevated by 1. This > prevents the hash table from ever being freed, leaking memory. > > __u32_destroy_key(new) already correctly drops new->ht_down's refcount > (the new linked hash table set by u32_set_parms), so no manual refcount > fixup is needed. > > This is a forward fix for currently dead code, which will be uncovered > by the upcoming patch "net/sched: cls_u32: feed u32_replace_hw_knode() > with correct set of flags". > > Fixes: e8d3d78c19be ("net: sched: cls_u32: Undo refcount decrement in case update failed") > Cc: stable@vger.kernel.org > Reported-by: Sashiko <sashiko-bot@kernel.org> > Closes: https://sashiko.dev/#/patchset/20260807100356.1083774-1-jedrzej.jagielski%40intel.com > Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com> Reviewed-by: Jamal Hadi Salim <jhs@mojatatu.com> cheers, jamal > --- > net/sched/cls_u32.c | 8 -------- > 1 file changed, 8 deletions(-) > > diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c > index c544c8e4e876..ae1b6476f921 100644 > --- a/net/sched/cls_u32.c > +++ b/net/sched/cls_u32.c > @@ -954,14 +954,6 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, > err = u32_replace_hw_knode(tp, new, flags, extack); > if (err) { > u32_unbind_filter(tp, new, tb); > - > - if (tb[TCA_U32_LINK]) { > - struct tc_u_hnode *ht_old; > - > - ht_old = rtnl_dereference(n->ht_down); > - if (ht_old) > - refcount_inc(&ht_old->refcnt); > - } > __u32_destroy_key(new); > return err; > } > -- > 2.31.1 > ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net v3 3/5] net/sched: cls_u32: don't remove old HW rule on failed knode replace [not found] <20261130123028.516696-1-jedrzej.jagielski@intel.com> 2026-11-30 12:30 ` [PATCH net v3 1/5] net/sched: cls_u32: fix linked hash table refcount leak Jedrzej Jagielski 2026-11-30 12:30 ` [PATCH net v3 2/5] net/sched: cls_u32: remove erroneous refcount_inc() Jedrzej Jagielski @ 2026-11-30 12:30 ` Jedrzej Jagielski 2026-11-30 19:18 ` Jamal Hadi Salim 2026-11-30 12:30 ` [PATCH net v3 4/5] net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags Jedrzej Jagielski 3 siblings, 1 reply; 11+ messages in thread From: Jedrzej Jagielski @ 2026-11-30 12:30 UTC (permalink / raw) To: netdev Cc: anthony.l.nguyen, kuba, jhs, jiri, edumazet, Jedrzej Jagielski, stable, Sashiko On knode replace, u32_init_knode() copies the handle of the existing knode into the new one. If offloading the new knode fails, u32_replace_hw_knode() rolls back with u32_remove_hw_knode(), which issues TC_CLSU32_DELETE_KNODE for that shared handle and so removes the HW rule of the old knode, which is still installed in software. For a skip_sw filter, u32_classify() skips it, so the filter matches neither in SW nor in HW, while userspace is told the replace failed. Add @new_handle to u32_replace_hw_knode() and roll back only when the handle is not shared with an installed knode, i.e. when adding a new one. On replace, leave the old HW rule in place, in line with tc_setup_cb_add() treating a failed add as non-destructive. This is a trade-off for blocks with multiple offload callbacks. tc_setup_cb_add() stops at the first failing callback, so callbacks which accepted the replace before it keep the new rule, and its link_handle may refer to an hnode no longer referenced in software once the new knode is destroyed. The removed rollback deleted the rule on all callbacks instead, including those which rejected the replace and still held the old rule. Since commit 695176bfe5de ("net_sched: refactor TC action init API") skip_sw is ignored, so the same split HW state is left, but silently and with the new knode installed in software. Let userspace know via extack that hardware may be partially updated, without overriding a reason set by the driver. Rolling back per callback is not possible, as tc_setup_cb_add() does not report which callbacks succeeded and drivers identify u32 rules by handle only. Re-offloading the old knode is not done either, as drivers which reject an existing handle (e.g. ixgbe) or handle REPLACE_KNODE as an add (e.g. cxgb4) would not be restored by it. Drivers which destroy the old rule themselves when REPLACE_KNODE fails (e.g. stmmac, nfp abm) still lose it, which is not changed by this patch. This is a forward fix for currently dead code, which will be uncovered by the upcoming patch "net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags". Fixes: 245dc5121a9b ("net: sched: cls_u32: call block callbacks for offload") Cc: stable@vger.kernel.org Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260813122242.1690024-1-jedrzej.jagielski%40intel.com Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com> --- net/sched/cls_u32.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index ae1b6476f921..bf4dc4244b84 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -548,7 +548,8 @@ static void u32_remove_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, } static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, - u32 flags, struct netlink_ext_ack *extack) + u32 flags, bool new_handle, + struct netlink_ext_ack *extack) { struct tc_u_hnode *ht = rtnl_dereference(n->ht_down); struct tcf_block *block = tp->chain->block; @@ -576,7 +577,11 @@ static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, err = tc_setup_cb_add(block, tp, TC_SETUP_CLSU32, &cls_u32, skip_sw, &n->flags, &n->in_hw_count, true); if (err) { - u32_remove_hw_knode(tp, n, NULL); + if (new_handle) + u32_remove_hw_knode(tp, n, NULL); + else + NL_SET_ERR_MSG_WEAK_MOD(extack, + "Replace failed, hardware may be partially updated"); return err; } @@ -951,7 +956,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, u32_bind_filter(tp, new, base, tb); - err = u32_replace_hw_knode(tp, new, flags, extack); + err = u32_replace_hw_knode(tp, new, flags, false, extack); if (err) { u32_unbind_filter(tp, new, tb); __u32_destroy_key(new); @@ -1189,7 +1194,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, struct tc_u_knode __rcu **ins; struct tc_u_knode *pins; - err = u32_replace_hw_knode(tp, n, flags, extack); + err = u32_replace_hw_knode(tp, n, flags, true, extack); if (err) goto errunbind; -- 2.31.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH net v3 3/5] net/sched: cls_u32: don't remove old HW rule on failed knode replace 2026-11-30 12:30 ` [PATCH net v3 3/5] net/sched: cls_u32: don't remove old HW rule on failed knode replace Jedrzej Jagielski @ 2026-11-30 19:18 ` Jamal Hadi Salim 2026-11-30 19:19 ` Jamal Hadi Salim 0 siblings, 1 reply; 11+ messages in thread From: Jamal Hadi Salim @ 2026-11-30 19:18 UTC (permalink / raw) To: Jedrzej Jagielski Cc: netdev, anthony.l.nguyen, kuba, jiri, edumazet, stable, Sashiko On Mon, Nov 30, 2026 at 7:53 AM Jedrzej Jagielski <jedrzej.jagielski@intel.com> wrote: > > On knode replace, u32_init_knode() copies the handle of the existing > knode into the new one. If offloading the new knode fails, > u32_replace_hw_knode() rolls back with u32_remove_hw_knode(), which > issues TC_CLSU32_DELETE_KNODE for that shared handle and so removes > the HW rule of the old knode, which is still installed in software. > For a skip_sw filter, u32_classify() skips it, so the filter matches > neither in SW nor in HW, while userspace is told the replace failed. > > Add @new_handle to u32_replace_hw_knode() and roll back only when the > handle is not shared with an installed knode, i.e. when adding a new > one. On replace, leave the old HW rule in place, in line with > tc_setup_cb_add() treating a failed add as non-destructive. > > This is a trade-off for blocks with multiple offload callbacks. > tc_setup_cb_add() stops at the first failing callback, so callbacks > which accepted the replace before it keep the new rule, and its > link_handle may refer to an hnode no longer referenced in software > once the new knode is destroyed. The removed rollback deleted the rule > on all callbacks instead, including those which rejected the replace > and still held the old rule. Since commit 695176bfe5de ("net_sched: > refactor TC action init API") skip_sw is ignored, so the same split > HW state is left, but silently and with the new knode installed in > software. Let userspace know via extack that hardware may be > partially updated, without overriding a reason set by the driver. > > Rolling back per callback is not possible, as tc_setup_cb_add() does > not report which callbacks succeeded and drivers identify u32 rules by > handle only. Re-offloading the old knode is not done either, as > drivers which reject an existing handle (e.g. ixgbe) or handle > REPLACE_KNODE as an add (e.g. cxgb4) would not be restored by it. > > Drivers which destroy the old rule themselves when REPLACE_KNODE fails > (e.g. stmmac, nfp abm) still lose it, which is not changed by this > patch. > > This is a forward fix for currently dead code, which will be uncovered > by the upcoming patch "net/sched: cls_u32: feed u32_replace_hw_knode() > with correct set of flags". > > Fixes: 245dc5121a9b ("net: sched: cls_u32: call block callbacks for offload") > Cc: stable@vger.kernel.org > Reported-by: Sashiko <sashiko-bot@kernel.org> > Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260813122242.1690024-1-jedrzej.jagielski%40intel.com > Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com> > --- > net/sched/cls_u32.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c > index ae1b6476f921..bf4dc4244b84 100644 > --- a/net/sched/cls_u32.c > +++ b/net/sched/cls_u32.c > @@ -548,7 +548,8 @@ static void u32_remove_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, > } > > static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, > - u32 flags, struct netlink_ext_ack *extack) > + u32 flags, bool new_handle, > + struct netlink_ext_ack *extack) > { > struct tc_u_hnode *ht = rtnl_dereference(n->ht_down); > struct tcf_block *block = tp->chain->block; > @@ -576,7 +577,11 @@ static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, > err = tc_setup_cb_add(block, tp, TC_SETUP_CLSU32, &cls_u32, skip_sw, > &n->flags, &n->in_hw_count, true); > if (err) { > - u32_remove_hw_knode(tp, n, NULL); > + if (new_handle) > + u32_remove_hw_knode(tp, n, NULL); > + else > + NL_SET_ERR_MSG_WEAK_MOD(extack, > + "Replace failed, hardware may be partially updated"); Nitpick: The extack msg is a bit misleading saying hardware may be partially updated even when the block has no offload device and no callback ran. This can only be true if the block has more than one callback and an earlier one accepted before a later one rejected. On a block with a non-offload device, tc_setup_cb_add() returns -EOPNOTSUPP before invoking anything, and with a single rejecting driver nothing changes either the common cases get a false warning. The caller can't tell those apart; i dont have a good answer but maybe add !block->nooffloaddevcnt and word it as "hardware rollback was skipped" cheers, jamal > return err; > } > > @@ -951,7 +956,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, > > u32_bind_filter(tp, new, base, tb); > > - err = u32_replace_hw_knode(tp, new, flags, extack); > + err = u32_replace_hw_knode(tp, new, flags, false, extack); > if (err) { > u32_unbind_filter(tp, new, tb); > __u32_destroy_key(new); > @@ -1189,7 +1194,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, > struct tc_u_knode __rcu **ins; > struct tc_u_knode *pins; > > - err = u32_replace_hw_knode(tp, n, flags, extack); > + err = u32_replace_hw_knode(tp, n, flags, true, extack); > if (err) > goto errunbind; > > -- > 2.31.1 > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net v3 3/5] net/sched: cls_u32: don't remove old HW rule on failed knode replace 2026-11-30 19:18 ` Jamal Hadi Salim @ 2026-11-30 19:19 ` Jamal Hadi Salim 0 siblings, 0 replies; 11+ messages in thread From: Jamal Hadi Salim @ 2026-11-30 19:19 UTC (permalink / raw) To: Jedrzej Jagielski Cc: netdev, anthony.l.nguyen, kuba, jiri, edumazet, stable, Sashiko On Mon, Nov 30, 2026 at 2:18 PM Jamal Hadi Salim <jhs@mojatatu.com> wrote: > > On Mon, Nov 30, 2026 at 7:53 AM Jedrzej Jagielski > <jedrzej.jagielski@intel.com> wrote: > > > > On knode replace, u32_init_knode() copies the handle of the existing > > knode into the new one. If offloading the new knode fails, > > u32_replace_hw_knode() rolls back with u32_remove_hw_knode(), which > > issues TC_CLSU32_DELETE_KNODE for that shared handle and so removes > > the HW rule of the old knode, which is still installed in software. > > For a skip_sw filter, u32_classify() skips it, so the filter matches > > neither in SW nor in HW, while userspace is told the replace failed. > > > > Add @new_handle to u32_replace_hw_knode() and roll back only when the > > handle is not shared with an installed knode, i.e. when adding a new > > one. On replace, leave the old HW rule in place, in line with > > tc_setup_cb_add() treating a failed add as non-destructive. > > > > This is a trade-off for blocks with multiple offload callbacks. > > tc_setup_cb_add() stops at the first failing callback, so callbacks > > which accepted the replace before it keep the new rule, and its > > link_handle may refer to an hnode no longer referenced in software > > once the new knode is destroyed. The removed rollback deleted the rule > > on all callbacks instead, including those which rejected the replace > > and still held the old rule. Since commit 695176bfe5de ("net_sched: > > refactor TC action init API") skip_sw is ignored, so the same split > > HW state is left, but silently and with the new knode installed in > > software. Let userspace know via extack that hardware may be > > partially updated, without overriding a reason set by the driver. > > > > Rolling back per callback is not possible, as tc_setup_cb_add() does > > not report which callbacks succeeded and drivers identify u32 rules by > > handle only. Re-offloading the old knode is not done either, as > > drivers which reject an existing handle (e.g. ixgbe) or handle > > REPLACE_KNODE as an add (e.g. cxgb4) would not be restored by it. > > > > Drivers which destroy the old rule themselves when REPLACE_KNODE fails > > (e.g. stmmac, nfp abm) still lose it, which is not changed by this > > patch. > > > > This is a forward fix for currently dead code, which will be uncovered > > by the upcoming patch "net/sched: cls_u32: feed u32_replace_hw_knode() > > with correct set of flags". > > > > Fixes: 245dc5121a9b ("net: sched: cls_u32: call block callbacks for offload") > > Cc: stable@vger.kernel.org > > Reported-by: Sashiko <sashiko-bot@kernel.org> > > Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260813122242.1690024-1-jedrzej.jagielski%40intel.com > > Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com> > > --- > > net/sched/cls_u32.c | 13 +++++++++---- > > 1 file changed, 9 insertions(+), 4 deletions(-) > > > > diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c > > index ae1b6476f921..bf4dc4244b84 100644 > > --- a/net/sched/cls_u32.c > > +++ b/net/sched/cls_u32.c > > @@ -548,7 +548,8 @@ static void u32_remove_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, > > } > > > > static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, > > - u32 flags, struct netlink_ext_ack *extack) > > + u32 flags, bool new_handle, > > + struct netlink_ext_ack *extack) > > { > > struct tc_u_hnode *ht = rtnl_dereference(n->ht_down); > > struct tcf_block *block = tp->chain->block; > > @@ -576,7 +577,11 @@ static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, > > err = tc_setup_cb_add(block, tp, TC_SETUP_CLSU32, &cls_u32, skip_sw, > > &n->flags, &n->in_hw_count, true); > > if (err) { > > - u32_remove_hw_knode(tp, n, NULL); > > + if (new_handle) > > + u32_remove_hw_knode(tp, n, NULL); > > + else > > + NL_SET_ERR_MSG_WEAK_MOD(extack, > > + "Replace failed, hardware may be partially updated"); > > Nitpick: > The extack msg is a bit misleading saying hardware may be partially > updated even when the block has no offload device and no callback ran. > This can only be true if the block has more than one callback and an > earlier one accepted before a later one rejected. > On a block with a non-offload device, tc_setup_cb_add() returns > -EOPNOTSUPP before invoking anything, and with a single rejecting > driver nothing changes either the common cases get a false warning. > The caller can't tell those apart; i dont have a good answer but maybe > add !block->nooffloaddevcnt and word it as "hardware rollback was > skipped" Along: } else if (!block->nooffloaddevcnt) { NL_SET_ERR_MSG_WEAK_MOD(extack, "Replace failed, hardware rollback was skipped"); } cheers, jamal > > cheers, > jamal > > > return err; > > } > > > > @@ -951,7 +956,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, > > > > u32_bind_filter(tp, new, base, tb); > > > > - err = u32_replace_hw_knode(tp, new, flags, extack); > > + err = u32_replace_hw_knode(tp, new, flags, false, extack); > > if (err) { > > u32_unbind_filter(tp, new, tb); > > __u32_destroy_key(new); > > @@ -1189,7 +1194,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, > > struct tc_u_knode __rcu **ins; > > struct tc_u_knode *pins; > > > > - err = u32_replace_hw_knode(tp, n, flags, extack); > > + err = u32_replace_hw_knode(tp, n, flags, true, extack); > > if (err) > > goto errunbind; > > > > > > -- > > 2.31.1 > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net v3 4/5] net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags [not found] <20261130123028.516696-1-jedrzej.jagielski@intel.com> ` (2 preceding siblings ...) 2026-11-30 12:30 ` [PATCH net v3 3/5] net/sched: cls_u32: don't remove old HW rule on failed knode replace Jedrzej Jagielski @ 2026-11-30 12:30 ` Jedrzej Jagielski 2026-11-30 19:25 ` Jamal Hadi Salim 2026-12-01 12:54 ` netdev-bot+sashiko 3 siblings, 2 replies; 11+ messages in thread From: Jedrzej Jagielski @ 2026-11-30 12:30 UTC (permalink / raw) To: netdev Cc: anthony.l.nguyen, kuba, jhs, jiri, edumazet, Jedrzej Jagielski, stable, Marcin Szycik, Przemek Kitszel When trying to offload u32 cmd by adding skip_sw attributes it gets ignored and it cannot be correctly processed by HW and tc_cls_u32_offload struct which is then passed to driver lacks skip_sw var enabled. Encountered the issue while developing ixgbe. u32_replace_hw_knode is fed with the TCA_ACT_* flags (bits 16+) instead of TCA_CLS_* flags (bits 0-4) which actually stores the flags parsed by tc, so tc_skip_sw() always returns false. This leads to ignoring some of the attributes which meant to be configured on filter setup. None of the TCA_ACT_FLAGS_* is actually used within u32_replace_hw_knode(), so there's no point in passing them. Other classifiers do not put TCA_ACT_FLAGS_* during filter setup. Looks like commit 695176bfe5de ("net_sched: refactor TC action init API") shadowed the local flags variable which used to be set with nla_get_u32(tb[TCA_U32_FLAGS]) with the flags as the new function param while not replacing for none of the u32_replace_hw_knode() calls. Because skip_sw is now honored, "tc ... u32 ... skip_sw" add/replace commands that previously succeeded (and were silently skipped by the software path) will now return -EOPNOTSUPP/-EINVAL when the block or driver cannot offload the filter. Fixes: 695176bfe5de ("net_sched: refactor TC action init API") Cc: stable@vger.kernel.org Reviewed-by: Marcin Szycik <marcin.szycik@linux.intel.com> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com> --- net/sched/cls_u32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index bf4dc4244b84..48c581d6830c 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -956,7 +956,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, u32_bind_filter(tp, new, base, tb); - err = u32_replace_hw_knode(tp, new, flags, false, extack); + err = u32_replace_hw_knode(tp, new, userflags, false, extack); if (err) { u32_unbind_filter(tp, new, tb); __u32_destroy_key(new); @@ -1194,7 +1194,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, struct tc_u_knode __rcu **ins; struct tc_u_knode *pins; - err = u32_replace_hw_knode(tp, n, flags, true, extack); + err = u32_replace_hw_knode(tp, n, userflags, true, extack); if (err) goto errunbind; -- 2.31.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH net v3 4/5] net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags 2026-11-30 12:30 ` [PATCH net v3 4/5] net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags Jedrzej Jagielski @ 2026-11-30 19:25 ` Jamal Hadi Salim 2026-12-01 12:54 ` netdev-bot+sashiko 1 sibling, 0 replies; 11+ messages in thread From: Jamal Hadi Salim @ 2026-11-30 19:25 UTC (permalink / raw) To: Jedrzej Jagielski Cc: netdev, anthony.l.nguyen, kuba, jiri, edumazet, stable, Marcin Szycik, Przemek Kitszel On Mon, Nov 30, 2026 at 7:53 AM Jedrzej Jagielski <jedrzej.jagielski@intel.com> wrote: > > When trying to offload u32 cmd by adding skip_sw attributes it gets > ignored and it cannot be correctly processed by HW and tc_cls_u32_offload > struct which is then passed to driver lacks skip_sw var enabled. > > Encountered the issue while developing ixgbe. > > u32_replace_hw_knode is fed with the TCA_ACT_* flags (bits 16+) > instead of TCA_CLS_* flags (bits 0-4) which actually stores the flags > parsed by tc, so tc_skip_sw() always returns false. This leads to > ignoring some of the attributes which meant to be configured on filter > setup. > > None of the TCA_ACT_FLAGS_* is actually used within > u32_replace_hw_knode(), so there's no point in passing them. > > Other classifiers do not put TCA_ACT_FLAGS_* during filter setup. > > Looks like commit 695176bfe5de ("net_sched: refactor TC action init API") > shadowed the local flags variable which used to be set with > nla_get_u32(tb[TCA_U32_FLAGS]) with the flags as the new function param > while not replacing for none of the u32_replace_hw_knode() calls. > > Because skip_sw is now honored, "tc ... u32 ... skip_sw" add/replace > commands that previously succeeded (and were silently skipped by the > software path) will now return -EOPNOTSUPP/-EINVAL when the block or > driver cannot offload the filter. > > Fixes: 695176bfe5de ("net_sched: refactor TC action init API") > Cc: stable@vger.kernel.org > Reviewed-by: Marcin Szycik <marcin.szycik@linux.intel.com> > Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> > Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com> > --- > net/sched/cls_u32.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c > index bf4dc4244b84..48c581d6830c 100644 > --- a/net/sched/cls_u32.c > +++ b/net/sched/cls_u32.c > @@ -956,7 +956,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, > > u32_bind_filter(tp, new, base, tb); > > - err = u32_replace_hw_knode(tp, new, flags, false, extack); > + err = u32_replace_hw_knode(tp, new, userflags, false, extack); > if (err) { > u32_unbind_filter(tp, new, tb); > __u32_destroy_key(new); > @@ -1194,7 +1194,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, > struct tc_u_knode __rcu **ins; > struct tc_u_knode *pins; > > - err = u32_replace_hw_knode(tp, n, flags, true, extack); > + err = u32_replace_hw_knode(tp, n, userflags, true, extack); > if (err) > goto errunbind; skip_hw is still not honoured. u32_replace_hw_knode() and u32_replace_hw_hnode() only test tc_skip_sw(); a skip_hw filter is still handed to the driver, can pick up IN_HW/offloadcnt, and u32_reoffload() then skips its removal on unbind so the block stays offload-in-use. Please check both on !tc_skip_hw(flags) (cls_flower/cls_matchall do it themselves), or say on-list that it's deferred to the existing follow-up) cheers, jamal > -- > 2.31.1 > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net v3 4/5] net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags 2026-11-30 12:30 ` [PATCH net v3 4/5] net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags Jedrzej Jagielski 2026-11-30 19:25 ` Jamal Hadi Salim @ 2026-12-01 12:54 ` netdev-bot+sashiko 1 sibling, 0 replies; 11+ messages in thread From: netdev-bot+sashiko @ 2026-12-01 12:54 UTC (permalink / raw) To: jedrzej.jagielski Cc: netdev, anthony.l.nguyen, kuba, jhs, jiri, edumazet, stable, sashiko-bot Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 0 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] This patch passes `userflags` into u32_replace_hw_knode(), so a `skip_sw` knode now reaches tc_setup_cb_add() with err_stop=true. -- net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags This commit passes the parsed TCA_U32_FLAGS value (userflags) to u32_replace_hw_knode() instead of the TCA_ACT_FLAGS_* flags argument of u32_change(). With this change, tc_skip_sw() sees skip_sw and the offload path honours it. > diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c > index bf4dc4244b84a..48c581d6830c9 100644 > --- a/net/sched/cls_u32.c > +++ b/net/sched/cls_u32.c [ ... ] > @@ -1194,7 +1194,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, > struct tc_u_knode __rcu **ins; > struct tc_u_knode *pins; > > - err = u32_replace_hw_knode(tp, n, flags, true, extack); > + err = u32_replace_hw_knode(tp, n, userflags, true, extack); [Severity: Medium] With skip_sw now reaching tc_setup_cb_add() as err_stop=true, the error branch in u32_replace_hw_knode() can run for the first time since 695176bfe5de. Can that rollback remove an unrelated filter from hardware? net/sched/cls_u32.c:u32_replace_hw_knode() { ... err = tc_setup_cb_add(block, tp, TC_SETUP_CLSU32, &cls_u32, skip_sw, &n->flags, &n->in_hw_count, true); if (err) { if (new_handle) u32_remove_hw_knode(tp, n, NULL); ... } u32_remove_hw_knode() sends TC_CLSU32_DELETE_KNODE through tc_setup_cb_destroy() to every block callback. That includes the driver that has just rejected the add and never programmed the knode. In ixgbe, the driver named in the commit message, root table knodes (uhtid 0x800) are deleted by slot alone. The child_loc_map ownership check is skipped: drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:ixgbe_delete_clsu32() { ... u32 loc = cls->knode.handle & 0xfffff; ... if (uhtid != 0x800) { ... if (!test_bit(loc - 1, jump->child_loc_map)) return -EINVAL; ... spin_lock(&adapter->fdir_perfect_lock); err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc); spin_unlock(&adapter->fdir_perfect_lock); ... } ixgbe_update_ethtool_fdir_entry() then erases the FDIR perfect filter at sw_idx == loc, whatever it is, and frees its fdir_filter_list entry. Ethtool ntuple rules and u32 knodes in child hash tables use the same sw_idx space. As an example, an admin could first add an existing rule in slot 5 with "ethtool -N ethX ... loc 5" or a u32 filter 1:0:5 in a linked table. Then they could run something like: tc filter add dev ethX ingress protocol ipv6 u32 handle 800::5 ... skip_sw The call chain would be: u32_change() u32_replace_hw_knode(tp, n, userflags, true, ...) tc_setup_cb_add(..., err_stop = true, ...) ixgbe_configure_clsu32() returns -EINVAL (protocol != ETH_P_IP) u32_remove_hw_knode(tp, n, NULL) tc_setup_cb_destroy() ixgbe_delete_clsu32() ixgbe_update_ethtool_fdir_entry(adapter, NULL, 5) A mask that differs from adapter->fdir_mask, or an action rejected by parse_tc_actions(), would hit the same path. In each case ixgbe_configure_clsu32() fails before it touches the hardware. The tc command fails, as the commit message expects. However, the filter that was already live in slot 5 also seems to be gone from the device. If slot 5 belonged to another u32 knode, the software side would still report it as offloaded (TCA_CLS_FLAGS_IN_HW, in_hw_count, child_loc_map bit). If that knode is also skip_sw, its traffic would no longer match in either software or hardware. Before this patch, err_stop was always false. tc_setup_cb_add() returned 0 and this rollback never ran. Since the patch is Cc: stable, would stable trees pick up this behaviour as well? Should the rollback only notify callbacks that accepted the add? Or should ixgbe_delete_clsu32() check ownership for uhtid 0x800 before it erases the slot? > if (err) > goto errunbind; > -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130123028.516696-1-jedrzej.jagielski%40intel.com ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-12-01 12:54 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261130123028.516696-1-jedrzej.jagielski@intel.com>
2026-11-30 12:30 ` [PATCH net v3 1/5] net/sched: cls_u32: fix linked hash table refcount leak Jedrzej Jagielski
2026-11-30 19:07 ` Jamal Hadi Salim
2026-12-01 12:54 ` netdev-bot+sashiko
2026-11-30 12:30 ` [PATCH net v3 2/5] net/sched: cls_u32: remove erroneous refcount_inc() Jedrzej Jagielski
2026-11-30 19:07 ` Jamal Hadi Salim
2026-11-30 12:30 ` [PATCH net v3 3/5] net/sched: cls_u32: don't remove old HW rule on failed knode replace Jedrzej Jagielski
2026-11-30 19:18 ` Jamal Hadi Salim
2026-11-30 19:19 ` Jamal Hadi Salim
2026-11-30 12:30 ` [PATCH net v3 4/5] net/sched: cls_u32: feed u32_replace_hw_knode() with correct set of flags Jedrzej Jagielski
2026-11-30 19:25 ` Jamal Hadi Salim
2026-12-01 12:54 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox