]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net/mlx4: Switching between sending commands via polling and events may results in...
authorMatan Barak <matanb@mellanox.com>
Wed, 9 Jul 2014 08:29:21 +0000 (11:29 +0300)
committerMukesh Kacker <mukesh.kacker@oracle.com>
Tue, 7 Jul 2015 21:45:21 +0000 (14:45 -0700)
When switching between those methonds of sending commands, it's
possbile that a task will keep waiting for the polling sempahore,
but may never be able to acquire it.
This is due to mlx4_cmd_use_events which "down"s the
sempahore back to 0.

Reproducing it involves in sending commands while changing
between mlx4_cmd_use_polling and mlx4_cmd_use_events.

Signed-off-by: Matan Barak <matanb@mellanox.com>
(Ported from Mellanox OFED 2.4)

Signed-off-by: Mukesh Kacker <mukesh.kacker@oracle.com>
drivers/net/ethernet/mellanox/mlx4/cmd.c
drivers/net/ethernet/mellanox/mlx4/mlx4.h

index 27ee706ae947859090c7f41e3c0d4d5ed8834585..372443c2853953a73166958aa850ebe7fb7a51ac 100644 (file)
@@ -805,14 +805,20 @@ int __mlx4_cmd(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
                if (dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR)
                        return mlx4_internal_err_ret_value(dev, op,
                                                          op_modifier);
-               if (mlx4_priv(dev)->cmd.use_events)
-                       return mlx4_cmd_wait(dev, in_param, out_param,
-                                            out_is_imm, in_modifier,
-                                            op_modifier, op, timeout);
-               else
-                       return mlx4_cmd_poll(dev, in_param, out_param,
-                                            out_is_imm, in_modifier,
-                                            op_modifier, op, timeout);
+               else {
+                       int ret;
+                       read_lock(&mlx4_priv(dev)->cmd.switch_lock);
+                       if (mlx4_priv(dev)->cmd.use_events)
+                               ret = mlx4_cmd_wait(dev, in_param, out_param,
+                                                   out_is_imm, in_modifier,
+                                                   op_modifier, op, timeout);
+                       else
+                               ret = mlx4_cmd_poll(dev, in_param, out_param,
+                                                   out_is_imm, in_modifier,
+                                                   op_modifier, op, timeout);
+                       read_unlock(&mlx4_priv(dev)->cmd.switch_lock);
+                       return ret;
+               }
        }
        return mlx4_slave_cmd(dev, in_param, out_param, out_is_imm,
                              in_modifier, op_modifier, op, timeout);
@@ -2469,6 +2475,7 @@ int mlx4_cmd_init(struct mlx4_dev *dev)
        int flags = 0;
 
        if (!priv->cmd.initialized) {
+               rwlock_init(&priv->cmd.switch_lock);
                mutex_init(&priv->cmd.slave_cmd_mutex);
                sema_init(&priv->cmd.poll_sem, 1);
                priv->cmd.use_events = 0;
@@ -2598,6 +2605,7 @@ int mlx4_cmd_use_events(struct mlx4_dev *dev)
        if (!priv->cmd.context)
                return -ENOMEM;
 
+       write_lock(&priv->cmd.switch_lock);
        for (i = 0; i < priv->cmd.max_cmds; ++i) {
                priv->cmd.context[i].token = i;
                priv->cmd.context[i].next  = i + 1;
@@ -2622,6 +2630,7 @@ int mlx4_cmd_use_events(struct mlx4_dev *dev)
 
        down(&priv->cmd.poll_sem);
        priv->cmd.use_events = 1;
+       write_unlock(&priv->cmd.switch_lock);
 
        return err;
 }
@@ -2634,6 +2643,7 @@ void mlx4_cmd_use_polling(struct mlx4_dev *dev)
        struct mlx4_priv *priv = mlx4_priv(dev);
        int i;
 
+       write_lock(&priv->cmd.switch_lock);
        priv->cmd.use_events = 0;
 
        for (i = 0; i < priv->cmd.max_cmds; ++i)
@@ -2642,6 +2652,7 @@ void mlx4_cmd_use_polling(struct mlx4_dev *dev)
        kfree(priv->cmd.context);
 
        up(&priv->cmd.poll_sem);
+       write_unlock(&priv->cmd.switch_lock);
 }
 
 struct mlx4_cmd_mailbox *mlx4_alloc_cmd_mailbox(struct mlx4_dev *dev)
index 84d1cfe8113f045c29860213eb9cb6765a2cc864..b38e385147ccbbebeefc3eda38d2634943accd61 100644 (file)
@@ -612,6 +612,7 @@ struct mlx4_cmd {
        struct mutex            slave_cmd_mutex;
        struct semaphore        poll_sem;
        struct semaphore        event_sem;
+       rwlock_t                switch_lock;
        int                     max_cmds;
        spinlock_t              context_lock;
        int                     free_head;