summary refs log tree commit diff stats
path: root/include/hw/virtio/virtio-scsi.h
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2025-03-11 21:26:08 +0800
committerKevin Wolf <kwolf@redhat.com>2025-03-13 17:57:23 +0100
commitb348ca2e043c0f7c9ecc1bbbd7dd87db47887e9f (patch)
treee9c26a542a03226f2c38a81fe70f058a7184c292 /include/hw/virtio/virtio-scsi.h
parent1cf18cc9bf5e9f88ad92f89886652e0361e2f41f (diff)
downloadfocaccia-qemu-b348ca2e043c0f7c9ecc1bbbd7dd87db47887e9f.tar.gz
focaccia-qemu-b348ca2e043c0f7c9ecc1bbbd7dd87db47887e9f.zip
virtio-scsi: introduce event and ctrl virtqueue locks
Virtqueues are not thread-safe. Until now this was not a major issue
since all virtqueue processing happened in the same thread. The ctrl
queue's Task Management Function (TMF) requests sometimes need the main
loop, so a BH was used to schedule the virtqueue completion back in the
thread that has virtqueue access.

When IOThread Virtqueue Mapping is introduced in later commits, event
and ctrl virtqueue accesses from other threads will become necessary.
Introduce an optional per-virtqueue lock so the event and ctrl
virtqueues can be protected in the commits that follow.

The addition of the ctrl virtqueue lock makes
virtio_scsi_complete_req_from_main_loop() and its BH unnecessary.
Instead, take the ctrl virtqueue lock from the main loop thread.

The cmd virtqueue does not have a lock because the entirety of SCSI
command processing happens in one thread. Only one thread accesses the
cmd virtqueue and a lock is unnecessary.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20250311132616.1049687-6-stefanha@redhat.com>
Tested-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'include/hw/virtio/virtio-scsi.h')
-rw-r--r--include/hw/virtio/virtio-scsi.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
index be230cd4bf..4ee98ebf63 100644
--- a/include/hw/virtio/virtio-scsi.h
+++ b/include/hw/virtio/virtio-scsi.h
@@ -84,6 +84,9 @@ struct VirtIOSCSI {
     int resetting; /* written from main loop thread, read from any thread */
     bool events_dropped;
 
+    QemuMutex ctrl_lock; /* protects ctrl_vq */
+    QemuMutex event_lock; /* protects event_vq */
+
     /*
      * TMFs deferred to main loop BH. These fields are protected by
      * tmf_bh_lock.