* [PATCH net] net/mlx5: HWS, fix action STE double free on rule update
@ 2026-11-23 22:13 Alexandre Cassen
2026-11-24 12:09 ` Yevgeny Kliteynik
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Alexandre Cassen @ 2026-11-23 22:13 UTC (permalink / raw)
To: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Moshe Shemesh, Yevgeny Kliteynik,
Vlad Dogaru, netdev, linux-rdma
An HWS rule keeps the chunk of its action STEs in rule->action_ste. An
update saves it in rule->old_action_ste and frees it once the new match
STE is written. When the new actions need no action STEs, the rule still
points to that chunk. Its next update or its deletion free it again.
Two rules can then end up with the same action STEs. A packet of one can
get the header rewrite or the meter of the other. The second free can
also dereference an action STE table that the cleanup work has freed.
Neither was observed.
The buddy allocator counts the same segment as free twice. After a few
updates of several rules, it finds no segment where it counts one:
ICM Buddy: failed finding free mem for order 0
WARNING: drivers/net/ethernet/mellanox/mlx5/core/steering/hws/buddy.c:93 at mlx5hws_buddy_alloc_mem+0x11a/0x140 [mlx5_core], CPU#34: tc/449154
Call Trace:
<TASK>
hws_pool_buddy_db_get_chunk+0x25/0x50 [mlx5_core]
mlx5hws_pool_chunk_alloc+0x30/0x80 [mlx5_core]
mlx5hws_action_ste_chunk_alloc+0x85/0x480 [mlx5_core]
hws_rule_create_hws+0x860/0x9c0 [mlx5_core]
mlx5hws_rule_action_update+0x81/0x140 [mlx5_core]
mlx5hws_bwc_rule_action_update+0x10d/0x200 [mlx5_core]
mlx5_cmd_hws_update_fte+0xb0/0x140 [mlx5_core]
del_hw_fte+0x1b2/0x390 [mlx5_core]
mlx5_del_flow_rules+0x10f/0x270 [mlx5_core]
__mlx5_eswitch_del_rule+0x5c/0x1b0 [mlx5_core]
mlx5_eswitch_del_offloaded_rule+0x10/0x20 [mlx5_core]
mlx5e_tc_rule_unoffload+0x4b/0x100 [mlx5_core]
mlx5e_tc_unoffload_fdb_rules+0x35/0x80 [mlx5_core]
mlx5e_tc_del_fdb_flow+0x2ca/0x310 [mlx5_core]
mlx5e_tc_del_flow+0x63/0x610 [mlx5_core]
mlx5e_flow_put+0x3a/0x80 [mlx5_core]
mlx5e_delete_flower+0x29b/0x460 [mlx5_core]
mlx5e_setup_tc_cls_flower+0x7d/0x90 [mlx5_core]
mlx5e_setup_tc_block_cb+0x58/0x90 [mlx5_core]
tc_setup_cb_destroy+0xcc/0x1b0
fl_hw_destroy_filter+0xa1/0xe0 [cls_flower]
fl_change+0x1bf1/0x20a9 [cls_flower]
tc_new_tfilter+0x432/0xea0
rtnetlink_rcv_msg+0x384/0x460
netlink_rcv_skb+0x61/0x120
rtnetlink_rcv+0x15/0x30
netlink_unicast+0x2a1/0x3d0
netlink_sendmsg+0x237/0x490
____sys_sendmsg+0x32d/0x350
___sys_sendmsg+0xaf/0x110
__sys_sendmsg+0x93/0x100
__x64_sys_sendmsg+0x1d/0x30
x64_sys_call+0x821/0x23d0
do_syscall_64+0xbd/0x570
</TASK>
The pool then holds more free elements than its size at close:
mlx5_core 0000:31:00.0: mlx5hws_pool_destroy:386:(pid 448599): Attempting to destroy non-empty pool
Forget the chunk in rule->action_ste once it is saved, as the update
flow did with the action STE index before the commit below.
Triggered during an endurance test of a 5G UPF code, on flower rules
that lose their police action in place. The reproduction below gives
the trace above on a ConnectX-7 with firmware 28.48.1000. It only
uses tc and devlink, with no kernel change. DEV is the uplink
representor and PCI its devlink handle:
r() { for i in $(seq 128); do echo "filter $1 dev $DEV ingress prio 1 handle $i protocol ip flower skip_sw dst_ip 10.0.0.$i $2"; done | tc -b -; }
BIG="action pedit ex munge ip ttl set 63 pipe action csum ip pipe action police rate 1mbit burst 32k conform-exceed drop/pipe action drop"
devlink dev param set $PCI name flow_steering_mode value hmfs cmode runtime
devlink dev eswitch set $PCI mode switchdev
tc qdisc add dev $DEV ingress
r add "$BIG"
for n in 1 2 3; do r replace "action drop"; r replace "$BIG"; done
tc filter del dev $DEV ingress prio 1
devlink dev eswitch set $PCI mode legacy
With this fix, the reproduction runs clean on the same ConnectX-7.
It was not tested against kernel selftests.
Not addressed here and not triggered: after a successful update,
hws_rule_destroy_failed_hws() can free rule->old_action_ste again. A
failed update can leak it now also when it needs no action STEs.
Fixes: 3fc44ca44d7c ("net/mlx5: HWS, update flow - support through bigger action RTC")
Signed-off-by: Alexandre Cassen <acassen@corp.free.fr>
---
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
index 0d4cb2b2393b..cc94d3149d76 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
@@ -243,6 +243,8 @@ static void hws_rule_create_init(struct mlx5hws_rule *rule,
* new action STEs and a corresponding match STE.
*/
rule->old_action_ste = rule->action_ste;
+ /* The rule may need no action STEs once updated */
+ rule->action_ste.action_tbl = NULL;
}
rule->pending_wqes = 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] net/mlx5: HWS, fix action STE double free on rule update
2026-11-23 22:13 [PATCH net] net/mlx5: HWS, fix action STE double free on rule update Alexandre Cassen
@ 2026-11-24 12:09 ` Yevgeny Kliteynik
2026-11-24 22:13 ` sashiko-bot
2026-11-24 22:47 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: Yevgeny Kliteynik @ 2026-11-24 12:09 UTC (permalink / raw)
To: Alexandre Cassen, Saeed Mahameed, Leon Romanovsky, Tariq Toukan,
Mark Bloch
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Moshe Shemesh, Vlad Dogaru, netdev,
linux-rdma
On 24-Nov-26 00:13, Alexandre Cassen wrote:
> An HWS rule keeps the chunk of its action STEs in rule->action_ste. An
> update saves it in rule->old_action_ste and frees it once the new match
> STE is written. When the new actions need no action STEs, the rule still
> points to that chunk. Its next update or its deletion free it again.
>
> Two rules can then end up with the same action STEs. A packet of one can
> get the header rewrite or the meter of the other. The second free can
> also dereference an action STE table that the cleanup work has freed.
> Neither was observed.
>
> The buddy allocator counts the same segment as free twice. After a few
> updates of several rules, it finds no segment where it counts one:
>
> ICM Buddy: failed finding free mem for order 0
> WARNING: drivers/net/ethernet/mellanox/mlx5/core/steering/hws/buddy.c:93 at mlx5hws_buddy_alloc_mem+0x11a/0x140 [mlx5_core], CPU#34: tc/449154
> Call Trace:
> <TASK>
> hws_pool_buddy_db_get_chunk+0x25/0x50 [mlx5_core]
> mlx5hws_pool_chunk_alloc+0x30/0x80 [mlx5_core]
> mlx5hws_action_ste_chunk_alloc+0x85/0x480 [mlx5_core]
> hws_rule_create_hws+0x860/0x9c0 [mlx5_core]
> mlx5hws_rule_action_update+0x81/0x140 [mlx5_core]
> mlx5hws_bwc_rule_action_update+0x10d/0x200 [mlx5_core]
> mlx5_cmd_hws_update_fte+0xb0/0x140 [mlx5_core]
> del_hw_fte+0x1b2/0x390 [mlx5_core]
> mlx5_del_flow_rules+0x10f/0x270 [mlx5_core]
> __mlx5_eswitch_del_rule+0x5c/0x1b0 [mlx5_core]
> mlx5_eswitch_del_offloaded_rule+0x10/0x20 [mlx5_core]
> mlx5e_tc_rule_unoffload+0x4b/0x100 [mlx5_core]
> mlx5e_tc_unoffload_fdb_rules+0x35/0x80 [mlx5_core]
> mlx5e_tc_del_fdb_flow+0x2ca/0x310 [mlx5_core]
> mlx5e_tc_del_flow+0x63/0x610 [mlx5_core]
> mlx5e_flow_put+0x3a/0x80 [mlx5_core]
> mlx5e_delete_flower+0x29b/0x460 [mlx5_core]
> mlx5e_setup_tc_cls_flower+0x7d/0x90 [mlx5_core]
> mlx5e_setup_tc_block_cb+0x58/0x90 [mlx5_core]
> tc_setup_cb_destroy+0xcc/0x1b0
> fl_hw_destroy_filter+0xa1/0xe0 [cls_flower]
> fl_change+0x1bf1/0x20a9 [cls_flower]
> tc_new_tfilter+0x432/0xea0
> rtnetlink_rcv_msg+0x384/0x460
> netlink_rcv_skb+0x61/0x120
> rtnetlink_rcv+0x15/0x30
> netlink_unicast+0x2a1/0x3d0
> netlink_sendmsg+0x237/0x490
> ____sys_sendmsg+0x32d/0x350
> ___sys_sendmsg+0xaf/0x110
> __sys_sendmsg+0x93/0x100
> __x64_sys_sendmsg+0x1d/0x30
> x64_sys_call+0x821/0x23d0
> do_syscall_64+0xbd/0x570
> </TASK>
>
> The pool then holds more free elements than its size at close:
>
> mlx5_core 0000:31:00.0: mlx5hws_pool_destroy:386:(pid 448599): Attempting to destroy non-empty pool
>
> Forget the chunk in rule->action_ste once it is saved, as the update
> flow did with the action STE index before the commit below.
>
> Triggered during an endurance test of a 5G UPF code, on flower rules
> that lose their police action in place. The reproduction below gives
> the trace above on a ConnectX-7 with firmware 28.48.1000. It only
> uses tc and devlink, with no kernel change. DEV is the uplink
> representor and PCI its devlink handle:
>
> r() { for i in $(seq 128); do echo "filter $1 dev $DEV ingress prio 1 handle $i protocol ip flower skip_sw dst_ip 10.0.0.$i $2"; done | tc -b -; }
> BIG="action pedit ex munge ip ttl set 63 pipe action csum ip pipe action police rate 1mbit burst 32k conform-exceed drop/pipe action drop"
> devlink dev param set $PCI name flow_steering_mode value hmfs cmode runtime
> devlink dev eswitch set $PCI mode switchdev
> tc qdisc add dev $DEV ingress
> r add "$BIG"
> for n in 1 2 3; do r replace "action drop"; r replace "$BIG"; done
> tc filter del dev $DEV ingress prio 1
> devlink dev eswitch set $PCI mode legacy
>
> With this fix, the reproduction runs clean on the same ConnectX-7.
> It was not tested against kernel selftests.
>
> Not addressed here and not triggered: after a successful update,
> hws_rule_destroy_failed_hws() can free rule->old_action_ste again. A
> failed update can leak it now also when it needs no action STEs.
>
> Fixes: 3fc44ca44d7c ("net/mlx5: HWS, update flow - support through bigger action RTC")
> Signed-off-by: Alexandre Cassen <acassen@corp.free.fr>
> ---
> drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
> index 0d4cb2b2393b..cc94d3149d76 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
> @@ -243,6 +243,8 @@ static void hws_rule_create_init(struct mlx5hws_rule *rule,
> * new action STEs and a corresponding match STE.
> */
> rule->old_action_ste = rule->action_ste;
> + /* The rule may need no action STEs once updated */
> + rule->action_ste.action_tbl = NULL;
Reviewed-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net/mlx5: HWS, fix action STE double free on rule update
2026-11-23 22:13 [PATCH net] net/mlx5: HWS, fix action STE double free on rule update Alexandre Cassen
2026-11-24 12:09 ` Yevgeny Kliteynik
@ 2026-11-24 22:13 ` sashiko-bot
2026-11-24 22:47 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-24 22:13 UTC (permalink / raw)
To: Alexandre Cassen; +Cc: linux-rdma
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net/mlx5: HWS, missing rollback on update alloc error in
hws_rule_create_hws()
- [Medium] net/mlx5: HWS, leak of old_action_ste on rule deletion after
failed update
--
commit 0a380355d2aec6e9f92b8c556ecd839808dbe0cd
Author: Alexandre Cassen <acassen@corp.free.fr>
net/mlx5: HWS, fix action STE double free on rule update
This commit clears rule->action_ste.action_tbl after saving rule->action_ste
to rule->old_action_ste during a rule update so that rules updated to need
no action STEs do not free the old chunk twice.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
> index 0d4cb2b2393b9..cc94d3149d76a 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
> @@ -243,6 +243,8 @@ static void hws_rule_create_init(struct mlx5hws_rule *rule,
> * new action STEs and a corresponding match STE.
> */
> rule->old_action_ste = rule->action_ste;
> + /* The rule may need no action STEs once updated */
> + rule->action_ste.action_tbl = NULL;
> }
>
> rule->pending_wqes = 0;
[Severity: Medium]
Does hws_rule_create_hws() leave the rule stuck in
MLX5HWS_RULE_STATUS_UPDATING and leak rule->old_action_ste if
mlx5hws_rule_alloc_action_ste() fails during an update?
hws_rule_create_init() sets rule->status to MLX5HWS_RULE_STATUS_UPDATING,
moves rule->action_ste to rule->old_action_ste, and clears
rule->action_ste.action_tbl before hws_rule_create_hws() calls
mlx5hws_rule_alloc_action_ste():
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c:hws_rule_create_hws() {
...
if (action_stes) {
ret = mlx5hws_rule_alloc_action_ste(rule, attr->queue_id,
!!ste_attr.rtc_0,
!!ste_attr.rtc_1);
if (ret) {
mlx5hws_err(ctx, "Failed to allocate action memory %d", ret);
mlx5hws_send_abort_new_dep_wqe(queue);
return ret;
}
}
...
}
Because no WQE is posted on that error return, no completion transitions
rule->status out of MLX5HWS_RULE_STATUS_UPDATING. Later update and
destroy calls fail with -EBUSY, and mlx5hws_bwc_rule_destroy() frees the
rule object while leaking rule->old_action_ste, rule->resize_info, and the
hardware match STE.
[Severity: Medium]
Can clearing rule->action_ste.action_tbl here also leak
rule->old_action_ste when a rule is deleted after an asynchronous update
failure?
If an update WQE fails while either rule->rtc_0 or rule->rtc_1 remains
non-zero, hws_send_engine_update_rule() leaves rule->status at
MLX5HWS_RULE_STATUS_FAILING rather than MLX5HWS_RULE_STATUS_FAILED. When
the rule is later deleted, both the MLX5HWS_RULE_STATUS_DELETED completion
in hws_send_engine_update_rule() and the skip_delete path in
hws_rule_destroy_hws() only call
mlx5hws_rule_free_action_ste(&rule->action_ste), leaving
rule->old_action_ste leaked in the action STE pool even when the failed
update needed no new action STEs.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123221310.4045513-1-acassen@corp.free.fr?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net/mlx5: HWS, fix action STE double free on rule update
2026-11-23 22:13 [PATCH net] net/mlx5: HWS, fix action STE double free on rule update Alexandre Cassen
2026-11-24 12:09 ` Yevgeny Kliteynik
2026-11-24 22:13 ` sashiko-bot
@ 2026-11-24 22:47 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 22:47 UTC (permalink / raw)
To: acassen
Cc: saeedm, leon, tariqt, mbloch, andrew+netdev, davem, edumazet,
kuba, pabeni, horms, moshe, kliteyn, vdogaru, netdev, linux-rdma
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · 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).
- [High] The patch leaves a second double free of action STEs on rule
update in place.
- [Medium] This patch adds a new leak of the old action STE chunk when an
update partially fails and the new actions need no action STEs…
--
net/mlx5: HWS, fix action STE double free on rule update
This patch clears rule->action_ste.action_tbl in hws_rule_create_init()
once the current chunk is saved into rule->old_action_ste during an
update. If the new actions need no action STEs, a later update or delete
no longer frees the same action STE chunk again.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
> index 0d4cb2b2393b9..cc94d3149d76a 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c
> @@ -243,6 +243,8 @@ static void hws_rule_create_init(struct mlx5hws_rule *rule,
> * new action STEs and a corresponding match STE.
> */
> rule->old_action_ste = rule->action_ste;
> + /* The rule may need no action STEs once updated */
> + rule->action_ste.action_tbl = NULL;
> }
[Severity: High]
The subject says this fixes the action STE double free on rule update.
Can the old_action_ste slot still be freed twice, though?
When an update succeeds, hws_send_engine_update_rule() in send.c frees
the old chunk:
} else if (priv->rule->status == MLX5HWS_RULE_STATUS_UPDATED) {
/* Rule was updated, free the old action STEs */
mlx5hws_rule_free_action_ste(&priv->rule->old_action_ste);
Neither mlx5hws_rule_free_action_ste() nor mlx5hws_action_ste_chunk_free()
clears old_action_ste.action_tbl after that. So the only guard in the
helper still passes on a later call:
if (!action_ste->action_tbl)
return;
One CQE with an opcode other than MLX5_CQE_REQ makes
hws_send_engine_poll_cq() set queue->err, and nothing clears it. After
that, every destroy on the queue goes through
hws_rule_destroy_hws()->hws_rule_destroy_failed_hws(), which does:
/* Perhaps the rule failed updating - release old action STEs as well */
mlx5hws_rule_free_action_ste(&rule->old_action_ste);
Any rule that was updated successfully before gets its old chunk freed a
second time here. The reproducer's flower rules, which lose and regain
their police action, are such rules. Eswitch teardown is one way to
reach this destroy path.
The cleanup work (hws_action_ste_pool_cleanup()->
hws_action_ste_table_destroy()) may kfree() the now empty table between
the two frees. In that case, mlx5hws_action_ste_chunk_free() would read
chunk->action_tbl->parent_elem->parent_pool->lock from freed memory.
The commit message calls this path "Not addressed here and not
triggered".
Would clearing action_ste->action_tbl inside
mlx5hws_rule_free_action_ste() after the free make every free site safe
to repeat? Combined with this change, that would cover this path as
well as the one fixed here.
[Severity: Medium]
Does this hunk now leak the old chunk when an update to actions with no
action STEs partially fails?
After this hunk, old_action_ste is the only reference to the old chunk.
Take an FDB rule with both RX and TX RTCs. One WQE may complete with an
error status without setting queue->err. Then
hws_send_engine_update_rule() zeroes only that RTC's used_id. The status
stays FAILING and does not become FAILED:
if (!priv->rule->rtc_0 && !priv->rule->rtc_1)
priv->rule->status = MLX5HWS_RULE_STATUS_FAILED;
hws_rule_destroy_hws() then takes either the skip_delete branch or the
normal DEACTIVATE path. Both free only rule->action_ste. The skip_delete
branch does:
mlx5hws_rule_free_action_ste(&rule->action_ste);
and the DELETED completion in hws_send_engine_update_rule() does:
mlx5hws_rule_free_action_ste(&priv->rule->action_ste);
action_ste.action_tbl is now NULL, so neither call frees anything. The
chunk held in old_action_ste is never released, so the pool is still
non-empty at teardown. Before this patch, the chunk was still in
action_ste, and delete freed it once.
The commit message notes "A failed update can leak it now also when it
needs no action STEs".
Would either of these avoid the leak?
- free old_action_ste in the DELETED completion and in the
skip_delete branch
- restore action_ste from old_action_ste on partial failure
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123221310.4045513-1-acassen%40corp.free.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 22:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 22:13 [PATCH net] net/mlx5: HWS, fix action STE double free on rule update Alexandre Cassen
2026-11-24 12:09 ` Yevgeny Kliteynik
2026-11-24 22:13 ` sashiko-bot
2026-11-24 22:47 ` 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