* [dpdk-stable] [PATCH] net/mlx5: fix deadlock of link status alarm
@ 2018-01-09 9:09 Yongseok Koh
2018-01-10 10:11 ` Nelio Laranjeiro
0 siblings, 1 reply; 4+ messages in thread
From: Yongseok Koh @ 2018-01-09 9:09 UTC (permalink / raw)
To: adrien.mazarguil, nelio.laranjeiro; +Cc: dev, Yongseok Koh, stable
If mlx5_dev_link_status_handler() is executed while canceling the alarm,
deadlock can happen because rte_eal_alarm_cancel() waits for all callbackes
to finish execution and both calls are protected by priv->lock.
Fixes: 198a3c339a8f ("mlx5: handle link status interrupts")
Cc: stable@dpdk.org
Signed-off-by: Yongseok Koh <yskoh@mellanox.com>
---
drivers/net/mlx5/mlx5.h | 16 ++++++++++++++++
drivers/net/mlx5/mlx5_ethdev.c | 13 +++++++++----
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index e6a69b823..1a4f444c7 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -165,6 +165,22 @@ priv_lock(struct priv *priv)
}
/**
+ * Try to lock private structure to protect it from concurrent access in the
+ * control path.
+ *
+ * @param priv
+ * Pointer to private structure.
+ *
+ * @return
+ * 1 if the lock is successfully taken; 0 otherwise.
+ */
+static inline int
+priv_trylock(struct priv *priv)
+{
+ return rte_spinlock_trylock(&priv->lock);
+}
+
+/**
* Unlock private structure.
*
* @param priv
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 282ef241e..9354dd17f 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -1185,8 +1185,12 @@ mlx5_dev_link_status_handler(void *arg)
struct priv *priv = dev->data->dev_private;
int ret;
- priv_lock(priv);
- assert(priv->pending_alarm == 1);
+ while (!priv_trylock(priv)) {
+ /* Alarm is being canceled. */
+ if (priv->pending_alarm == 0)
+ return;
+ rte_pause();
+ }
priv->pending_alarm = 0;
ret = priv_link_status_update(priv);
priv_unlock(priv);
@@ -1256,9 +1260,10 @@ priv_dev_interrupt_handler_uninstall(struct priv *priv, struct rte_eth_dev *dev)
if (priv->primary_socket)
rte_intr_callback_unregister(&priv->intr_handle_socket,
mlx5_dev_handler_socket, dev);
- if (priv->pending_alarm)
+ if (priv->pending_alarm) {
+ priv->pending_alarm = 0;
rte_eal_alarm_cancel(mlx5_dev_link_status_handler, dev);
- priv->pending_alarm = 0;
+ }
priv->intr_handle.fd = 0;
priv->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
priv->intr_handle_socket.fd = 0;
--
2.11.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-stable] [PATCH] net/mlx5: fix deadlock of link status alarm
2018-01-09 9:09 [dpdk-stable] [PATCH] net/mlx5: fix deadlock of link status alarm Yongseok Koh
@ 2018-01-10 10:11 ` Nelio Laranjeiro
0 siblings, 0 replies; 4+ messages in thread
From: Nelio Laranjeiro @ 2018-01-10 10:11 UTC (permalink / raw)
To: Yongseok Koh; +Cc: adrien.mazarguil, dev, stable
On Tue, Jan 09, 2018 at 01:09:20AM -0800, Yongseok Koh wrote:
> If mlx5_dev_link_status_handler() is executed while canceling the alarm,
> deadlock can happen because rte_eal_alarm_cancel() waits for all callbackes
> to finish execution and both calls are protected by priv->lock.
>
> Fixes: 198a3c339a8f ("mlx5: handle link status interrupts")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yongseok Koh <yskoh@mellanox.com>
<snip/>
Acked-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
Thanks,
--
Nélio Laranjeiro
6WIND
^ permalink raw reply [flat|nested] 4+ messages in thread
* [dpdk-stable] [PATCH] net/mlx5: fix deadlock of link status alarm
@ 2018-01-10 17:46 Yongseok Koh
2018-01-15 6:45 ` Shahaf Shuler
0 siblings, 1 reply; 4+ messages in thread
From: Yongseok Koh @ 2018-01-10 17:46 UTC (permalink / raw)
To: adrien.mazarguil, nelio.laranjeiro; +Cc: dev, Yongseok Koh, stable
If mlx5_dev_link_status_handler() is executed while canceling the alarm,
deadlock can happen because rte_eal_alarm_cancel() waits for all callbackes
to finish execution and both calls are protected by priv->lock.
Fixes: 198a3c339a8f ("mlx5: handle link status interrupts")
Cc: stable@dpdk.org
Signed-off-by: Yongseok Koh <yskoh@mellanox.com>
Acked-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
---
drivers/net/mlx5/mlx5.h | 16 ++++++++++++++++
drivers/net/mlx5/mlx5_ethdev.c | 13 +++++++++----
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 8ee522069..e740a4e77 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -180,6 +180,22 @@ priv_lock(struct priv *priv)
}
/**
+ * Try to lock private structure to protect it from concurrent access in the
+ * control path.
+ *
+ * @param priv
+ * Pointer to private structure.
+ *
+ * @return
+ * 1 if the lock is successfully taken; 0 otherwise.
+ */
+static inline int
+priv_trylock(struct priv *priv)
+{
+ return rte_spinlock_trylock(&priv->lock);
+}
+
+/**
* Unlock private structure.
*
* @param priv
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 278a4dfc3..618d13d5f 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -1187,8 +1187,12 @@ mlx5_dev_link_status_handler(void *arg)
struct priv *priv = dev->data->dev_private;
int ret;
- priv_lock(priv);
- assert(priv->pending_alarm == 1);
+ while (!priv_trylock(priv)) {
+ /* Alarm is being canceled. */
+ if (priv->pending_alarm == 0)
+ return;
+ rte_pause();
+ }
priv->pending_alarm = 0;
ret = priv_link_status_update(priv);
priv_unlock(priv);
@@ -1258,9 +1262,10 @@ priv_dev_interrupt_handler_uninstall(struct priv *priv, struct rte_eth_dev *dev)
if (priv->primary_socket)
rte_intr_callback_unregister(&priv->intr_handle_socket,
mlx5_dev_handler_socket, dev);
- if (priv->pending_alarm)
+ if (priv->pending_alarm) {
+ priv->pending_alarm = 0;
rte_eal_alarm_cancel(mlx5_dev_link_status_handler, dev);
- priv->pending_alarm = 0;
+ }
priv->intr_handle.fd = 0;
priv->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
priv->intr_handle_socket.fd = 0;
--
2.11.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-stable] [PATCH] net/mlx5: fix deadlock of link status alarm
2018-01-10 17:46 Yongseok Koh
@ 2018-01-15 6:45 ` Shahaf Shuler
0 siblings, 0 replies; 4+ messages in thread
From: Shahaf Shuler @ 2018-01-15 6:45 UTC (permalink / raw)
To: Yongseok Koh, Adrien Mazarguil, Nélio Laranjeiro
Cc: dev, Yongseok Koh, stable
Wednesday, January 10, 2018 7:47 PM, Yongseok Koh:
> If mlx5_dev_link_status_handler() is executed while canceling the alarm,
> deadlock can happen because rte_eal_alarm_cancel() waits for all callbackes
> to finish execution and both calls are protected by priv->lock.
>
> Fixes: 198a3c339a8f ("mlx5: handle link status interrupts")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yongseok Koh <yskoh@mellanox.com>
> Acked-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
> ---
> drivers/net/mlx5/mlx5.h | 16 ++++++++++++++++
> drivers/net/mlx5/mlx5_ethdev.c | 13 +++++++++----
> 2 files changed, 25 insertions(+), 4 deletions(-)
>
Applied to next-net-mlx, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-01-15 6:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-09 9:09 [dpdk-stable] [PATCH] net/mlx5: fix deadlock of link status alarm Yongseok Koh
2018-01-10 10:11 ` Nelio Laranjeiro
2018-01-10 17:46 Yongseok Koh
2018-01-15 6:45 ` Shahaf Shuler
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).