Skip to content

Commit bffb023

Browse files
Jack Morgensteindavem330
authored andcommitted
net/mlx4_core: Fix GEN_EQE accessing uninitialixed mutex
We occasionally see in procedure mlx4_GEN_EQE that the driver tries to grab an uninitialized mutex. This can occur in only one of two ways: 1. We are trying to generate an async event on an uninitialized slave. 2. We are trying to generate an async event on an illegal slave number ( < 0 or > persist->num_vfs) or an inactive slave. To deal with #1: move the mutex initialization from specific slave init sequence in procedure mlx_master_do_cmd to mlx4_multi_func_init() (so that the mutex is always initialized for all slaves). To deal with #2: check in procedure mlx4_GEN_EQE that the slave number provided is in the proper range and that the slave is active. Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e5eda89 commit bffb023

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

drivers/net/ethernet/mellanox/mlx4/cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,6 @@ static void mlx4_master_do_cmd(struct mlx4_dev *dev, int slave, u8 cmd,
19931993
goto reset_slave;
19941994
slave_state[slave].vhcr_dma = ((u64) param) << 48;
19951995
priv->mfunc.master.slave_state[slave].cookie = 0;
1996-
mutex_init(&priv->mfunc.master.gen_eqe_mutex[slave]);
19971996
break;
19981997
case MLX4_COMM_CMD_VHCR1:
19991998
if (slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR0)
@@ -2225,6 +2224,7 @@ int mlx4_multi_func_init(struct mlx4_dev *dev)
22252224
for (i = 0; i < dev->num_slaves; ++i) {
22262225
s_state = &priv->mfunc.master.slave_state[i];
22272226
s_state->last_cmd = MLX4_COMM_CMD_RESET;
2227+
mutex_init(&priv->mfunc.master.gen_eqe_mutex[i]);
22282228
for (j = 0; j < MLX4_EVENT_TYPES_NUM; ++j)
22292229
s_state->event_eq[j].eqn = -1;
22302230
__raw_writel((__force u32) 0,

drivers/net/ethernet/mellanox/mlx4/eq.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,10 @@ void mlx4_gen_slave_eqe(struct work_struct *work)
153153

154154
/* All active slaves need to receive the event */
155155
if (slave == ALL_SLAVES) {
156-
for (i = 0; i < dev->num_slaves; i++) {
157-
if (i != dev->caps.function &&
158-
master->slave_state[i].active)
159-
if (mlx4_GEN_EQE(dev, i, eqe))
160-
mlx4_warn(dev, "Failed to generate event for slave %d\n",
161-
i);
156+
for (i = 0; i <= dev->persist->num_vfs; i++) {
157+
if (mlx4_GEN_EQE(dev, i, eqe))
158+
mlx4_warn(dev, "Failed to generate event for slave %d\n",
159+
i);
162160
}
163161
} else {
164162
if (mlx4_GEN_EQE(dev, slave, eqe))
@@ -203,13 +201,11 @@ static void mlx4_slave_event(struct mlx4_dev *dev, int slave,
203201
struct mlx4_eqe *eqe)
204202
{
205203
struct mlx4_priv *priv = mlx4_priv(dev);
206-
struct mlx4_slave_state *s_slave =
207-
&priv->mfunc.master.slave_state[slave];
208204

209-
if (!s_slave->active) {
210-
/*mlx4_warn(dev, "Trying to pass event to inactive slave\n");*/
205+
if (slave < 0 || slave > dev->persist->num_vfs ||
206+
slave == dev->caps.function ||
207+
!priv->mfunc.master.slave_state[slave].active)
211208
return;
212-
}
213209

214210
slave_event(dev, slave, eqe);
215211
}

drivers/net/ethernet/mellanox/mlx4/resource_tracker.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,6 +3095,12 @@ int mlx4_GEN_EQE(struct mlx4_dev *dev, int slave, struct mlx4_eqe *eqe)
30953095
if (!priv->mfunc.master.slave_state)
30963096
return -EINVAL;
30973097

3098+
/* check for slave valid, slave not PF, and slave active */
3099+
if (slave < 0 || slave > dev->persist->num_vfs ||
3100+
slave == dev->caps.function ||
3101+
!priv->mfunc.master.slave_state[slave].active)
3102+
return 0;
3103+
30983104
event_eq = &priv->mfunc.master.slave_state[slave].event_eq[eqe->type];
30993105

31003106
/* Create the event only if the slave is registered */

0 commit comments

Comments
 (0)