* [PATCH net] net/mlx5: Enter error state on surprise removal
@ 2026-12-02 19:43 Tariq Toukan
2026-12-02 19:48 ` netdev-bot+sinfo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Tariq Toukan @ 2026-12-02 19:43 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni, Willem de Bruijn
Cc: Gal Pressman, Leon Romanovsky, linux-rdma, Mark Bloch,
Moshe Shemesh, Moshe Shemesh, Parav Pandit, Saeed Mahameed,
Saeed Mahameed, Tariq Toukan, Uri Dar
From: Uri Dar <udar@nvidia.com>
On PCI surprise removal, remove_one() drains the health work before
tearing the device down, so the fatal health work never puts the dead
device in error state. Work already posted to the device, such as the
IPoIB multicast leave MADs sent during IB unregister, then never
completes and the removal hangs in mcast_remove_one().
On remove_one(), after draining the health work, enter error state if
the device is dead. Do it without the "previous error is still being
handled" check of mlx5_enter_error_state(): once the health work is
drained, nobody else will handle an error that poll_health() already
marked. Skip it when the device is not loaded, for example after a
failed reload: the command interface may not be set up, and no driver
is left waiting on the device.
Fixes: 41798df9bfca ("net/mlx5: Drain wq first during PCI device removal")
Signed-off-by: Uri Dar <udar@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/health.c | 12 ++++++++++++
drivers/net/ethernet/mellanox/mlx5/core/main.c | 1 +
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h | 1 +
3 files changed, 14 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c b/drivers/net/ethernet/mellanox/mlx5/core/health.c
index aeeb136f5ebc..622c9e0f065d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
@@ -224,6 +224,18 @@ void mlx5_enter_error_state(struct mlx5_core_dev *dev, bool force)
mutex_unlock(&dev->intf_state_mutex);
}
+/* Caller must drain the fw_reset and health work before calling this */
+void mlx5_health_enter_error_state_drained(struct mlx5_core_dev *dev)
+{
+ if (!mlx5_health_check_fatal_sensors(dev))
+ return;
+
+ mutex_lock(&dev->intf_state_mutex);
+ if (test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state))
+ enter_error_state(dev, false);
+ mutex_unlock(&dev->intf_state_mutex);
+}
+
void mlx5_error_sw_reset(struct mlx5_core_dev *dev)
{
unsigned long end, delay_ms = mlx5_tout_ms(dev, PCI_TOGGLE);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index 0439fcfb9ce5..567df9d8eb52 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -2014,6 +2014,7 @@ static void remove_one(struct pci_dev *pdev)
set_bit(MLX5_BREAK_FW_WAIT, &dev->intf_state);
mlx5_drain_fw_reset(dev);
mlx5_drain_health_wq(dev);
+ mlx5_health_enter_error_state_drained(dev);
mlx5_sriov_disable(pdev, false);
mlx5_uninit_one(dev);
mlx5_shd_uninit(dev);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
index d84d0424d04e..9edbf190683e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
@@ -231,6 +231,7 @@ int mlx5_cmd_teardown_hca(struct mlx5_core_dev *dev);
int mlx5_cmd_force_teardown_hca(struct mlx5_core_dev *dev);
int mlx5_cmd_fast_teardown_hca(struct mlx5_core_dev *dev);
void mlx5_enter_error_state(struct mlx5_core_dev *dev, bool force);
+void mlx5_health_enter_error_state_drained(struct mlx5_core_dev *dev);
void mlx5_error_sw_reset(struct mlx5_core_dev *dev);
u32 mlx5_health_check_fatal_sensors(struct mlx5_core_dev *dev);
int mlx5_health_wait_pci_up(struct mlx5_core_dev *dev);
--
2.44.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] net/mlx5: Enter error state on surprise removal
2026-12-02 19:43 [PATCH net] net/mlx5: Enter error state on surprise removal Tariq Toukan
@ 2026-12-02 19:48 ` netdev-bot+sinfo
2026-12-02 19:54 ` sashiko-bot
2026-12-03 19:44 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-12-02 19:48 UTC (permalink / raw)
To: Tariq Toukan
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni, Willem de Bruijn, Gal Pressman,
Leon Romanovsky, linux-rdma, Mark Bloch, Moshe Shemesh,
Moshe Shemesh, Parav Pandit, Saeed Mahameed, Saeed Mahameed,
Uri Dar
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net/mlx5: Enter error state on surprise removal
2026-12-02 19:43 [PATCH net] net/mlx5: Enter error state on surprise removal Tariq Toukan
2026-12-02 19:48 ` netdev-bot+sinfo
@ 2026-12-02 19:54 ` sashiko-bot
2026-12-03 19:44 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-02 19:54 UTC (permalink / raw)
To: Tariq Toukan; +Cc: linux-rdma
> From: Uri Dar <udar@nvidia.com>
>
> On PCI surprise removal, remove_one() drains the health work before
> tearing the device down, so the fatal health work never puts the dead
> device in error state. Work already posted to the device, such as the
> IPoIB multicast leave MADs sent during IB unregister, then never
> completes and the removal hangs in mcast_remove_one().
>
> On remove_one(), after draining the health work, enter error state if
> the device is dead. Do it without the "previous error is still being
> handled" check of mlx5_enter_error_state(): once the health work is
> drained, nobody else will handle an error that poll_health() already
> marked. Skip it when the device is not loaded, for example after a
> failed reload: the command interface may not be set up, and no driver
> is left waiting on the device.
>
> Fixes: 41798df9bfca ("net/mlx5: Drain wq first during PCI device removal")
> Signed-off-by: Uri Dar <udar@nvidia.com>
> Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202194317.3593082-1-tariqt@nvidia.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net/mlx5: Enter error state on surprise removal
2026-12-02 19:43 [PATCH net] net/mlx5: Enter error state on surprise removal Tariq Toukan
2026-12-02 19:48 ` netdev-bot+sinfo
2026-12-02 19:54 ` sashiko-bot
@ 2026-12-03 19:44 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 19:44 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, willemb,
gal, leon, linux-rdma, mbloch, moshe, moshe, parav, saeedm,
saeedm, udar
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · 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] remove_one() now calls mlx5_health_enter_error_state_drained().
- [Medium] The patch only fixes the error-state entry on the PCI
remove_one() path.
- [Medium] mlx5_health_enter_error_state_drained() (health.c) reads the
fatal sensors only once, right after mlx5_drain_health_wq().
--
net/mlx5: Enter error state on surprise removal
On PCI surprise removal, remove_one() now checks the fatal sensors after
it drains the health work. If the device is dead and the interface is
up, it puts the device in error state, so already-posted work such as
IPoIB multicast leave MADs can complete. A new helper does this:
mlx5_health_enter_error_state_drained(). It skips the "previous error is
still being handled" check of mlx5_enter_error_state().
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c b/drivers/net/ethernet/mellanox/mlx5/core/health.c
> index aeeb136f5ebc7..622c9e0f065d9 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
> @@ -224,6 +224,18 @@ void mlx5_enter_error_state(struct mlx5_core_dev *dev, bool force)
> mutex_unlock(&dev->intf_state_mutex);
> }
>
> +/* Caller must drain the fw_reset and health work before calling this */
> +void mlx5_health_enter_error_state_drained(struct mlx5_core_dev *dev)
> +{
> + if (!mlx5_health_check_fatal_sensors(dev))
> + return;
[Severity: Medium]
This sensor check runs only once, right after mlx5_drain_health_wq(). What
happens if the device or firmware goes fatal after this check but before
the IB device is unregistered?
mlx5_drain_health_wq() sets MLX5_DROP_HEALTH_WORK and cancels the works,
but the health poll timer stays armed. Only mlx5_stop_health_poll() in
mlx5_function_disable() stops it, and that runs at the end of
mlx5_uninit_one(). By then mlx5_sriov_disable() and
mlx5_unregister_device() have already removed the IB device.
If the failure happens in that window:
poll_health()
dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR;
mlx5_trigger_health_work(dev);
mlx5_fw_fatal_reporter_err_work()
if (test_bit(MLX5_DROP_HEALTH_WORK, &health->flags)) {
mlx5_core_err(dev, "health works are not permitted at this stage\n");
mutex_unlock(&dev->intf_state_mutex);
return;
}
In that case mlx5_cmd_flush() never runs, and mlx5_ib never receives
MLX5_DEV_EVENT_SYS_ERROR.
The commit message says "once the health work is drained, nobody else
will handle an error that poll_health() already marked". Wouldn't the
same reasoning also apply to errors that poll_health() marks after this
check?
pciehp surprise removal is covered here, because
pciehp_unconfigure_device() calls pci_dev_set_disconnected() before the
device is removed. Two windows remain:
- a device or FW failure during an orderly unbind
- a surprise removal that races an orderly remove already in progress
> +
> + mutex_lock(&dev->intf_state_mutex);
> + if (test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state))
> + enter_error_state(dev, false);
[Severity: High]
Could this lead to a use-after-free of struct mlx5_ib_dev?
enter_error_state() does:
mlx5_notifier_call_chain(dev->priv.events, MLX5_DEV_EVENT_SYS_ERROR, (void *)1);
The mlx5_ib listener does not handle the event inline.
mlx5_ib_sys_error_event() in drivers/infiniband/hw/mlx5/main.c defers it
to a work item:
work->dev = container_of(nb, struct mlx5_ib_dev, sys_error_events);
...
queue_work(mlx5_ib_event_wq, &work->work);
It takes no reference on the ibdev.
Right after this, on the same thread, remove_one() continues into:
remove_one()
mlx5_uninit_one()
mlx5_unregister_device()
del_adev()
mlx5r_remove()
__mlx5_ib_remove()
mlx5_ib_stage_sys_error_notifier_cleanup()
mlx5_notifier_unregister()
kfree(dev->port);
ib_dealloc_device(&dev->ib_dev);
Nothing in this sequence flushes or cancels mlx5_ib_event_wq. It looks
like the queue is only destroyed at module exit.
Suppose mlx5_ib_handle_sys_error_event() has not run yet when
ib_dealloc_device() frees the device. It would then run on freed memory:
struct mlx5_ib_dev *ibdev = work->dev;
...
mlx5_ib_handle_internal_error(ibdev);
...
ibdev->ib_active = false;
That includes walking the QP/CQ lists. The window is a backlogged ordered
workqueue, or a delay in creating workers under memory pressure.
The missing flush in mlx5_ib is older. It can also be reached from
mlx5_pci_err_detected() and from the fatal work unload path. This patch,
though, sends SYS_ERROR right before synchronous IB teardown on every
surprise removal, and the fix depends on that async handoff.
Should the mlx5_ib teardown flush mlx5_ib_event_wq, or cancel the pending
sys_error work, before it frees the device?
> + mutex_unlock(&dev->intf_state_mutex);
> +}
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
> index 0439fcfb9ce57..567df9d8eb524 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
> @@ -2014,6 +2014,7 @@ static void remove_one(struct pci_dev *pdev)
> set_bit(MLX5_BREAK_FW_WAIT, &dev->intf_state);
> mlx5_drain_fw_reset(dev);
> mlx5_drain_health_wq(dev);
> + mlx5_health_enter_error_state_drained(dev);
[Severity: Medium]
This fixes remove_one(). Are there other drain-then-teardown paths that
leave the device in the same drained but never-errored state?
mlx5_sf_dev_remove() in sf/dev/driver.c does:
set_bit(MLX5_BREAK_FW_WAIT, &mdev->intf_state);
mlx5_drain_health_wq(mdev);
if (mlx5_dev_is_lightweight(mdev))
mlx5_uninit_one_light(mdev);
else
mlx5_uninit_one(mdev);
mlx5_sf_dev_shutdown() also drains the health work and then calls
mlx5_unload_one().
SF mdevs share the parent PF BAR, and mdev->pdev is the parent pdev, so
they are dead too after a PF surprise removal. They are removed from
inside the PF teardown:
remove_one()
mlx5_uninit_one()
mlx5_unload()
mlx5_sf_dev_table_destroy()
...
mlx5_sf_dev_remove()
The SYS_ERROR raised for the PF goes only to the PF's own notifier chain.
So the SF's mlx5_ib device never receives it, and mlx5_cmd_flush() never
runs for the SF.
The PCI shutdown() callback in main.c follows a similar pattern:
mlx5_drain_fw_reset(dev);
mlx5_drain_health_wq(dev);
err = mlx5_try_fast_unload(dev);
if (err)
mlx5_unload_one(dev, false);
If poll_health() has already set MLX5_DEVICE_STATE_INTERNAL_ERROR,
mlx5_try_fast_unload() returns early:
if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) {
mlx5_core_dbg(dev, "Device in internal error state, giving up\n");
return -EAGAIN;
}
That return comes before its own mlx5_enter_error_state(dev, true).
mlx5_unload_one() then removes the IB aux device with no cmd flush and no
SYS_ERROR first.
Should these paths call mlx5_health_enter_error_state_drained() too?
> mlx5_sriov_disable(pdev, false);
> mlx5_uninit_one(dev);
> mlx5_shd_uninit(dev);
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202194317.3593082-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-03 19:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 19:43 [PATCH net] net/mlx5: Enter error state on surprise removal Tariq Toukan
2026-12-02 19:48 ` netdev-bot+sinfo
2026-12-02 19:54 ` sashiko-bot
2026-12-03 19:44 ` 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