mlx5e misc fixes 2025-09-15
Subsystems (7)
Tariq Toukan
maintainerv2 cover mlx5e misc fixes 2025-09-15
Hi,
This patchset provides misc bug fixes from the team to the mlx5 Eth driver.
Find V1 here:
https://lore.kernel.org/all/[email protected]/
Thanks,
Tariq.
V2:
- Improve commit message in patches 1-2.
- Move local var assginment call from init when the call might fail.
Jianbo Liu (2):
net/mlx5e: Harden uplink netdev access against device unbind net/mlx5e: Prevent entering switchdev mode with inconsistent netns
Lama Kayal (1):
net/mlx5e: Add a miss level for ipsec crypto offload
.../net/ethernet/mellanox/mlx5/core/en/fs.h | 1 + .../mellanox/mlx5/core/en_accel/ipsec.h | 1 + .../mellanox/mlx5/core/en_accel/ipsec_fs.c | 3 +- .../net/ethernet/mellanox/mlx5/core/en_rep.c | 27 ++++++++++++--- .../net/ethernet/mellanox/mlx5/core/esw/qos.c | 1 + .../mellanox/mlx5/core/eswitch_offloads.c | 33 +++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/fs_core.c | 4 +-- .../ethernet/mellanox/mlx5/core/lib/mlx5.h | 15 ++++++++- include/linux/mlx5/driver.h | 1 + 9 files changed, 77 insertions(+), 9 deletions(-)
base-commit: 2e5fb2ff31730786c05e0f18949143b05efa1212
Signature · 1 line
2.31.1
Tariq Toukan
maintainerPATCH v2 1/3 net/mlx5e: Harden uplink netdev access against device unbind
From: Jianbo Liu <[email protected]>
The function mlx5_uplink_netdev_get() gets the uplink netdevice pointer from mdev->mlx5e_res.uplink_netdev. However, the netdevice can be removed and its pointer cleared when unbound from the mlx5_core.eth driver. This results in a NULL pointer, causing a kernel panic.
BUG: unable to handle page fault for address: 0000000000001300 at RIP: 0010:mlx5e_vport_rep_load+0x22a/0x270 [mlx5_core] Call Trace: <TASK> mlx5_esw_offloads_rep_load+0x68/0xe0 [mlx5_core] esw_offloads_enable+0x593/0x910 [mlx5_core] mlx5_eswitch_enable_locked+0x341/0x420 [mlx5_core] mlx5_devlink_eswitch_mode_set+0x17e/0x3a0 [mlx5_core] devlink_nl_eswitch_set_doit+0x60/0xd0 genl_family_rcv_msg_doit+0xe0/0x130 genl_rcv_msg+0x183/0x290 netlink_rcv_skb+0x4b/0xf0 genl_rcv+0x24/0x40 netlink_unicast+0x255/0x380 netlink_sendmsg+0x1f3/0x420 __sock_sendmsg+0x38/0x60 __sys_sendto+0x119/0x180 do_syscall_64+0x53/0x1d0 entry_SYSCALL_64_after_hwframe+0x4b/0x53
Ensure the pointer is valid before use by checking it for NULL. If it is valid, immediately call netdev_hold() to take a reference, and preventing the netdevice from being freed while it is in use.
--- .../net/ethernet/mellanox/mlx5/core/en_rep.c | 27 +++++++++++++++---- .../net/ethernet/mellanox/mlx5/core/esw/qos.c | 1 + .../ethernet/mellanox/mlx5/core/lib/mlx5.h | 15 ++++++++++- include/linux/mlx5/driver.h | 1 + 4 files changed, 38 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +22 -5
@@ -1506,12 +1506,21 @@ static const struct mlx5e_profile mlx5e_uplink_rep_profile = {static int mlx5e_vport_uplink_rep_load (struct mlx5_core_dev *dev,struct mlx5_eswitch_rep *rep) { -struct mlx5e_priv *priv =netdev_priv (mlx5_uplink_netdev_get (dev));struct mlx5e_rep_priv *rpriv =mlx5e_rep_to_rep_priv (rep); +struct net_device *netdev; +struct mlx5e_priv *priv; +int err; + + netdev =mlx5_uplink_netdev_get (dev); +if (!netdev) +return 0 ; + priv =netdev_priv (netdev); rpriv->netdev = priv->netdev; -return mlx5e_netdev_change_profile (priv, &mlx5e_uplink_rep_profile, - rpriv); + err =mlx5e_netdev_change_profile (priv, &mlx5e_uplink_rep_profile, + rpriv); +mlx5_uplink_netdev_put (dev, netdev); +return err; } static void
@@ -1638,8 +1647,16 @@ mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep) {struct mlx5e_rep_priv *rpriv =mlx5e_rep_to_rep_priv (rep);struct net_device *netdev = rpriv->netdev; -struct mlx5e_priv *priv =netdev_priv (netdev); -void *ppriv = priv->ppriv; +struct mlx5e_priv *priv; +void *ppriv; + +if (!netdev) { + ppriv = rpriv; + goto free_ppriv; + } + + priv =netdev_priv (netdev); + ppriv = priv->ppriv;if (rep->vport ==MLX5_VPORT_UPLINK ) {mlx5e_vport_uplink_rep_unload (rpriv);
drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c +1 -0
@@ -1515,6 +1515,7 @@ static u32 mlx5_esw_qos_lag_link_speed_get_locked(struct mlx5_core_dev *mdev) speed = lksettings.base.speed; out: +mlx5_uplink_netdev_put (mdev, slave);return speed; }
drivers/net/ethernet/mellanox/mlx5/core/lib/mlx5.h +14 -1
@@ -47,7 +47,20 @@ int mlx5_crdump_collect(struct mlx5_core_dev *dev, u32 *cr_data);static inline struct net_device *mlx5_uplink_netdev_get (struct mlx5_core_dev *mdev) { -return mdev->mlx5e_res.uplink_netdev; +struct mlx5e_resources *mlx5e_res = &mdev->mlx5e_res; +struct net_device *netdev; + +mutex_lock (&mlx5e_res->uplink_netdev_lock); + netdev = mlx5e_res->uplink_netdev; +netdev_hold (netdev, &mlx5e_res->tracker,GFP_KERNEL ); +mutex_unlock (&mlx5e_res->uplink_netdev_lock); +return netdev; +} + +static inline void mlx5_uplink_netdev_put (struct mlx5_core_dev *mdev, +struct net_device *netdev) +{ +netdev_put (netdev, &mdev->mlx5e_res.tracker); }struct mlx5_sd ;
include/linux/mlx5/driver.h +1 -0
@@ -663,6 +663,7 @@ struct mlx5e_resources {bool tisn_valid; } hw_objs;struct net_device *uplink_netdev; +netdevice_tracker tracker;struct mutex uplink_netdev_lock;struct mlx5_crypto_dek_priv *dek_priv; };
Signature · 1 line
2.31.1
Tariq Toukan
maintainerPATCH v2 2/3 net/mlx5e: Prevent entering switchdev mode with inconsistent netns
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
When a PF enters switchdev mode, its netdevice becomes the uplink representor but remains in its current network namespace. All other representors (VFs, SFs) are created in the netns of the devlink instance.
If the PF's netns has been moved and differs from the devlink's netns, enabling switchdev mode would create a state where the OVS control plane (ovs-vsctl) cannot manage the switch because the PF uplink representor and the other representors are split across different namespaces.
To prevent this inconsistent configuration, block the request to enter switchdev mode if the PF netdevice's netns does not match the netns of its devlink instance.
As part of this change, the PF's netns is first marked as immutable. This prevents race conditions where the netns could be changed after the check is performed but before the mode transition is complete, and it aligns the PF's behavior with that of the final uplink representor.
--- .../mellanox/mlx5/core/eswitch_offloads.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +33 -0
@@ -3739,6 +3739,29 @@ void mlx5_eswitch_unblock_mode(struct mlx5_core_dev *dev)up_write (&esw->mode_lock); } +/* Returns false only when uplink netdev exists and its netns is different from +* devlink's netns. True for all others so entering switchdev mode is allowed. +*/ +static bool mlx5_devlink_netdev_netns_immutable_set (struct devlink *devlink, +bool immutable) +{ +struct mlx5_core_dev *mdev =devlink_priv (devlink); +struct net_device *netdev; +bool ret; + + netdev =mlx5_uplink_netdev_get (mdev); +if (!netdev) +return true; + +rtnl_lock (); + netdev->netns_immutable = immutable; + ret =net_eq (dev_net (netdev),devlink_net (devlink)); +rtnl_unlock (); + +mlx5_uplink_netdev_put (mdev, netdev); +return ret; +} +int mlx5_devlink_eswitch_mode_set (struct devlink *devlink,u16 mode,struct netlink_ext_ack *extack) {
@@ -3781,6 +3804,14 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, esw->eswitch_operation_in_progress = true;up_write (&esw->mode_lock); +if (mode ==DEVLINK_ESWITCH_MODE_SWITCHDEV && + !mlx5_devlink_netdev_netns_immutable_set (devlink, true)) { +NL_SET_ERR_MSG_MOD (extack, +"Can't change E-Switch mode to switchdev when netdev net namespace has diverged from the devlink's." ); + err = -EINVAL ; + goto skip; + } +if (mode ==DEVLINK_ESWITCH_MODE_LEGACY ) esw->dev->priv.flags |=MLX5_PRIV_FLAGS_SWITCH_LEGACY ;mlx5_eswitch_disable_locked (esw);
@@ -3799,6 +3830,8 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, } skip: +if (mode ==DEVLINK_ESWITCH_MODE_SWITCHDEV && err) +mlx5_devlink_netdev_netns_immutable_set (devlink, false);down_write (&esw->mode_lock); esw->eswitch_operation_in_progress = false; unlock:
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerRe: [PATCH net V2 2/3] net/mlx5e: Prevent entering switchdev mode with inconsistent netns
Quoted 5 lines · On Mon, 15 Sep 2025 15:24:33 +0300 Tariq Toukan wrote:
If the PF's netns has been moved and differs from the devlink's netns, enabling switchdev mode would create a state where the OVS control plane (ovs-vsctl) cannot manage the switch because the PF uplink representor and the other representors are split across different namespaces.
I appreciate the extra paragraph of explanation but it's still not a fix.
Re: [PATCH net V2 2/3] net/mlx5e: Prevent entering switchdev mode with inconsistent netns
Quoted 9 lines · Jakub Kicinski
Quoted 5 lines · On Mon, 15 Sep 2025 15:24:33 +0300 Tariq Toukan wrote:
If the PF's netns has been moved and differs from the devlink's netns, enabling switchdev mode would create a state where the OVS control plane (ovs-vsctl) cannot manage the switch because the PF uplink representor and the other representors are split across different namespaces.
I appreciate the extra paragraph of explanation but it's still not a fix.
Ack.
Tariq Toukan
maintainerPATCH v2 3/3 net/mlx5e: Add a miss level for ipsec crypto offload
In reply to Tariq ToukanFrom: Lama Kayal <[email protected]>
The cited commit adds a miss table for switchdev mode. But it uses the same level as policy table. Will hit the following error when running command:
# ip xfrm state add src 192.168.1.22 dst 192.168.1.21 proto \ esp spi 1001 reqid 10001 aead 'rfc4106(gcm(aes))' \ 0x3a189a7f9374955d3817886c8587f1da3df387ff 128 \ mode tunnel offload dev enp8s0f0 dir in Error: mlx5_core: Device failed to offload this state.
The dmesg error is:
mlx5_core 0000:03:00.0: ipsec_miss_create:578:(pid 311797): fail to create IPsec miss_rule err=-22
Fix it by adding a new miss level to avoid the error.
--- drivers/net/ethernet/mellanox/mlx5/core/en/fs.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c | 3 ++- drivers/net/ethernet/mellanox/mlx5/core/fs_core.c | 4 ++-- 4 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +1 -0
@@ -92,6 +92,7 @@ enum {MLX5E_ACCEL_FS_ESP_FT_LEVEL =MLX5E_INNER_TTC_FT_LEVEL +1 ,MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL ,MLX5E_ACCEL_FS_POL_FT_LEVEL , +MLX5E_ACCEL_FS_POL_MISS_FT_LEVEL , MLX5E_ACCEL_FS_ESP_FT_ROCE_LEVEL, #endif };
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h +1 -0
@@ -185,6 +185,7 @@ struct mlx5e_ipsec_rx_create_attr {u32 family;int prio;int pol_level; +int pol_miss_level;int sa_level;int status_level;enum mlx5_flow_namespace_type chains_ns;
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +2 -1
@@ -747,6 +747,7 @@ static void ipsec_rx_create_attr_set(struct mlx5e_ipsec *ipsec, attr->family = family; attr->prio =MLX5E_NIC_PRIO ; attr->pol_level =MLX5E_ACCEL_FS_POL_FT_LEVEL ; + attr->pol_miss_level =MLX5E_ACCEL_FS_POL_MISS_FT_LEVEL ; attr->sa_level =MLX5E_ACCEL_FS_ESP_FT_LEVEL ; attr->status_level =MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL ; attr->chains_ns =MLX5_FLOW_NAMESPACE_KERNEL ;
@@ -833,7 +834,7 @@ static int ipsec_rx_chains_create_miss(struct mlx5e_ipsec *ipsec, ft_attr.max_fte =1 ; ft_attr.autogroup.max_num_groups =1 ; - ft_attr.level = attr->pol_level; + ft_attr.level = attr->pol_miss_level; ft_attr.prio = attr->prio; ft =mlx5_create_auto_grouped_flow_table (attr->ns, &ft_attr);
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c +2 -2
@@ -114,9 +114,9 @@#define ETHTOOL_NUM_PRIOS 11#define ETHTOOL_MIN_LEVEL (KERNEL_MIN_LEVEL + ETHTOOL_NUM_PRIOS)/* Vlan, mac, ttc, inner ttc, {UDP/ANY/aRFS/accel/{esp, esp_err}}, IPsec policy, -* {IPsec RoCE MPV,Alias table},IPsec RoCE policy +* IPsec policy miss, {IPsec RoCE MPV,Alias table},IPsec RoCE policy */ -#define KERNEL_NIC_PRIO_NUM_LEVELS 10 +#define KERNEL_NIC_PRIO_NUM_LEVELS 11#define KERNEL_NIC_NUM_PRIOS 1/* One more level for tc, and one more for promisc */ #define KERNEL_MIN_LEVEL (KERNEL_NIC_PRIO_NUM_LEVELS + 2)
Signature · 1 line
2.31.1
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 15 Sep 2025 15:24:31 +0300 you wrote:
Hi,
This patchset provides misc bug fixes from the team to the mlx5 Eth driver.
Find V1 here:
https://lore.kernel.org/all/[email protected]/[...]
Here is the summary with links:
- [net,V2,1/3] net/mlx5e: Harden uplink netdev access against device unbind
https://git.kernel.org/netdev/net/c/6b4be64fd9fe - [net,V2,2/3] net/mlx5e: Prevent entering switchdev mode with inconsistent netns (no matching commit) - [net,V2,3/3] net/mlx5e: Add a miss level for ipsec crypto offload https://git.kernel.org/netdev/net/c/7601a0a46216
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html