Commit f5adbfee authored by Eran Ben Elisha's avatar Eran Ben Elisha Committed by David S. Miller

net/mlx4_core: Fix sleeping while holding spinlock at rem_slave_counters

When cleaning slave's counter resources, we hold a spinlock that
protects the slave's counters list. As part of the clean, we call
__mlx4_clear_if_stat which calls mlx4_alloc_cmd_mailbox which is a
sleepable function.

In order to fix this issue, hold the spinlock, and copy all counter
indices into a temporary array, and release the spinlock. Afterwards,
iterate over this array and free every counter. Repeat this scenario
until the original list is empty (a new counter might have been added
while releasing the counters from the temporary array).

Fixes: b72ca7e9 ("net/mlx4_core: Reset counters data when freed")
Reported-by: default avatarMoni Shoua <monis@mellanox.com>
Tested-by: default avatarMoni Shoua <monis@mellanox.com>
Signed-off-by: default avatarJack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: default avatarEran Ben Elisha <eranbe@mellanox.com>
Signed-off-by: default avatarOr Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d4e28cbd
...@@ -4952,26 +4952,41 @@ static void rem_slave_counters(struct mlx4_dev *dev, int slave) ...@@ -4952,26 +4952,41 @@ static void rem_slave_counters(struct mlx4_dev *dev, int slave)
struct res_counter *counter; struct res_counter *counter;
struct res_counter *tmp; struct res_counter *tmp;
int err; int err;
int index; int *counters_arr = NULL;
int i, j;
err = move_all_busy(dev, slave, RES_COUNTER); err = move_all_busy(dev, slave, RES_COUNTER);
if (err) if (err)
mlx4_warn(dev, "rem_slave_counters: Could not move all counters - too busy for slave %d\n", mlx4_warn(dev, "rem_slave_counters: Could not move all counters - too busy for slave %d\n",
slave); slave);
counters_arr = kmalloc_array(dev->caps.max_counters,
sizeof(*counters_arr), GFP_KERNEL);
if (!counters_arr)
return;
do {
i = 0;
j = 0;
spin_lock_irq(mlx4_tlock(dev)); spin_lock_irq(mlx4_tlock(dev));
list_for_each_entry_safe(counter, tmp, counter_list, com.list) { list_for_each_entry_safe(counter, tmp, counter_list, com.list) {
if (counter->com.owner == slave) { if (counter->com.owner == slave) {
index = counter->com.res_id; counters_arr[i++] = counter->com.res_id;
rb_erase(&counter->com.node, rb_erase(&counter->com.node,
&tracker->res_tree[RES_COUNTER]); &tracker->res_tree[RES_COUNTER]);
list_del(&counter->com.list); list_del(&counter->com.list);
kfree(counter); kfree(counter);
__mlx4_counter_free(dev, index);
mlx4_release_resource(dev, slave, RES_COUNTER, 1, 0);
} }
} }
spin_unlock_irq(mlx4_tlock(dev)); spin_unlock_irq(mlx4_tlock(dev));
while (j < i) {
__mlx4_counter_free(dev, counters_arr[j++]);
mlx4_release_resource(dev, slave, RES_COUNTER, 1, 0);
}
} while (i);
kfree(counters_arr);
} }
static void rem_slave_xrcdns(struct mlx4_dev *dev, int slave) static void rem_slave_xrcdns(struct mlx4_dev *dev, int slave)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment