Blame SOURCES/kvm-usb-host-skip-open-on-pending-postload-bh.patch

1bdc94
From 05af6159ba18882c0bdef512abd3c852b515430b Mon Sep 17 00:00:00 2001
1bdc94
From: Gerd Hoffmann <kraxel@redhat.com>
1bdc94
Date: Wed, 13 Jun 2018 14:07:30 +0200
1bdc94
Subject: [PATCH 03/57] usb-host: skip open on pending postload bh
1bdc94
1bdc94
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
1bdc94
Message-id: <20180613140730.16401-2-kraxel@redhat.com>
1bdc94
Patchwork-id: 80667
1bdc94
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 1/1] usb-host: skip open on pending postload bh
1bdc94
Bugzilla: 1572851
1bdc94
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1bdc94
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
1bdc94
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
1bdc94
1bdc94
usb-host emulates a device unplug after live migration, because the
1bdc94
device state is unknown and unplug/replug makes sure the guest
1bdc94
re-initializes the device into a working state.  This can't be done in
1bdc94
post-load though, so post-load just schedules a bottom half which
1bdc94
executes after vmload is complete.
1bdc94
1bdc94
It can happen that the device autoscan timer hits the race window
1bdc94
between scheduling and running the bottom half, which in turn can
1bdc94
triggers an assert().
1bdc94
1bdc94
Fix that issue by just ignoring the usb_host_open() call in case the
1bdc94
bottom half didn't execute yet.
1bdc94
1bdc94
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1572851
1bdc94
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
1bdc94
Message-id: 20180503062932.17233-1-kraxel@redhat.com
1bdc94
(cherry picked from commit 3280ea8edede3814553aa19fa27a58daedd48ad9)
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 hw/usb/host-libusb.c | 7 +++++++
1bdc94
 1 file changed, 7 insertions(+)
1bdc94
1bdc94
diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
1bdc94
index 1b0be07..0290fb8 100644
1bdc94
--- a/hw/usb/host-libusb.c
1bdc94
+++ b/hw/usb/host-libusb.c
1bdc94
@@ -102,6 +102,7 @@ struct USBHostDevice {
1bdc94
     /* callbacks & friends */
1bdc94
     QEMUBH                           *bh_nodev;
1bdc94
     QEMUBH                           *bh_postld;
1bdc94
+    bool                             bh_postld_pending;
1bdc94
     Notifier                         exit;
1bdc94
 
1bdc94
     /* request queues */
1bdc94
@@ -866,6 +867,10 @@ static int usb_host_open(USBHostDevice *s, libusb_device *dev)
1bdc94
     int rc;
1bdc94
     Error *local_err = NULL;
1bdc94
 
1bdc94
+    if (s->bh_postld_pending) {
1bdc94
+        return -1;
1bdc94
+    }
1bdc94
+
1bdc94
     trace_usb_host_open_started(bus_num, addr);
1bdc94
 
1bdc94
     if (s->dh != NULL) {
1bdc94
@@ -1524,6 +1529,7 @@ static void usb_host_post_load_bh(void *opaque)
1bdc94
     if (udev->attached) {
1bdc94
         usb_device_detach(udev);
1bdc94
     }
1bdc94
+    dev->bh_postld_pending = false;
1bdc94
     usb_host_auto_check(NULL);
1bdc94
 }
1bdc94
 
1bdc94
@@ -1535,6 +1541,7 @@ static int usb_host_post_load(void *opaque, int version_id)
1bdc94
         dev->bh_postld = qemu_bh_new(usb_host_post_load_bh, dev);
1bdc94
     }
1bdc94
     qemu_bh_schedule(dev->bh_postld);
1bdc94
+    dev->bh_postld_pending = true;
1bdc94
     return 0;
1bdc94
 }
1bdc94
 
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94