Re: [PATCH net-next V5 1/7] net/mlx5e: Generalize TC <-> IPsec mutual exclusion

From: Cosmin Ratiu

Date: Tue Dec 01 2026 - 09:58:16 EST


On Mon, 2026-11-30 at 12:07 +0000, netdev-bot+sashiko@xxxxxxxxxx wrote:
> 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] The num_block_accel count leaks on PM suspend/resume while
> TC
>   flower rules are installed on the PF netdev in NIC (legacy) mode.
>
> --
>
> net/mlx5e: Generalize TC <-> IPsec mutual exclusion
>
> This commit moves the TC/IPsec mutual exclusion helpers to en_accel.h
> as
> mlx5e_accel_{,un}block_tc_offload() and renames num_block_ipsec to
> num_block_accel. It also drops the CONFIG_MLX5_EN_IPSEC check from
> is_tc_accel_check_needed(), so that follow-up patches can use the
> same gate
> for PSP and MACsec.
>
> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> > b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> > index 615af3acdb9eb..03bade86c38c2 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> > @@ -4821,14 +4821,15 @@ static bool
> > is_flow_rule_duplicate_allowed(struct net_device *dev,
>
> [ ... ]
>
> > -static bool is_tc_ipsec_order_check_needed(struct net_device
> > *filter, struct mlx5e_priv *priv)
> > +static bool is_tc_accel_check_needed(struct net_device *filter,
> > +      struct mlx5e_priv *priv)
> >  {
> > - if (!IS_ENABLED(CONFIG_MLX5_EN_IPSEC))
> > - return false;
> > -
> >   if (filter != priv->netdev)
> >   return false;
>
> [Severity: Medium]
> Without the IS_ENABLED(CONFIG_MLX5_EN_IPSEC) check, every successful
> mlx5e_configure_flower() on the PF netdev now increments
> num_block_accel in
> every build. That count is becoming the gate for IPsec, PSP and
> MACsec. Can
> it leak across PM suspend/resume in NIC (legacy) mode?
>
> The only decrement is in mlx5e_delete_flower(). It only runs when the
> flow's cookie is still in the driver's tc hashtable.
>
> On system suspend the netdev stays registered, so the TC core keeps
> its
> filters. The driver still frees its flows, though:
>
> mlx5_suspend()
>   mlx5_unload_one(dev, true)
>     mlx5_detach_device(dev, true)
>       mlx5e_suspend()
>         _mlx5e_suspend()
>           mlx5e_detach_netdev()
>             profile->cleanup_rx() == mlx5e_cleanup_nic_rx()
>               mlx5e_tc_nic_cleanup()
>                 rhashtable_free_and_destroy(&tc->ht,
> _mlx5e_tc_del_flow, NULL);
>
> The destroy callback does not drop the count:
>
> drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:_mlx5e_tc_del_flow()
> {
> ...
> mlx5e_tc_del_flow(priv, flow);
> kfree(flow);
> }
>
> On resume, mlx5e_attach_netdev() creates a new, empty hashtable. When
> the
> user later deletes the filters, mlx5e_delete_flower() misses the
> lookup.
> It returns before it reaches mlx5e_tc_unblock_accel_offload():
>
> flow = rhashtable_lookup(tc_ht, &f->cookie, tc_ht_params);
> if (!flow || !same_flow_direction(flow, flags)) {
> err = -EINVAL;
> goto errout;
> }
>
> offload_block is set up only once, in mlx5_mdev_init(), and is never
> reset.
> esw->user_count, by contrast, is reset on the legacy and offloads
> init
> paths. So num_block_accel would stay non-zero for the life of the
> mdev.
>
> Wouldn't every later mlx5e_accel_block_tc_offload() call on this mdev
> then
> return -EBUSY until the driver is reloaded?
>
> if (mdev->offload_block.num_block_accel)
> ret = -EBUSY;
>
> The leaking teardown path dates from commit c8e350e62fc5, where it
> only
> affected IPsec packet offload in CONFIG_MLX5_EN_IPSEC builds. With
> this
> patch and the follow-ups, one leaked TC count would block IPsec SA
> and
> policy add, PSP RX enable and MACsec RX SA add. That includes builds
> without IPsec. At the end of the series, the _mlx5e_tc_del_flow() and
> mlx5e_tc_nic_cleanup() path still has no unblock.
>
> The other teardown paths look fine:
>
> - Health recovery, fw reset, devlink reload and driver unload use
>   suspend=false.
> - _mlx5e_remove() calls unregister_netdev() before _mlx5e_suspend(),
> so
>   the TC core flushes the filters through mlx5e_delete_flower()
> first.
> - In switchdev mode, mlx5e_vport_uplink_rep_unload() unregisters the
>   netdev before the profile change.
>
> So this appears specific to PM suspend in NIC mode.
>
> Should mlx5e_tc_nic_cleanup() also drop the num_block_accel count for
> each
> flow it frees?
>

This is a preexisting bug introduced by commit c8e350e62fc5
("net/mlx5e: Make TC and IPsec offloads mutually exclusive on a
netdev"). I have a fix prepared for net for this, will submit it
separately to not block this series.

Cosmin.