virtio-scsi: Fix QEMU hang with vIOMMU and ATS
cover virtio-scsi: Fix QEMU hang with vIOMMU and ATS
The first patch describes the bug and the reproducer.
The VQ poll handler that is called by mistake within virtio_scsi_dataplane_stop enters a dead loop because it fails to detect an error state. Fix both sides of the problem: the handler should break out from the loop if no progress can be made due to virtio_error; the handler shouldn't be called in that situation in the first place.
Fam Zheng (2):
virtio: Return true from virtio_queue_empty if broken virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
hw/block/dataplane/virtio-blk.c | 2 ++ hw/scsi/virtio-scsi-dataplane.c | 2 ++ hw/virtio/virtio.c | 8 ++++++++ 3 files changed, 12 insertions(+)
Signature · 1 line
2.17.1
PATCH 1/2 virtio: Return true from virtio_queue_empty if broken
Both virtio-blk and virtio-scsi use virtio_queue_empty() as the loop condition in VQ handlers (virtio_blk_handle_vq, virtio_scsi_handle_cmd_vq). When a device is marked broken in virtqueue_pop, for example if a vIOMMU address translation failed, we want to break out of the loop.
This fixes a hanging problem when booting a CentOS 3.10.0-862.el7.x86_64 kernel with ATS enabled:
$ qemu-system-x86_64 \
... \
-device intel-iommu,intremap=on,caching-mode=on,eim=on,device-iotlb=on \
-device virtio-scsi-pci,iommu_platform=on,ats=on,id=scsi0,bus=pci.4,addr=0x0The dead loop happens immediately when the kernel boots and initializes the device, where virtio_scsi_data_plane_handle_cmd will not return:
Quoted 17 lines
...
#130x00005586602b7793invirtio_scsi_handle_cmd_vq#140x00005586602b8d66invirtio_scsi_data_plane_handle_cmd#150x00005586602ddab7invirtio_queue_notify_aio_vq#160x00005586602dfc9finvirtio_queue_host_notifier_aio_poll#170x00005586607885dainrun_poll_handlers_once#180x000055866078880eintry_poll_mode
#190x00005586607888ebinaio_poll
#200x0000558660784561inaio_wait_bh_oneshot
#210x00005586602b9582invirtio_scsi_dataplane_stop#220x00005586605a7110invirtio_bus_stop_ioeventfd#230x00005586605a9426invirtio_pci_stop_ioeventfd#240x00005586605ab808invirtio_pci_common_write#250x0000558660242396inmemory_region_write_accessor#260x00005586602425abinaccess_with_adjusted_size#270x0000558660245281inmemory_region_dispatch_write#280x00005586601e008einflatview_write_continue
Quoted 8 lines
#29
0x00005586601e01d8inflatview_write
#300x00005586601e04deinaddress_space_write
#310x00005586601e052finaddress_space_rw
#320x00005586602607f2inkvm_cpu_exec
#330x0000558660227148inqemu_kvm_cpu_thread_fn
#340x000055866078bde7inqemu_thread_start
#350x00007f5784906594instart_thread
#360x00007f5784639e6fin clone
With this patch, virtio_queue_empty will now return 1 as soon as the vdev is marked as broken, after a "virtio: zero sized buffers are not allowed" error.
To be consistent, update virtio_queue_empty_rcu as well.
--- hw/virtio/virtio.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/virtio/virtio.c +8 -0
@@ -358,6 +358,10 @@ int virtio_queue_ready(VirtQueue *vq)* Called within rcu_read_lock(). */ static int virtio_queue_empty_rcu (VirtQueue *vq) { +if (unlikely (vq->vdev->broken)) { +return 1 ; + } +if (unlikely (!vq->vring.avail)) {return 1 ; }
@@ -373,6 +377,10 @@ int virtio_queue_empty(VirtQueue *vq) {bool empty; +if (unlikely (vq->vdev->broken)) { +return 1 ; + } +if (unlikely (!vq->vring.avail)) {return 1 ; }
Signature · 1 line
2.17.1
PATCH 2/2 virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
In reply to Fam ZhengWe have this unwanted call stack:
Quoted 17 lines
...
#130x00005586602b7793invirtio_scsi_handle_cmd_vq#140x00005586602b8d66invirtio_scsi_data_plane_handle_cmd#150x00005586602ddab7invirtio_queue_notify_aio_vq#160x00005586602dfc9finvirtio_queue_host_notifier_aio_poll#170x00005586607885dainrun_poll_handlers_once#180x000055866078880eintry_poll_mode
#190x00005586607888ebinaio_poll
#200x0000558660784561inaio_wait_bh_oneshot
#210x00005586602b9582invirtio_scsi_dataplane_stop#220x00005586605a7110invirtio_bus_stop_ioeventfd#230x00005586605a9426invirtio_pci_stop_ioeventfd#240x00005586605ab808invirtio_pci_common_write#250x0000558660242396inmemory_region_write_accessor#260x00005586602425abinaccess_with_adjusted_size#270x0000558660245281inmemory_region_dispatch_write#280x00005586601e008einflatview_write_continue
Quoted 8 lines
#29
0x00005586601e01d8inflatview_write
#300x00005586601e04deinaddress_space_write
#310x00005586601e052finaddress_space_rw
#320x00005586602607f2inkvm_cpu_exec
#330x0000558660227148inqemu_kvm_cpu_thread_fn
#340x000055866078bde7inqemu_thread_start
#350x00007f5784906594instart_thread
#360x00007f5784639e6fin clone
Avoid it with the aio_disable_external/aio_enable_external pair, so that no vq poll handlers can be called in aio_wait_bh_oneshot.
--- hw/block/dataplane/virtio-blk.c | 2 ++ hw/scsi/virtio-scsi-dataplane.c | 2 ++ 2 files changed, 4 insertions(+)
hw/block/dataplane/virtio-blk.c +2 -0
@@ -279,7 +279,9 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)trace_virtio_blk_data_plane_stop (s);aio_context_acquire (s->ctx); +aio_disable_external (s->ctx);aio_wait_bh_oneshot (s->ctx, virtio_blk_data_plane_stop_bh, s); +aio_enable_external (s->ctx);/* Drain and switch bs back to the QEMU main loop */ blk_set_aio_context (s->conf->conf.blk,qemu_get_aio_context ());
hw/scsi/virtio-scsi-dataplane.c +2 -0
@@ -208,7 +208,9 @@ void virtio_scsi_dataplane_stop(VirtIODevice *vdev) s->dataplane_stopping = true;aio_context_acquire (s->ctx); +aio_disable_external (s->ctx);aio_wait_bh_oneshot (s->ctx, virtio_scsi_dataplane_stop_bh, s); +aio_enable_external (s->ctx);aio_context_release (s->ctx);blk_drain_all ();/* ensure there are no in-flight requests */
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 28 lines · Fam Zheng
We have this unwanted call stack:
Quoted 17 lines
...
#130x00005586602b7793invirtio_scsi_handle_cmd_vq#140x00005586602b8d66invirtio_scsi_data_plane_handle_cmd#150x00005586602ddab7invirtio_queue_notify_aio_vq#160x00005586602dfc9finvirtio_queue_host_notifier_aio_poll#170x00005586607885dainrun_poll_handlers_once#180x000055866078880eintry_poll_mode
#190x00005586607888ebinaio_poll
#200x0000558660784561inaio_wait_bh_oneshot
#210x00005586602b9582invirtio_scsi_dataplane_stop#220x00005586605a7110invirtio_bus_stop_ioeventfd#230x00005586605a9426invirtio_pci_stop_ioeventfd#240x00005586605ab808invirtio_pci_common_write#250x0000558660242396inmemory_region_write_accessor#260x00005586602425abinaccess_with_adjusted_size#270x0000558660245281inmemory_region_dispatch_write#280x00005586601e008einflatview_write_continueQuoted 8 lines
#29
0x00005586601e01d8inflatview_write
#300x00005586601e04deinaddress_space_write
#310x00005586601e052finaddress_space_rw
#320x00005586602607f2inkvm_cpu_exec
#330x0000558660227148inqemu_kvm_cpu_thread_fn
#340x000055866078bde7inqemu_thread_start
#350x00007f5784906594instart_thread
#360x00007f5784639e6fin clone
Quoted 2 lines
Avoid it with the aio_disable_external/aio_enable_external pair, so that no vq poll handlers can be called in
aio_wait_bh_oneshot.
I don't understand. We are in the vCPU thread, so not in the AioContext's home thread. Why is aio_wait_bh_oneshot polling rather than going through the aio_wait_bh path?
Thanks,
Paolo
Re: [Qemu-devel] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 29 lines · Paolo Bonzini
Quoted 28 lines · Fam Zheng
We have this unwanted call stack:
Quoted 25 lines
...
#130x00005586602b7793invirtio_scsi_handle_cmd_vq#140x00005586602b8d66invirtio_scsi_data_plane_handle_cmd#150x00005586602ddab7invirtio_queue_notify_aio_vq#160x00005586602dfc9finvirtio_queue_host_notifier_aio_poll#170x00005586607885dainrun_poll_handlers_once#180x000055866078880eintry_poll_mode
#190x00005586607888ebinaio_poll
#200x0000558660784561inaio_wait_bh_oneshot
#210x00005586602b9582invirtio_scsi_dataplane_stop#220x00005586605a7110invirtio_bus_stop_ioeventfd#230x00005586605a9426invirtio_pci_stop_ioeventfd#240x00005586605ab808invirtio_pci_common_write#250x0000558660242396inmemory_region_write_accessor#260x00005586602425abinaccess_with_adjusted_size#270x0000558660245281inmemory_region_dispatch_write#280x00005586601e008einflatview_write_continue#290x00005586601e01d8inflatview_write
#300x00005586601e04deinaddress_space_write
#310x00005586601e052finaddress_space_rw
#320x00005586602607f2inkvm_cpu_exec
#330x0000558660227148inqemu_kvm_cpu_thread_fn#340x000055866078bde7inqemu_thread_start
#350x00007f5784906594instart_thread
#360x00007f5784639e6fin clone
Quoted 6 lines
Quoted 2 lines
Avoid it with the aio_disable_external/aio_enable_external pair, so that no vq poll handlers can be called in
aio_wait_bh_oneshot.I don't understand. We are in the vCPU thread, so not in the AioContext's home thread. Why is
aio_wait_bh_oneshotpolling rather than going through theaio_wait_bhpath?
What do you mean by 'aio_wait_bh path'? Here is aio_wait_bh_oneshot:
void aio_wait_bh_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
{
AioWaitBHData data = {
.cb = cb,
.opaque = opaque,
};
assert(qemu_get_current_aio_context() == qemu_get_aio_context());
aio_bh_schedule_oneshot(ctx, aio_wait_bh, &data);
AIO_WAIT_WHILE(&data.wait, ctx, !data.done);
}ctx is qemu_aio_context here, so there's no interaction with IOThread. This is the full backtrace:
https://paste.ubuntu.com/p/Dm7zGzmmRG/
Fam
Re: [Qemu-devel] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 30 lines · Fam Zheng
Quoted 29 lines · Paolo Bonzini
Quoted 28 lines · Fam Zheng
We have this unwanted call stack:
Quoted 25 lines
...
#130x00005586602b7793invirtio_scsi_handle_cmd_vq#140x00005586602b8d66invirtio_scsi_data_plane_handle_cmd#150x00005586602ddab7invirtio_queue_notify_aio_vq#160x00005586602dfc9finvirtio_queue_host_notifier_aio_poll#170x00005586607885dainrun_poll_handlers_once#180x000055866078880eintry_poll_mode
#190x00005586607888ebinaio_poll
#200x0000558660784561inaio_wait_bh_oneshot
#210x00005586602b9582invirtio_scsi_dataplane_stop#220x00005586605a7110invirtio_bus_stop_ioeventfd#230x00005586605a9426invirtio_pci_stop_ioeventfd#240x00005586605ab808invirtio_pci_common_write#250x0000558660242396inmemory_region_write_accessor#260x00005586602425abinaccess_with_adjusted_size#270x0000558660245281inmemory_region_dispatch_write#280x00005586601e008einflatview_write_continue#290x00005586601e01d8inflatview_write
#300x00005586601e04deinaddress_space_write
#310x00005586601e052finaddress_space_rw
#320x00005586602607f2inkvm_cpu_exec
#330x0000558660227148inqemu_kvm_cpu_thread_fn#340x000055866078bde7inqemu_thread_start
#350x00007f5784906594instart_thread
#360x00007f5784639e6fin clone
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Avoid it with the aio_disable_external/aio_enable_external pair, so that no vq poll handlers can be called in
aio_wait_bh_oneshot.I don't understand. We are in the vCPU thread, so not in the AioContext's home thread. Why is
aio_wait_bh_oneshotpolling rather than going through theaio_wait_bhpath?What do you mean by '
aio_wait_bhpath'? Here isaio_wait_bh_oneshot:
Sorry, I meant the "atomic_inc(&wait_->num_waiters);" path. But if this backtrace is obtained without dataplane, that's the answer I was seeking.
Quoted 13 lines
void
aio_wait_bh_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque){ AioWaitBHData data = { .cb = cb, .opaque = opaque, }; assert(qemu_get_current_aio_context() == qemu_get_aio_context()); aio_bh_schedule_oneshot(ctx, aio_wait_bh, &data); AIO_WAIT_WHILE(&data.wait, ctx, !data.done); }
Quoted 1 line
ctx is
qemu_aio_contexthere, so there's no interaction with IOThread.
In this case, it should be okay to have the reentrancy, what is the bug that this patch is fixing?
Thanks,
Paolo
Re: [Qemu-devel] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 52 lines · Paolo Bonzini
Quoted 30 lines · Fam Zheng
Quoted 29 lines · Paolo Bonzini
Quoted 28 lines · Fam Zheng
We have this unwanted call stack:
Quoted 25 lines
...
#130x00005586602b7793invirtio_scsi_handle_cmd_vq#140x00005586602b8d66invirtio_scsi_data_plane_handle_cmd#150x00005586602ddab7invirtio_queue_notify_aio_vq#160x00005586602dfc9finvirtio_queue_host_notifier_aio_poll#170x00005586607885dainrun_poll_handlers_once#180x000055866078880eintry_poll_mode
#190x00005586607888ebinaio_poll
#200x0000558660784561inaio_wait_bh_oneshot
#210x00005586602b9582invirtio_scsi_dataplane_stop#220x00005586605a7110invirtio_bus_stop_ioeventfd#230x00005586605a9426invirtio_pci_stop_ioeventfd#240x00005586605ab808invirtio_pci_common_write#250x0000558660242396inmemory_region_write_accessor#260x00005586602425abinaccess_with_adjusted_size#270x0000558660245281inmemory_region_dispatch_write#280x00005586601e008einflatview_write_continue#290x00005586601e01d8inflatview_write
#300x00005586601e04deinaddress_space_write
#310x00005586601e052finaddress_space_rw
#320x00005586602607f2inkvm_cpu_exec
#330x0000558660227148inqemu_kvm_cpu_thread_fn#340x000055866078bde7inqemu_thread_start
#350x00007f5784906594instart_thread
#360x00007f5784639e6fin cloneQuoted 8 lines
Quoted 6 lines
Quoted 2 lines
Avoid it with the aio_disable_external/aio_enable_external pair, so that no vq poll handlers can be called in
aio_wait_bh_oneshot.I don't understand. We are in the vCPU thread, so not in the AioContext's home thread. Why is
aio_wait_bh_oneshotpolling rather than going through theaio_wait_bhpath?What do you mean by '
aio_wait_bhpath'? Here isaio_wait_bh_oneshot:Sorry, I meant the "
atomic_inc(&wait_->num_waiters);" path. But if this backtrace is obtained without dataplane, that's the answer I was seeking.Quoted 9 lines
void
aio_wait_bh_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque){ AioWaitBHData data = { .cb = cb, .opaque = opaque, }; assert(qemu_get_current_aio_context() == qemu_get_aio_context());
Quoted 8 lines
Quoted 5 lines
aio_bh_schedule_oneshot(ctx, aio_wait_bh, &data); AIO_WAIT_WHILE(&data.wait, ctx, !data.done); }ctx is
qemu_aio_contexthere, so there's no interaction with IOThread.In this case, it should be okay to have the reentrancy, what is the bug that this patch is fixing?
The same symptom as in the previous patch: virtio_scsi_handle_cmd_vq hangs. The reason it hangs is fixed by the previous patch, but I don't think it should be invoked as we're in the middle of virtio_scsi_dataplane_stop(). Applying either one of the two patches avoids the problem, but this one is more superficial. What do you think?
Fam
Re: [Qemu-devel] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 9 lines · Fam Zheng
Quoted 4 lines
Quoted 2 lines
ctx is
qemu_aio_contexthere, so there's no interaction with IOThread.In this case, it should be okay to have the reentrancy, what is the bug that this patch is fixing?
The same symptom as in the previous patch:
virtio_scsi_handle_cmd_vqhangs. The reason it hangs is fixed by the previous patch, but I don't think it should be invoked as we're in the middle ofvirtio_scsi_dataplane_stop(). Applying either one of the two patches avoids the problem, but this one is more superficial. What do you think?
I think it's okay if it is invoked. The sequence is first you stop the vq, then you drain the BlockBackends, then you switch AioContext. All that matters is the outcome when virtio_scsi_dataplane_stop returns.
Paolo
Re: [Qemu-devel] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Fam Zheng
Quoted 4 lines
Quoted 2 lines
ctx is
qemu_aio_contexthere, so there's no interaction with IOThread.In this case, it should be okay to have the reentrancy, what is the bug that this patch is fixing?
The same symptom as in the previous patch:
virtio_scsi_handle_cmd_vqhangs. The reason it hangs is fixed by the previous patch, but I don't think it should be invoked as we're in the middle ofvirtio_scsi_dataplane_stop(). Applying either one of the two patches avoids the problem, but this one is more superficial. What do you think?
Quoted 3 lines
I think it's okay if it is invoked. The sequence is first you stop the vq, then you drain the BlockBackends, then you switch AioContext. All that matters is the outcome when
virtio_scsi_dataplane_stopreturns.
Yes, but together with vIOMMU, it also effectively leads to a virtio_error(), which is not clean. QEMU stderr when this call happens (with patch 1 but not this patch):
2018-09-12T11:48:10.193023Z qemu-system-x86_64: vtd_iommu_translate: detected translation failure (dev=02:00:00, iova=0x0) 2018-09-12T11:48:10.193044Z qemu-system-x86_64: New fault is not recorded due to compression of faults 2018-09-12T11:48:10.193061Z qemu-system-x86_64: virtio: zero sized buffers are not allowed
Fam
Re: [Qemu-devel] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 10 lines · Fam Zheng
Quoted 3 lines
I think it's okay if it is invoked. The sequence is first you stop the vq, then you drain the BlockBackends, then you switch AioContext. All that matters is the outcome when
virtio_scsi_dataplane_stopreturns.Yes, but together with vIOMMU, it also effectively leads to a
virtio_error(), which is not clean. QEMU stderr when this call happens (with patch 1 but not this patch):2018-09-12T11:48:10.193023Z qemu-system-x86_64: vtd_iommu_translate: detected translation failure (dev=02:00:00, iova=0x0) 2018-09-12T11:48:10.193044Z qemu-system-x86_64: New fault is not recorded due to compression of faults 2018-09-12T11:48:10.193061Z qemu-system-x86_64: virtio: zero sized buffers are not allowed
But with iothread, virtio_scsi_dataplane_stop runs in another thread than the iothread; in that case you still have a race where the iothread can process the vq before aio_disable_external and print the error.
IIUC the guest has cleared the IOMMU page tables _before_ clearing the DRIVER_OK bit in the status field. Could this be a guest bug?
Paolo
Re: [Qemu-devel] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 12 lines · Paolo Bonzini
Quoted 10 lines · Fam Zheng
Quoted 3 lines
I think it's okay if it is invoked. The sequence is first you stop the vq, then you drain the BlockBackends, then you switch AioContext. All that matters is the outcome when
virtio_scsi_dataplane_stopreturns.Yes, but together with vIOMMU, it also effectively leads to a
virtio_error(), which is not clean. QEMU stderr when this call happens (with patch 1 but not this patch):2018-09-12T11:48:10.193023Z qemu-system-x86_64: vtd_iommu_translate: detected translation failure (dev=02:00:00, iova=0x0) 2018-09-12T11:48:10.193044Z qemu-system-x86_64: New fault is not recorded due to compression of faults 2018-09-12T11:48:10.193061Z qemu-system-x86_64: virtio: zero sized buffers are not allowed
Quoted 7 lines
But with iothread,
virtio_scsi_dataplane_stopruns in another thread than the iothread; in that case you still have a race where the iothread can process the vq beforeaio_disable_externaland print the error.IIUC the guest has cleared the IOMMU page tables _before_ clearing the
DRIVER_OKbit in the status field. Could this be a guest bug?
I'm not sure if it is a bug or not. I think what happens is the device is left enabled by Seabios, and then reset by kernel.
Fam
Re: [Qemu-devel] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 17 lines · Fam Zheng
Quoted 16 lines · Paolo Bonzini
Quoted 10 lines · Fam Zheng
Quoted 3 lines
I think it's okay if it is invoked. The sequence is first you stop the vq, then you drain the BlockBackends, then you switch AioContext. All that matters is the outcome when
virtio_scsi_dataplane_stopreturns.Yes, but together with vIOMMU, it also effectively leads to a
virtio_error(), which is not clean. QEMU stderr when this call happens (with patch 1 but not this patch):2018-09-12T11:48:10.193023Z qemu-system-x86_64: vtd_iommu_translate: detected translation failure (dev=02:00:00, iova=0x0) 2018-09-12T11:48:10.193044Z qemu-system-x86_64: New fault is not recorded due to compression of faults 2018-09-12T11:48:10.193061Z qemu-system-x86_64: virtio: zero sized buffers are not allowedBut with iothread,
virtio_scsi_dataplane_stopruns in another thread than the iothread; in that case you still have a race where the iothread can process the vq beforeaio_disable_externaland print the error.
Quoted 5 lines
Quoted 2 lines
IIUC the guest has cleared the IOMMU page tables _before_ clearing the
DRIVER_OKbit in the status field. Could this be a guest bug?I'm not sure if it is a bug or not. I think what happens is the device is left enabled by Seabios, and then reset by kernel.
That makes sense, though I'm not sure why QEMU needs to process a request long after SeaBIOS has left control to Linux. Maybe it's just that the messages should not go on QEMU stderr, and rather trace-point should be enough.
Paolo
Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Fam Zheng
Quoted 18 lines · Paolo Bonzini
Quoted 10 lines · Fam Zheng
Quoted 3 lines
I think it's okay if it is invoked. The sequence is first you stop the vq, then you drain the BlockBackends, then you switch AioContext. All that matters is the outcome when
virtio_scsi_dataplane_stopreturns.Yes, but together with vIOMMU, it also effectively leads to a
virtio_error(), which is not clean. QEMU stderr when this call happens (with patch 1 but not this patch):2018-09-12T11:48:10.193023Z qemu-system-x86_64: vtd_iommu_translate: detected translation failure (dev=02:00:00, iova=0x0) 2018-09-12T11:48:10.193044Z qemu-system-x86_64: New fault is not recorded due to compression of faults 2018-09-12T11:48:10.193061Z qemu-system-x86_64: virtio: zero sized buffers are not allowedBut with iothread,
virtio_scsi_dataplane_stopruns in another thread than the iothread; in that case you still have a race where the iothread can process the vq beforeaio_disable_externaland print the error.IIUC the guest has cleared the IOMMU page tables _before_ clearing the
DRIVER_OKbit in the status field. Could this be a guest bug?
Quoted 7 lines
Quoted 2 lines
I'm not sure if it is a bug or not. I think what happens is the device is left enabled by Seabios, and then reset by kernel.
That makes sense, though I'm not sure why QEMU needs to process a request long after SeaBIOS has left control to Linux. Maybe it's just that the messages should not go on QEMU stderr, and rather trace-point should be enough.
Aha, it's not that QEMU needs to poll, it's just that polling mode is enabled, and it decides to do one last iteration. In general the virtio spec allows the hardware to poll whenever it wants, hence:
1) I'm not sure that translation failures should mark the device as broken---definitely not when doing polling, possibly not even in response to the guest "kicking" the virtqueue. Alex, does the PCI spec say anything about this?
2) translation faliures should definitely not print messages to stderr.
Thanks,
Paolo
Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 30 lines · On Thu, 13 Sep 2018 12:04:34 +0200 Paolo Bonzini <[email protected]> wrote:
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Fam Zheng
Quoted 18 lines · Paolo Bonzini
Quoted 10 lines · Fam Zheng
Quoted 3 lines
I think it's okay if it is invoked. The sequence is first you stop the vq, then you drain the BlockBackends, then you switch AioContext. All that matters is the outcome when
virtio_scsi_dataplane_stopreturns.Yes, but together with vIOMMU, it also effectively leads to a
virtio_error(), which is not clean. QEMU stderr when this call happens (with patch 1 but not this patch):2018-09-12T11:48:10.193023Z qemu-system-x86_64: vtd_iommu_translate: detected translation failure (dev=02:00:00, iova=0x0) 2018-09-12T11:48:10.193044Z qemu-system-x86_64: New fault is not recorded due to compression of faults 2018-09-12T11:48:10.193061Z qemu-system-x86_64: virtio: zero sized buffers are not allowedBut with iothread,
virtio_scsi_dataplane_stopruns in another thread than the iothread; in that case you still have a race where the iothread can process the vq beforeaio_disable_externaland print the error.IIUC the guest has cleared the IOMMU page tables _before_ clearing the
DRIVER_OKbit in the status field. Could this be a guest bug?Quoted 7 lines
Quoted 2 lines
I'm not sure if it is a bug or not. I think what happens is the device is left enabled by Seabios, and then reset by kernel.
That makes sense, though I'm not sure why QEMU needs to process a request long after SeaBIOS has left control to Linux. Maybe it's just that the messages should not go on QEMU stderr, and rather trace-point should be enough.
Quoted 8 lines
Aha, it's not that QEMU needs to poll, it's just that polling mode is enabled, and it decides to do one last iteration. In general the virtio spec allows the hardware to poll whenever it wants, hence:
1) I'm not sure that translation failures should mark the device as broken---definitely not when doing polling, possibly not even in response to the guest "kicking" the virtqueue. Alex, does the PCI spec say anything about this?
AFAIK the PCI spec doesn't define anything about the IOMMU or response to translation failures. Depending on whether it's a read or write, the device might see an unsupported request or not even be aware of the error. It's really a platform RAS question whether to have any more significant response, most don't, but at least one tends to consider IOMMU faults to be a data integrity issue worth bring the system down. We've struggled with handling ongoing DMA generating IOMMU faults during kexec for a long time, so any sort of marking a device broken for a fault should be thoroughly considered, especially when a device could be assigned to a user who can trivially trigger a fault.
Quoted 1 line
2) translation faliures should definitely not print messages to stderr.
Yep, easy DoS vector for a malicious guest, or malicious userspace driver within the guest. Thanks,
Alex
Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] virtio-scsi/virtio-blk: Disable poll handlers when stopping vq handler
Quoted 53 lines · Alex Williamson
Quoted 30 lines · On Thu, 13 Sep 2018 12:04:34 +0200 Paolo Bonzini <[email protected]> wrote:
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Fam Zheng
Quoted 18 lines · Paolo Bonzini
Quoted 10 lines · Fam Zheng
Quoted 3 lines
I think it's okay if it is invoked. The sequence is first you stop the vq, then you drain the BlockBackends, then you switch AioContext. All that matters is the outcome when
virtio_scsi_dataplane_stopreturns.Yes, but together with vIOMMU, it also effectively leads to a
virtio_error(), which is not clean. QEMU stderr when this call happens (with patch 1 but not this patch):2018-09-12T11:48:10.193023Z qemu-system-x86_64: vtd_iommu_translate: detected translation failure (dev=02:00:00, iova=0x0) 2018-09-12T11:48:10.193044Z qemu-system-x86_64: New fault is not recorded due to compression of faults 2018-09-12T11:48:10.193061Z qemu-system-x86_64: virtio: zero sized buffers are not allowedBut with iothread,
virtio_scsi_dataplane_stopruns in another thread than the iothread; in that case you still have a race where the iothread can process the vq beforeaio_disable_externaland print the error.IIUC the guest has cleared the IOMMU page tables _before_ clearing the
DRIVER_OKbit in the status field. Could this be a guest bug?Quoted 7 lines
Quoted 2 lines
I'm not sure if it is a bug or not. I think what happens is the device is left enabled by Seabios, and then reset by kernel.
That makes sense, though I'm not sure why QEMU needs to process a request long after SeaBIOS has left control to Linux. Maybe it's just that the messages should not go on QEMU stderr, and rather trace-point should be enough.
Quoted 8 lines
Aha, it's not that QEMU needs to poll, it's just that polling mode is enabled, and it decides to do one last iteration. In general the virtio spec allows the hardware to poll whenever it wants, hence:
1) I'm not sure that translation failures should mark the device as broken---definitely not when doing polling, possibly not even in response to the guest "kicking" the virtqueue. Alex, does the PCI spec say anything about this?
AFAIK the PCI spec doesn't define anything about the IOMMU or response to translation failures. Depending on whether it's a read or write, the device might see an unsupported request or not even be aware of the error. It's really a platform RAS question whether to have any more significant response, most don't, but at least one tends to consider IOMMU faults to be a data integrity issue worth bring the system down. We've struggled with handling ongoing DMA generating IOMMU faults during kexec for a long time, so any sort of marking a device broken for a fault should be thoroughly considered, especially when a device could be assigned to a user who can trivially trigger a fault.
Quoted 4 lines
Quoted 1 line
2) translation faliures should definitely not print messages to stderr.
Yep, easy DoS vector for a malicious guest, or malicious userspace driver within the guest. Thanks,
Note that it's using error_report_once() upstream so it'll only print once for the whole lifecycle of QEMU process, and it's still a tracepoint downstream so no error will be dumped by default. So AFAIU it's not a DoS target for either.
I would consider it a good hint for strange bugs since AFAIU DMA error should never exist on well-behaved guests. However I'll be fine too to post a patch to make it an explicit tracepoint again if any of us would still like it to go away.
Thanks,
Signature · 1 line
Peter Xu