On Mon, Nov 30, 2026 at 7:53 AM Jedrzej Jagielski
<jedr…@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: stab…@vger.kernel.org
> Reported-by: Sashiko <sash…@kernel.org>
> Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40intel.com
> Signed-off-by: Jedrzej Jagielski <jedr…@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
>