From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Fam Zheng" <fam@euphon.net>,
"Stefan Hajnoczi" <stefanha@redhat.com>
Subject: [PATCH v2 0/3] virtio-scsi: fix SCSIDevice hot unplug with IOThread
Date: Fri, 10 Feb 2023 09:32:35 -0500 [thread overview]
Message-ID: <20230210143238.524357-1-stefanha@redhat.com> (raw)
Unplugging SCSIDevices when virtio-scsi is using an IOThread suffers from race
conditions:
- scsi_device_purge_requests() is called from the IOThread in TMF emulation.
This is unsafe, it should only be called from the BQL.
- SCSIRequest->aiocb is not protected by a lock, so there are races between the
main loop thread and the IOThread when scsi_device_purge_requests() runs in
the main loop thread.
- DMAAIOCB->acb is not protected by a lock, so there are races in the DMA
helpers code when cancelling a request from the main loop thread.
These fixes solve assertion failures during SCSIDevice hot unplug in
virtio-scsi with IOThread. Expanding the use of the AioContext lock isn't great
since we're in the midst of trying to remove it. However, I think this solution
is appropriate so that stable trees or distros can backport the fix without
depending on QEMU multi-queue block layer refactoring.
Special thanks to Qing Wang, who helped me iterate these patches because I
couldn't reproduce the assertion failures myself.
Stefan Hajnoczi (3):
scsi: protect req->aiocb with AioContext lock
dma-helpers: prevent dma_blk_cb() vs dma_aio_cancel() race
virtio-scsi: reset SCSI devices from main loop thread
include/hw/virtio/virtio-scsi.h | 11 ++-
hw/scsi/scsi-disk.c | 23 +++--
hw/scsi/scsi-generic.c | 11 ++-
hw/scsi/virtio-scsi.c | 169 +++++++++++++++++++++++++-------
softmmu/dma-helpers.c | 12 ++-
5 files changed, 171 insertions(+), 55 deletions(-)
--
2.39.1
next reply other threads:[~2023-02-10 14:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-10 14:32 Stefan Hajnoczi [this message]
2023-02-10 14:32 ` [PATCH v2 1/3] scsi: protect req->aiocb with AioContext lock Stefan Hajnoczi
2023-02-15 18:17 ` Eric Blake
2023-02-16 12:34 ` Kevin Wolf
2023-02-10 14:32 ` [PATCH v2 2/3] dma-helpers: prevent dma_blk_cb() vs dma_aio_cancel() race Stefan Hajnoczi
2023-02-15 18:19 ` Eric Blake
2023-02-16 15:27 ` Kevin Wolf
2023-02-16 21:27 ` Stefan Hajnoczi
2023-02-10 14:32 ` [PATCH v2 3/3] virtio-scsi: reset SCSI devices from main loop thread Stefan Hajnoczi
2023-02-15 18:27 ` Eric Blake
2023-02-17 10:22 ` Kevin Wolf
[not found] ` <Y/Tz+qw7thcwO+G3@fedora>
2023-02-23 15:03 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230210143238.524357-1-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=david@redhat.com \
--cc=fam@euphon.net \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).