TmFIFO invokes virtqueue callbacks from its FIFO work item under
spin_lock_irqsave(). The core's synchronize_rcu() fallback already
covers those sections.

Implement synchronize_cbs() using the existing per-direction locks
instead of waiting for an RCU grace period. fifo->spin_lock[0] covers
the transmit callbacks, including the callback from the timeout
handler. fifo->spin_lock[1] covers the receive callbacks. Take and
release each lock in turn to synchronize with callbacks running
under that lock.

Assisted-by: LLM
Signed-off-by: Karl Mehltretter <[email protected]>
---
 drivers/platform/mellanox/mlxbf-tmfifo.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/platform/mellanox/mlxbf-tmfifo.c 
b/drivers/platform/mellanox/mlxbf-tmfifo.c
index 3c6408581373..664bec20a7ae 100644
--- a/drivers/platform/mellanox/mlxbf-tmfifo.c
+++ b/drivers/platform/mellanox/mlxbf-tmfifo.c
@@ -1135,6 +1135,20 @@ static void mlxbf_tmfifo_virtio_reset(struct 
virtio_device *vdev)
        tm_vdev->status = 0;
 }
 
+/* Synchronize with callbacks running in the FIFO work item. */
+static void mlxbf_tmfifo_virtio_synchronize_cbs(struct virtio_device *vdev)
+{
+       struct mlxbf_tmfifo_vdev *tm_vdev = mlxbf_vdev_to_tmfifo(vdev);
+       struct mlxbf_tmfifo *fifo = tm_vdev->vrings[0].fifo;
+       unsigned long flags;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(fifo->spin_lock); i++) {
+               spin_lock_irqsave(&fifo->spin_lock[i], flags);
+               spin_unlock_irqrestore(&fifo->spin_lock[i], flags);
+       }
+}
+
 /* Read the value of a configuration field. */
 static void mlxbf_tmfifo_virtio_get(struct virtio_device *vdev,
                                    unsigned int offset,
@@ -1179,6 +1193,7 @@ static const struct virtio_config_ops 
mlxbf_tmfifo_virtio_config_ops = {
        .find_vqs = mlxbf_tmfifo_virtio_find_vqs,
        .del_vqs = mlxbf_tmfifo_virtio_del_vqs,
        .reset = mlxbf_tmfifo_virtio_reset,
+       .synchronize_cbs = mlxbf_tmfifo_virtio_synchronize_cbs,
        .set_status = mlxbf_tmfifo_virtio_set_status,
        .get_status = mlxbf_tmfifo_virtio_get_status,
        .get = mlxbf_tmfifo_virtio_get,
-- 
2.39.5 (Apple Git-154)

Reply via email to