Re: [PATCH net-next V5 4/7] net/mlx5e: macsec: Block TC offload when MACsec is enabled

From: Cosmin Ratiu

Date: Tue Dec 01 2026 - 10:05:58 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] This patch makes every installed MACsec RX decrypt rule
> take a
>   device-wide TC block.
>
> --
>
> net/mlx5e: macsec: Block TC offload when MACsec is enabled
>
> This patch makes each installed MACsec RX decrypt rule hold a device-
> wide
> TC offload block. The block is taken in mlx5e_macsec_init_sa_fs() and
> released in mlx5e_macsec_cleanup_sa_fs().
> macsec_upd_secy_hw_address()
> also keeps TC blocked while it rebuilds the RX rules.
>
> > diff --git
> > a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
> > b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
> > index 13896e9c1d331..146f1036dba42 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
>
> [ ... ]
>
> > @@ -325,6 +326,8 @@ static void mlx5e_macsec_cleanup_sa_fs(struct
> > mlx5e_macsec *macsec,
> >   mlx5_macsec_fs_del_rule(macsec->mdev->macsec_fs, sa-
> > >macsec_rule, action, netdev,
> >   fs_id);
> >   sa->macsec_rule = NULL;
> > + if (!is_tx)
> > + mlx5e_accel_unblock_tc_offload(macsec->mdev);
> >  }
>
> [ ... ]
>
> > @@ -354,13 +358,26 @@ static int mlx5e_macsec_init_sa_fs(struct
> > macsec_context *ctx,
> >   rule_attrs.action = (is_tx) ?
> > MLX5_ACCEL_MACSEC_ACTION_ENCRYPT :
> >        
> > MLX5_ACCEL_MACSEC_ACTION_DECRYPT;
> >  
> > + if (!is_tx) {
> > + err = mlx5e_accel_block_tc_offload(priv->mdev);
> > + if (err)
> > + return err;
> > + }
> > +
>
> [Severity: Medium]
> Can mdev->offload_block.num_block_tc leak here when the NIC profile
> is
> torn down while RX SAs are still installed?
>
> The only place this block is released is
> mlx5e_macsec_cleanup_sa_fs().
> When the eswitch moves from legacy to switchdev, the path is:
>
> mlx5e_vport_uplink_rep_load()
>   mlx5e_netdev_change_profile()
>     priv->profile->cleanup(priv) == mlx5e_nic_cleanup()
>       mlx5e_macsec_cleanup()
>
> mlx5e_macsec_cleanup() tears everything down without walking the RX
> SAs:
>
> mlx5_notifier_unregister(mdev, &macsec->nb);
> mlx5_macsec_fs_cleanup(mdev->macsec_fs);
> destroy_workqueue(macsec->wq);
> mlx5e_macsec_aso_cleanup(&macsec->aso, mdev);
> mutex_destroy(&macsec->lock);
> kfree(macsec);
>
> The netdev stays registered during a profile change. The MACsec core
> (macsec_notify() in drivers/net/macsec.c) only deletes secys on
> NETDEV_UNREGISTER, so mdo_del_secy is never called either.
>
> Unlike IPsec, MACsec does not call mlx5_eswitch_block_mode(), so
> nothing
> prevents this mode change.
>
> After the switch, num_block_tc stays above zero in struct
> mlx5_core_dev.
> It is only initialized at mdev init and is never reset. The uplink
> representor reuses the same netdev, and is_tc_accel_check_needed()
> returns true for it. Every mlx5e_configure_flower() on the uplink
> would
> then fail in mlx5e_tc_block_accel_offload():
>
> if (mdev->offload_block.num_block_tc)
> ret = -EBUSY;
>
> Going back to legacy mode doesn't seem to recover either.
> mlx5e_macsec_init() allocates a fresh, empty context, so a later
> mdo_del_secy can't find the device and never unblocks. TC offload on
> the
> uplink/NIC netdev would stay disabled until the mlx5_core_dev is
> re-probed.
>
> Dropping SA rules during profile teardown is an older problem. The
> persistent device-level TC block is what turns it into a lasting TC
> offload outage. Later patches in the series don't seem to touch
> mlx5e_macsec_cleanup() or the profile-change path.
>
> Should mlx5e_macsec_cleanup() release the TC blocks held by installed
> RX
> rules? Alternatively, should MACsec RX offload block the eswitch mode
> change?
>

This is preexisting, and that's not the only scenario this can be
triggered in. mlx5e_detach_netdev() also invokes mlx5e_macsec_cleanup()
which doesn't fully release the RX resources.
I have a series of macsec patches to address this (and several other
mlx5 macsec issues), we will send this to the ML when finalized.

Cosmin.
>