net/mlx5e: PSP fixes
Subsystems (6)
Tariq Toukan
maintainerv2 cover net/mlx5e: PSP fixes
Hi,
This patchset provides bug fixes from Cosmin to the mlx5e PSP feature.
Thanks,
Tariq.
V2:
- Link to V1:
https://lore.kernel.org/all/[email protected]/
- Expand commit message in patch #1.
Cosmin Ratiu (2):
net/mlx5e: psp: Fix invalid access on PSP dev registration fail net/mlx5e: psp: Hook PSP dev reg/unreg to profile enable/disable
.../mellanox/mlx5/core/en_accel/psp.c | 36 ++++++++++--------- .../net/ethernet/mellanox/mlx5/core/en_main.c | 4 +-- 2 files changed, 22 insertions(+), 18 deletions(-)
base-commit: d40831b016b4986e70d20d0ad14e6a0c62318986
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH v2 1/2 net/mlx5e: psp: Fix invalid access on PSP dev registration fail
From: Cosmin Ratiu <[email protected]>
priv->psp->psp is initialized with the PSP device as returned by psp_dev_create(). This could also return an error, in which case a future psp_dev_unregister() will result in unpleasantness.
Avoid that by using a local variable and only saving the PSP device when registration succeeds.
Also apply some light refactoring of the functions managing the PSP device in order to make them more readable/safe.
In case psp_dev_create() fails, priv->psp and steering structs are left in place, but they will be inert. The unchecked access of priv->psp in mlx5e_psp_offload_handle_rx_skb() won't happen because without a PSP device, there can be no SAs added and therefore no packets will be successfully decrypted and be handed off to the SW handler.
--- .../mellanox/mlx5/core/en_accel/psp.c | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +20 -16
@@ -1070,29 +1070,37 @@ static struct psp_dev_ops mlx5_psp_ops = {void mlx5e_psp_unregister (struct mlx5e_priv *priv) { -if (!priv->psp || !priv->psp->psp) +struct mlx5e_psp *psp = priv->psp; + +if (!psp || !psp->psp)return ; -psp_dev_unregister (priv->psp->psp); +psp_dev_unregister (psp->psp); + psp->psp =NULL ; }void mlx5e_psp_register (struct mlx5e_priv *priv) { +struct mlx5e_psp *psp = priv->psp; +struct psp_dev *psd; +/* FW Caps missing */ if (!priv->psp)return ; - priv->psp->caps.assoc_drv_spc =sizeof (u32); - priv->psp->caps.versions =1 <<PSP_VERSION_HDR0_AES_GCM_128 ; + psp->caps.assoc_drv_spc =sizeof (u32); + psp->caps.versions =1 <<PSP_VERSION_HDR0_AES_GCM_128 ;if (MLX5_CAP_PSP (priv->mdev, psp_crypto_esp_aes_gcm_256_encrypt) &&MLX5_CAP_PSP (priv->mdev, psp_crypto_esp_aes_gcm_256_decrypt)) - priv->psp->caps.versions |=1 <<PSP_VERSION_HDR0_AES_GCM_256 ; + psp->caps.versions |=1 <<PSP_VERSION_HDR0_AES_GCM_256 ; - priv->psp->psp =psp_dev_create (priv->netdev, &mlx5_psp_ops, - &priv->psp->caps,NULL ); -if (IS_ERR (priv->psp->psp)) + psd =psp_dev_create (priv->netdev, &mlx5_psp_ops, &psp->caps,NULL ); +if (IS_ERR (psd)) {mlx5_core_err (priv->mdev,"PSP failed to register due to %pe\n" , - priv->psp->psp); + psd); +return ; + } + psp->psp = psd; }int mlx5e_psp_init (struct mlx5e_priv *priv)
@@ -1131,22 +1139,18 @@ int mlx5e_psp_init(struct mlx5e_priv *priv)if (!psp)return -ENOMEM ; - priv->psp = psp; fs =mlx5e_accel_psp_fs_init (priv);if (IS_ERR (fs)) { err =PTR_ERR (fs); - goto out_err; +kfree (psp); +return err; } psp->fs = fs; + priv->psp = psp;mlx5_core_dbg (priv->mdev,"PSP attached to netdevice\n" );return 0 ; - -out_err: - priv->psp =NULL ; -kfree (psp); -return err; }void mlx5e_psp_cleanup (struct mlx5e_priv *priv)
Signature · 1 line
2.44.0
Re: [PATCH net V2 1/2] net/mlx5e: psp: Fix invalid access on PSP dev registration fail
Quoted 10 lines · Tariq Toukan
From: Cosmin Ratiu <[email protected]>
priv->psp->pspis initialized with the PSP device as returned bypsp_dev_create(). This could also return an error, in which case a futurepsp_dev_unregister()will result in unpleasantness.Avoid that by using a local variable and only saving the PSP device when registration succeeds.
Also apply some light refactoring of the functions managing the PSP device in order to make them more readable/safe.
This is generally discouraged as it obfuscates the fix.
That said, the fix on its own makes sense.
Quoted 10 lines
In case
psp_dev_create()fails,priv->pspand steering structs are left in place, but they will be inert. The unchecked access ofpriv->pspinmlx5e_psp_offload_handle_rx_skb()won't happen because without a PSP device, there can be no SAs added and therefore no packets will be successfully decrypted and be handed off to the SW handler.Fixes 89ee2d92f66c ("net/mlx5e: Support PSP offload functionality")Signed-off-by Cosmin Ratiu <[email protected]>Reviewed-by Dragos Tatulea <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
Jakub Kicinski
maintainerRe: [PATCH net V2 1/2] net/mlx5e: psp: Fix invalid access on PSP dev registration fail
Quoted 10 lines · On Sun, 26 Apr 2026 09:17:08 -0400 Willem de Bruijn wrote:
Quoted 8 lines
priv->psp->pspis initialized with the PSP device as returned bypsp_dev_create(). This could also return an error, in which case a futurepsp_dev_unregister()will result in unpleasantness.Avoid that by using a local variable and only saving the PSP device when registration succeeds.
Also apply some light refactoring of the functions managing the PSP device in order to make them more readable/safe.This is generally discouraged as it obfuscates the fix.
+1, I should have said this during the v1 convo, I thought it's obvious :\
Tariq Toukan
maintainerPATCH v2 2/2 net/mlx5e: psp: Hook PSP dev reg/unreg to profile enable/disable
In reply to Tariq ToukanFrom: Cosmin Ratiu <[email protected]>
devlink reload while PSP connections are active does:
mlx5_unload_one_devl_locked() -> mlx5_detach_device() -> _mlx5e_suspend()
-> mlx5e_detach_netdev()
-> profile->cleanup_rx
-> profile->cleanup_tx -> mlx5e_destroy_mdev_resources() -> mlx5_core_dealloc_pd() fails:
...mlx5_core 0000:08:00.0: mlx5_cmd_out_err:821:(pid 19722):DEALLOC_PD(0x801) op_mod(0x0) failed, status bad resource state(0x9), syndrome (0xef0c8a), err(-22)
...
The reason for failure is the existence of TX keys, which are removed by the PSP dev unregistration happening in:profile->cleanup() -> mlx5e_psp_unregister() -> mlx5e_psp_cleanup()
-> psp_dev_unregister()
...but this isn't invoked in the devlink reload flow, only when changing the NIC profile (e.g. when transitioning to switchdev mode) or on dev teardown.
Move PSP device registration into mlx5e_nic_enable(), and unregistration into the corresponding mlx5e_nic_disable(). These functions are called during netdev attach/detach after RX & TX are set up.
This ensures that the keys will be gone by the time the PD is destroyed.
--- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +2 -2
@@ -6023,7 +6023,6 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev,if (take_rtnl)rtnl_lock (); -mlx5e_psp_register (priv);/* update XDP supported features */ mlx5e_set_xdp_feature (priv);
@@ -6036,7 +6035,6 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev,static void mlx5e_nic_cleanup (struct mlx5e_priv *priv) {mlx5e_health_destroy_reporters (priv); -mlx5e_psp_unregister (priv);mlx5e_ktls_cleanup (priv);mlx5e_psp_cleanup (priv);mlx5e_fs_cleanup (priv->fs);
@@ -6160,6 +6158,7 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)mlx5e_fs_init_l2_addr (priv->fs, netdev);mlx5e_ipsec_init (priv); +mlx5e_psp_register (priv); err =mlx5e_macsec_init (priv);if (err)
@@ -6230,6 +6229,7 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)mlx5_lag_remove_netdev (mdev, priv->netdev);mlx5_vxlan_reset_to_default (mdev->vxlan);mlx5e_macsec_cleanup (priv); +mlx5e_psp_unregister (priv);mlx5e_ipsec_cleanup (priv); }
Signature · 1 line
2.44.0