Blame SOURCES/kvm-virtio-Return-true-from-virtio_queue_empty-if-broken.patch

016a62
From 5bcbdfefff3209a194168dbe772c7e2f45d248f7 Mon Sep 17 00:00:00 2001
016a62
From: Maxim Levitsky <mlevitsk@redhat.com>
016a62
Date: Sun, 22 Dec 2019 11:02:07 +0100
016a62
Subject: [PATCH 2/7] virtio: Return true from virtio_queue_empty if broken
016a62
016a62
RH-Author: Maxim Levitsky <mlevitsk@redhat.com>
016a62
Message-id: <20191222110207.21384-3-mlevitsk@redhat.com>
016a62
Patchwork-id: 93208
016a62
O-Subject: [RHEL-8.2.0 qemu-kvm PATCH 2/2] virtio: Return true from virtio_queue_empty if broken
016a62
Bugzilla: 1769613
016a62
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
016a62
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
016a62
RH-Acked-by: Peter Xu <peterx@redhat.com>
016a62
016a62
From: Fam Zheng <famz@redhat.com>
016a62
016a62
Both virtio-blk and virtio-scsi use virtio_queue_empty() as the
016a62
loop condition in VQ handlers (virtio_blk_handle_vq,
016a62
virtio_scsi_handle_cmd_vq). When a device is marked broken in
016a62
virtqueue_pop, for example if a vIOMMU address translation failed, we
016a62
want to break out of the loop.
016a62
016a62
This fixes a hanging problem when booting a CentOS 3.10.0-862.el7.x86_64
016a62
kernel with ATS enabled:
016a62
016a62
  $ qemu-system-x86_64 \
016a62
    ... \
016a62
    -device intel-iommu,intremap=on,caching-mode=on,eim=on,device-iotlb=on \
016a62
    -device virtio-scsi-pci,iommu_platform=on,ats=on,id=scsi0,bus=pci.4,addr=0x0
016a62
016a62
The dead loop happens immediately when the kernel boots and initializes
016a62
the device, where virtio_scsi_data_plane_handle_cmd will not return:
016a62
016a62
    > ...
016a62
    > #13 0x00005586602b7793 in virtio_scsi_handle_cmd_vq
016a62
    > #14 0x00005586602b8d66 in virtio_scsi_data_plane_handle_cmd
016a62
    > #15 0x00005586602ddab7 in virtio_queue_notify_aio_vq
016a62
    > #16 0x00005586602dfc9f in virtio_queue_host_notifier_aio_poll
016a62
    > #17 0x00005586607885da in run_poll_handlers_once
016a62
    > #18 0x000055866078880e in try_poll_mode
016a62
    > #19 0x00005586607888eb in aio_poll
016a62
    > #20 0x0000558660784561 in aio_wait_bh_oneshot
016a62
    > #21 0x00005586602b9582 in virtio_scsi_dataplane_stop
016a62
    > #22 0x00005586605a7110 in virtio_bus_stop_ioeventfd
016a62
    > #23 0x00005586605a9426 in virtio_pci_stop_ioeventfd
016a62
    > #24 0x00005586605ab808 in virtio_pci_common_write
016a62
    > #25 0x0000558660242396 in memory_region_write_accessor
016a62
    > #26 0x00005586602425ab in access_with_adjusted_size
016a62
    > #27 0x0000558660245281 in memory_region_dispatch_write
016a62
    > #28 0x00005586601e008e in flatview_write_continue
016a62
    > #29 0x00005586601e01d8 in flatview_write
016a62
    > #30 0x00005586601e04de in address_space_write
016a62
    > #31 0x00005586601e052f in address_space_rw
016a62
    > #32 0x00005586602607f2 in kvm_cpu_exec
016a62
    > #33 0x0000558660227148 in qemu_kvm_cpu_thread_fn
016a62
    > #34 0x000055866078bde7 in qemu_thread_start
016a62
    > #35 0x00007f5784906594 in start_thread
016a62
    > #36 0x00007f5784639e6f in clone
016a62
016a62
With this patch, virtio_queue_empty will now return 1 as soon as the
016a62
vdev is marked as broken, after a "virtio: zero sized buffers are not
016a62
allowed" error.
016a62
016a62
To be consistent, update virtio_queue_empty_rcu as well.
016a62
016a62
Signed-off-by: Fam Zheng <famz@redhat.com>
016a62
Message-Id: <20180910145616.8598-2-famz@redhat.com>
016a62
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
016a62
(cherry picked from commit 2d1df8591022737b8ef19d681ff74eda389f5198)
016a62
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
016a62
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
016a62
---
016a62
 hw/virtio/virtio.c | 8 ++++++++
016a62
 1 file changed, 8 insertions(+)
016a62
016a62
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
016a62
index 1debb01..fce199e 100644
016a62
--- a/hw/virtio/virtio.c
016a62
+++ b/hw/virtio/virtio.c
016a62
@@ -344,6 +344,10 @@ int virtio_queue_ready(VirtQueue *vq)
016a62
  * Called within rcu_read_lock().  */
016a62
 static int virtio_queue_empty_rcu(VirtQueue *vq)
016a62
 {
016a62
+    if (unlikely(vq->vdev->broken)) {
016a62
+        return 1;
016a62
+    }
016a62
+
016a62
     if (unlikely(!vq->vring.avail)) {
016a62
         return 1;
016a62
     }
016a62
@@ -359,6 +363,10 @@ int virtio_queue_empty(VirtQueue *vq)
016a62
 {
016a62
     bool empty;
016a62
 
016a62
+    if (unlikely(vq->vdev->broken)) {
016a62
+        return 1;
016a62
+    }
016a62
+
016a62
     if (unlikely(!vq->vring.avail)) {
016a62
         return 1;
016a62
     }
016a62
-- 
016a62
1.8.3.1
016a62