Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 3d43f9f

Browse files
lsun100jwrdegoede
authored andcommitted
platform/mellanox: fix potential race in mlxbf-tmfifo driver
This commit adds memory barrier for the 'vq' update in function mlxbf_tmfifo_virtio_find_vqs() to avoid potential race due to out-of-order memory write. It also adds barrier for the 'is_ready' flag to make sure the initializations are visible before this flag is checked. Signed-off-by: Liming Sun <[email protected]> Reviewed-by: Vadim Pasternak <[email protected]> Link: https://lore.kernel.org/r/b98c0ab61d644ba38fa9b3fd1607b138b0dd820b.1682518748.git.limings@nvidia.com Signed-off-by: Hans de Goede <[email protected]>
1 parent 4b65f95 commit 3d43f9f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/platform/mellanox/mlxbf-tmfifo.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ static void mlxbf_tmfifo_rxtx(struct mlxbf_tmfifo_vring *vring, bool is_rx)
784784
fifo = vring->fifo;
785785

786786
/* Return if vdev is not ready. */
787-
if (!fifo->vdev[devid])
787+
if (!fifo || !fifo->vdev[devid])
788788
return;
789789

790790
/* Return if another vring is running. */
@@ -980,9 +980,13 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,
980980

981981
vq->num_max = vring->num;
982982

983+
vq->priv = vring;
984+
985+
/* Make vq update visible before using it. */
986+
virtio_mb(false);
987+
983988
vqs[i] = vq;
984989
vring->vq = vq;
985-
vq->priv = vring;
986990
}
987991

988992
return 0;
@@ -1302,6 +1306,9 @@ static int mlxbf_tmfifo_probe(struct platform_device *pdev)
13021306

13031307
mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL);
13041308

1309+
/* Make all updates visible before setting the 'is_ready' flag. */
1310+
virtio_mb(false);
1311+
13051312
fifo->is_ready = true;
13061313
return 0;
13071314

0 commit comments

Comments
 (0)