[PATCH 0/4] scsi: eliminate AioContext lock

Stefan Hajnoczi posted 4 patches 1 year ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231123194931.171598-1-stefanha@redhat.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>, "Michael S. Tsirkin" <mst@redhat.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
There is a newer version of this series
include/hw/scsi/scsi.h          |   7 +-
hw/scsi/scsi-bus.c              | 174 ++++++++++++++++++++++----------
hw/scsi/scsi-disk.c             |  23 -----
hw/scsi/scsi-generic.c          |  20 +---
hw/scsi/virtio-scsi-dataplane.c |   8 +-
system/dma-helpers.c            |   7 +-
6 files changed, 130 insertions(+), 109 deletions(-)
[PATCH 0/4] scsi: eliminate AioContext lock
Posted by Stefan Hajnoczi 1 year ago
The SCSI subsystem uses the AioContext lock to protect internal state. This is
necessary because the main loop and the IOThread can access SCSI state in
parallel. This inter-thread access happens during scsi_device_purge_requests()
and scsi_dma_restart_cb().

This patch series modifies the code so SCSI state is only accessed from the
IOThread that is executing requests. Once this has been achieved the AioContext
lock is no longer necessary.

Note that a few aio_context_acquire()/aio_context_release() calls still remain
after this series. They surround API calls that invoke AIO_WAIT_WHILE() and
therefore still rely on the AioContext lock for now.

Stefan Hajnoczi (4):
  scsi: only access SCSIDevice->requests from one thread
  virtio-scsi: don't lock AioContext around
    virtio_queue_aio_attach_host_notifier()
  scsi: don't lock AioContext in I/O code path
  dma-helpers: don't lock AioContext in dma_blk_cb()

 include/hw/scsi/scsi.h          |   7 +-
 hw/scsi/scsi-bus.c              | 174 ++++++++++++++++++++++----------
 hw/scsi/scsi-disk.c             |  23 -----
 hw/scsi/scsi-generic.c          |  20 +---
 hw/scsi/virtio-scsi-dataplane.c |   8 +-
 system/dma-helpers.c            |   7 +-
 6 files changed, 130 insertions(+), 109 deletions(-)

-- 
2.42.0
Re: [PATCH 0/4] scsi: eliminate AioContext lock
Posted by Stefan Hajnoczi 1 year ago
On Thu, Nov 23, 2023 at 02:49:27PM -0500, Stefan Hajnoczi wrote:
> The SCSI subsystem uses the AioContext lock to protect internal state. This is
> necessary because the main loop and the IOThread can access SCSI state in
> parallel. This inter-thread access happens during scsi_device_purge_requests()
> and scsi_dma_restart_cb().
> 
> This patch series modifies the code so SCSI state is only accessed from the
> IOThread that is executing requests. Once this has been achieved the AioContext
> lock is no longer necessary.
> 
> Note that a few aio_context_acquire()/aio_context_release() calls still remain
> after this series. They surround API calls that invoke AIO_WAIT_WHILE() and
> therefore still rely on the AioContext lock for now.
> 
> Stefan Hajnoczi (4):
>   scsi: only access SCSIDevice->requests from one thread
>   virtio-scsi: don't lock AioContext around
>     virtio_queue_aio_attach_host_notifier()
>   scsi: don't lock AioContext in I/O code path
>   dma-helpers: don't lock AioContext in dma_blk_cb()
> 
>  include/hw/scsi/scsi.h          |   7 +-
>  hw/scsi/scsi-bus.c              | 174 ++++++++++++++++++++++----------
>  hw/scsi/scsi-disk.c             |  23 -----
>  hw/scsi/scsi-generic.c          |  20 +---
>  hw/scsi/virtio-scsi-dataplane.c |   8 +-
>  system/dma-helpers.c            |   7 +-
>  6 files changed, 130 insertions(+), 109 deletions(-)

CCing Kevin and qemu-block

> 
> -- 
> 2.42.0
>