From: Stefan Hajnoczi <stefanha@redhat.com>
To: Hannes Reinecke <hare@suse.de>
Cc: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>,
mst@redhat.com, jasowangio@gmail.com, mkp@kernel.org,
James.Bottomley@hansenpartnership.com, pbonzini@redhat.com,
eperezma@redhat.com, virtualization@lists.linux.dev,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
sashiko-bot@kernel.org, kwolf@redhat.com
Subject: Re: [PATCH v2] scsi: virtio_scsi: implement eh_host_reset_handler
Date: Tue, 3 Nov 2026 16:43:13 -0500 [thread overview]
Message-ID: <20261103214313.GA2159241@shajnocz.csb> (raw)
In-Reply-To: <bdef8300-8570-4103-8c8b-cb978c88eb81@suse.de>
On Tue, Nov 03, 2026 at 05:26:44PM +0100, Hannes Reinecke wrote:
> On 11/3/26 2:51 PM, Stefan Hajnoczi wrote:
> > On Tue, Nov 03, 2026 at 08:27:52AM +0100, Hannes Reinecke wrote:
> > > On 11/2/26 9:06 PM, Stefan Hajnoczi wrote:
> > > > On Mon, Sep 14, 2026 at 08:31:44PM +0700, Nguyen Ngoc Thang wrote:
> > > > > Once virtscsi_eh_timed_out() lets SCSI EH run on an unresponsive host,
> > > > > abort and device reset both fail the same way (same dead ctrl vq), and
> > > > > since virtio_scsi implements neither target nor bus reset, EH falls
> > > > > through to scsi_eh_offline_sdevs(), which frees the stuck commands' DMA
> > > > > buffers without any guarantee the device has actually stopped touching
> > > > > them. If bus mastering (or whatever broke the transport) comes back
> > > > > later, the device can still write into memory the kernel has already
> > > > > reused.
> > > > >
> > > > > Add a real eh_host_reset_handler instead. virtio_reset_device() is the
> > > > > guarantee scsi_eh_offline_sdevs() was missing: once it returns, the
> > > > > device will not touch guest memory again, so it is safe to hand
> > > > > outstanding commands' buffers back. Reuse virtscsi_remove_vqs() +
> > > > > virtscsi_init() -- the exact sequence already used across
> > > > > suspend/resume -- to tear the virtqueues down and rebuild them.
> > > > >
> > > > > Verified with a QEMU virtio-scsi repro (PCI_COMMAND_MASTER cleared
> > > > > mid-write): EH now runs abort -> device reset -> host reset -> abort ->
> > > > > device reset -> host reset -> offline, then dd's stuck fsync returns
> > > > > EIO and D-state drains to 0, in ~244s total. No task remains
> > > > > uninterruptibly blocked.
> > > >
> > > > By the way, there is a known limitation in the QEMU virtio-scsi
> > > > implementation where some reset-related operations are implemented
> > > > synchronously (can block vCPUs and QEMU activity while waiting for I/O
> > > > to drain in some situations) instead of asynchronously. Recently there
> > > > has been work in QEMU to make VIRTIO device reset asynchronous, for
> > > > example, but it needs to be implemented on a per-device basis and
> > > > virtio-scsi hasn't taken advantage of it yet.
> > > >
> > > > Please let me know if you'd like to discuss or contribute. It's
> > > > something that is on my radar but not until 2027.
> > > >
> > > > >
> > > > > Suggested-by: Hannes Reinecke <hare@suse.de>
> > > > > Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
> > > > > ---
> > > > > v1 -> v2: implemented eh_host_reset_handler as suggested by Hannes
> > > > > Reinecke in review of the original RFC, instead of relying solely on
> > > > > the EH loop falling through to offline.
> > > > > ---
> > > > > drivers/scsi/virtio_scsi.c | 24 ++++++++++++++++++++++++
> > > > > 1 file changed, 24 insertions(+)
> > > > >
> > > > > diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
> > > > > index b4f20c487718..9698f4f91cc6 100644
> > > > > --- a/drivers/scsi/virtio_scsi.c
> > > > > +++ b/drivers/scsi/virtio_scsi.c
> > > > > @@ -833,6 +833,8 @@ static enum scsi_timeout_action virtscsi_eh_timed_out(struct scsi_cmnd *scmnd)
> > > > > return SCSI_EH_NOT_HANDLED;
> > > > > }
> > > > > +static int virtscsi_host_reset(struct scsi_cmnd *sc);
> > > > > +
> > > > > static const struct scsi_host_template virtscsi_host_template = {
> > > > > .module = THIS_MODULE,
> > > > > .name = "Virtio SCSI HBA",
> > > > > @@ -846,6 +848,7 @@ static const struct scsi_host_template virtscsi_host_template = {
> > > > > .eh_abort_handler = virtscsi_abort,
> > > > > .eh_device_reset_handler = virtscsi_device_reset,
> > > > > .eh_timed_out = virtscsi_eh_timed_out,
> > > > > + .eh_host_reset_handler = virtscsi_host_reset,
> > > > > .sdev_init = virtscsi_device_alloc,
> > > > > .dma_boundary = UINT_MAX,
> > > > > @@ -947,6 +950,27 @@ static int virtscsi_init(struct virtio_device *vdev,
> > > > > return err;
> > > > > }
> > > > > +/*
> > > > > + * No bus/target reset in virtio-scsi, so EH lands here after device
> > > >
> > > > The choice to use the VIRTIO device reset in virtscsi_host_reset() looks
> > > > good to me, but I would like clarification on this comment. virtio-scsi
> > > > does have I_T_NEXUS_RESET and I believe this is the modern equivalent to
> > > > the pre-SCSI-6 TARGET RESET. Is it really the case that virtio-scsi
> > > > doesn't have target reset? And do you want to go ahead and implement
> > > > .eh_target_reset_handler() using I_T_NEXUS_RESET?
> > > >
> > > Would probably not a bad idea to use I_T_NEXUS_RESET here.
> > > Not sure what it does internally, though; _is_ there a nexus
> > > to reset?
> >
> > Whether there is any benefit to I_T_NEXUS_RESET may depend on the device
> > implementation. In QEMU:
> > - LOGICAL_UNIT_RESET resets just 1 LUN
> > - I_T_NEXUS_RESET resets all LUNs
> > - VIRTIO device reset also resets the HBA itself
> >
> > In practice QEMU's I_T_NEXUS_RESET is unlikely to fix things if
> > LOGICAL_UNIT_RESET wasn't sufficient. Maybe it will help on other device
> > implementations though.
> >
> > I think the Linux driver mapping should be:
> > - .eh_device_reset_handler() -> LOGICAL_UNIT_RESET
> > - .eh_target_reset_handler() -> I_T_NEXUS_RESET
> > - .eh_host_reset_handler() -> VIRTIO device reset
> >
> I guess 'target_reset' is pretty much pointless for modern setups.
> If lun reset doesn't work it's pretty much guaranteed that target_reset
> won't help, either.
> (Unless you are on SAS, then it might, as I_T nexus reset actually
> resets the SAS link and such does something useful).
> Problem is that in most cases LUN reset fails as the _communication_
> to the LUN is interrupted, and hence sending another TMF across the
> same communication channel won't help, either.
> For virtio that would mean that we'd have to reset the virtio queues;
> can we even do that in a meaningful fashion?
The virtqueues can only really be reset by VIRTIO device reset
(.eh_host_reset_handler()).
Stefan
next prev parent reply other threads:[~2026-11-03 21:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260911163509.684191F000FF@smtp.kernel.org>
2026-09-11 16:44 ` [RFC PATCH] scsi: virtio_scsi: bound EH timer resets to avoid unkillable hang Nguyen Ngoc Thang
2026-09-14 9:17 ` Hannes Reinecke
2026-09-14 13:31 ` [PATCH v2] scsi: virtio_scsi: implement eh_host_reset_handler Nguyen Ngoc Thang
2026-11-02 11:48 ` Michael S. Tsirkin
2026-11-02 20:06 ` Stefan Hajnoczi
2026-11-03 7:27 ` Hannes Reinecke
2026-11-03 13:51 ` Stefan Hajnoczi
2026-11-03 16:26 ` Hannes Reinecke
2026-11-03 21:43 ` Stefan Hajnoczi [this message]
2026-09-14 13:36 ` [RFC PATCH] scsi: virtio_scsi: bound EH timer resets to avoid unkillable hang Nguyen Ngoc Thang
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=20261103214313.GA2159241@shajnocz.csb \
--to=stefanha@redhat.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=eperezma@redhat.com \
--cc=hare@suse.de \
--cc=jasowangio@gmail.com \
--cc=kwolf@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=mst@redhat.com \
--cc=ngocthang2710.1999@gmail.com \
--cc=pbonzini@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=virtualization@lists.linux.dev \
/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
all inboxes | Powered by JetHome®