patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH 1/1] net/mlx5: fix device removal event handling
@ 2023-05-30 15:13 Viacheslav Ovsiienko
  2023-06-19 12:14 ` Raslan Darawsheh
  0 siblings, 1 reply; 2+ messages in thread
From: Viacheslav Ovsiienko @ 2023-05-30 15:13 UTC (permalink / raw)
  To: dev; +Cc: orika, rasland, matan, stable

On the device removal kernel notifies user space application
with queueing the IBV_DEVICE_FATAL_EVENT and triggering appropriate
file descriptor. Mellanox kernel driver stack emits this event
twice from different layers (mlx5 and uverbs). The IB port index
is not applicable in the event structure and should be ignored
for IBV_DEVICE_FATAL_EVENT events.

Also, on the older kernels (at least from OFED 4.9) there might be
race conditions causing the event queue close before application
fetches the IBV_DEVICE_FATAL_EVENT message with ibv_get_async_event()
API.

To provide the reliable device removal event detection the patch:

  - ignores the IB port index for the IBV_DEVICE_FATAL_EVENT
  - introduces the flag to notify PMD about removal only once
  - acks event with ibv_ack_async_event after actual handling
  - checks for EIO error, making sure queue is not closed yet

Fixes: 40d9f906f4e2 ("net/mlx5: fix device removal handler for multiport")
Cc: stable@dpdk.org

Signed-off-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_ethdev_os.c | 34 +++++++++++++++++--------
 drivers/net/mlx5/mlx5.h                 |  1 +
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
index 55801534d1..639e629fe4 100644
--- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
@@ -746,6 +746,7 @@ mlx5_dev_interrupt_device_fatal(struct mlx5_dev_ctx_shared *sh)
 
 	for (i = 0; i < sh->max_port; ++i) {
 		struct rte_eth_dev *dev;
+		struct mlx5_priv *priv;
 
 		if (sh->port[i].ih_port_id >= RTE_MAX_ETHPORTS) {
 			/*
@@ -756,9 +757,14 @@ mlx5_dev_interrupt_device_fatal(struct mlx5_dev_ctx_shared *sh)
 		}
 		dev = &rte_eth_devices[sh->port[i].ih_port_id];
 		MLX5_ASSERT(dev);
-		if (dev->data->dev_conf.intr_conf.rmv)
+		priv = dev->data->dev_private;
+		MLX5_ASSERT(priv);
+		if (!priv->rmv_notified && dev->data->dev_conf.intr_conf.rmv) {
+			/* Notify driver about removal only once. */
+			priv->rmv_notified = 1;
 			rte_eth_dev_callback_process
 				(dev, RTE_ETH_EVENT_INTR_RMV, NULL);
+		}
 	}
 }
 
@@ -830,21 +836,29 @@ mlx5_dev_interrupt_handler(void *cb_arg)
 		struct rte_eth_dev *dev;
 		uint32_t tmp;
 
-		if (mlx5_glue->get_async_event(sh->cdev->ctx, &event))
+		if (mlx5_glue->get_async_event(sh->cdev->ctx, &event)) {
+			if (errno == EIO) {
+				DRV_LOG(DEBUG,
+					"IBV async event queue closed on: %s",
+					sh->ibdev_name);
+				mlx5_dev_interrupt_device_fatal(sh);
+			}
 			break;
-		/* Retrieve and check IB port index. */
-		tmp = (uint32_t)event.element.port_num;
-		if (!tmp && event.event_type == IBV_EVENT_DEVICE_FATAL) {
+		}
+		if (event.event_type == IBV_EVENT_DEVICE_FATAL) {
 			/*
-			 * The DEVICE_FATAL event is called once for
-			 * entire device without port specifying.
-			 * We should notify all existing ports.
+			 * The DEVICE_FATAL event can be called by kernel
+			 * twice - from mlx5 and uverbs layers, and port
+			 * index is not applicable. We should notify all
+			 * existing ports.
 			 */
-			mlx5_glue->ack_async_event(&event);
 			mlx5_dev_interrupt_device_fatal(sh);
+			mlx5_glue->ack_async_event(&event);
 			continue;
 		}
-		MLX5_ASSERT(tmp && (tmp <= sh->max_port));
+		/* Retrieve and check IB port index. */
+		tmp = (uint32_t)event.element.port_num;
+		MLX5_ASSERT(tmp <= sh->max_port);
 		if (!tmp) {
 			/* Unsupported device level event. */
 			mlx5_glue->ack_async_event(&event);
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 021049ad2b..6aae8fe3f4 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -1743,6 +1743,7 @@ struct mlx5_priv {
 	unsigned int mtr_en:1; /* Whether support meter. */
 	unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */
 	unsigned int lb_used:1; /* Loopback queue is referred to. */
+	unsigned int rmv_notified:1; /* Notified about removal event */
 	uint32_t mark_enabled:1; /* If mark action is enabled on rxqs. */
 	uint32_t num_lag_ports:4; /* Number of ports can be bonded. */
 	uint16_t domain_id; /* Switch domain identifier. */
-- 
2.18.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: [PATCH 1/1] net/mlx5: fix device removal event handling
  2023-05-30 15:13 [PATCH 1/1] net/mlx5: fix device removal event handling Viacheslav Ovsiienko
@ 2023-06-19 12:14 ` Raslan Darawsheh
  0 siblings, 0 replies; 2+ messages in thread
From: Raslan Darawsheh @ 2023-06-19 12:14 UTC (permalink / raw)
  To: Slava Ovsiienko, dev; +Cc: Ori Kam, Matan Azrad, stable

Hi,

> -----Original Message-----
> From: Slava Ovsiienko <viacheslavo@nvidia.com>
> Sent: Tuesday, May 30, 2023 6:13 PM
> To: dev@dpdk.org
> Cc: Ori Kam <orika@nvidia.com>; Raslan Darawsheh <rasland@nvidia.com>;
> Matan Azrad <matan@nvidia.com>; stable@dpdk.org
> Subject: [PATCH 1/1] net/mlx5: fix device removal event handling
> 
> On the device removal kernel notifies user space application with queueing the
> IBV_DEVICE_FATAL_EVENT and triggering appropriate file descriptor. Mellanox
> kernel driver stack emits this event twice from different layers (mlx5 and
> uverbs). The IB port index is not applicable in the event structure and should
> be ignored for IBV_DEVICE_FATAL_EVENT events.
> 
> Also, on the older kernels (at least from OFED 4.9) there might be race
> conditions causing the event queue close before application fetches the
> IBV_DEVICE_FATAL_EVENT message with ibv_get_async_event() API.
> 
> To provide the reliable device removal event detection the patch:
> 
>   - ignores the IB port index for the IBV_DEVICE_FATAL_EVENT
>   - introduces the flag to notify PMD about removal only once
>   - acks event with ibv_ack_async_event after actual handling
>   - checks for EIO error, making sure queue is not closed yet
> 
> Fixes: 40d9f906f4e2 ("net/mlx5: fix device removal handler for multiport")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
> ---

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-19 12:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30 15:13 [PATCH 1/1] net/mlx5: fix device removal event handling Viacheslav Ovsiienko
2023-06-19 12:14 ` Raslan Darawsheh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).