All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net/mlx4_en: initialize cmd.context_lock spinlock earlier
@ 2016-06-13 14:50 Eric Dumazet
  2016-06-15 19:17 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2016-06-13 14:50 UTC (permalink / raw)
  To: David Miller
  Cc: netdev, Eugenia Emantayev, Tariq Toukan, Maciej Żenczykowski

From: Eric Dumazet <edumazet@google.com>

Maciej Żenczykowski reported lockdep warning a spinlock
was not registered before being held in mlx4_cmd_wake_completions()

cmd.context_lock initialization is not at the right place.

1) mlx4_cmd_use_events() can be called multiple times.
   Calling spin_lock_init() on a live spinlock can lead
   to hangs.

2) mlx4_cmd_wake_completions() can be called while lock
   has not been initialized.
   Lockdep complains, and current logic is not race prone.

It seems better to move the initialization earlier in
mlx4_load_one()

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Maciej Żenczykowski <maze@google.com>
Cc: Eugenia Emantayev <eugenia@mellanox.com>
Cc: Tariq Toukan <tariqt@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlx4/cmd.c  |    1 -
 drivers/net/ethernet/mellanox/mlx4/main.c |    1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/ethernet/mellanox/mlx4/cmd.c
index e94ca1c3fc7c..f04a423ff79d 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c
@@ -2597,7 +2597,6 @@ int mlx4_cmd_use_events(struct mlx4_dev *dev)
 	priv->cmd.free_head = 0;
 
 	sema_init(&priv->cmd.event_sem, priv->cmd.max_cmds);
-	spin_lock_init(&priv->cmd.context_lock);
 
 	for (priv->cmd.token_mask = 1;
 	     priv->cmd.token_mask < priv->cmd.max_cmds;
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 12c77a70abdb..372ebfa880f5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -3222,6 +3222,7 @@ static int mlx4_load_one(struct pci_dev *pdev, int pci_dev_data,
 
 	INIT_LIST_HEAD(&priv->pgdir_list);
 	mutex_init(&priv->pgdir_mutex);
+	spin_lock_init(&priv->cmd.context_lock);
 
 	INIT_LIST_HEAD(&priv->bf_list);
 	mutex_init(&priv->bf_mutex);

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

* Re: [PATCH net] net/mlx4_en: initialize cmd.context_lock spinlock earlier
  2016-06-13 14:50 [PATCH net] net/mlx4_en: initialize cmd.context_lock spinlock earlier Eric Dumazet
@ 2016-06-15 19:17 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2016-06-15 19:17 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev, eugenia, tariqt, maze

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Mon, 13 Jun 2016 07:50:25 -0700

> From: Eric Dumazet <edumazet@google.com>
> 
> Maciej Żenczykowski reported lockdep warning a spinlock
> was not registered before being held in mlx4_cmd_wake_completions()
> 
> cmd.context_lock initialization is not at the right place.
> 
> 1) mlx4_cmd_use_events() can be called multiple times.
>    Calling spin_lock_init() on a live spinlock can lead
>    to hangs.
> 
> 2) mlx4_cmd_wake_completions() can be called while lock
>    has not been initialized.
>    Lockdep complains, and current logic is not race prone.
> 
> It seems better to move the initialization earlier in
> mlx4_load_one()
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: Maciej Żenczykowski <maze@google.com>

Applied.

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

end of thread, other threads:[~2016-06-15 19:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-13 14:50 [PATCH net] net/mlx4_en: initialize cmd.context_lock spinlock earlier Eric Dumazet
2016-06-15 19:17 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.