qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging

virtio: quick fix

Fixes a regression in virtio that's causing issues
for many people.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

# gpg: Signature made Wed 24 Jan 2018 17:20:24 GMT
# gpg: using RSA key 0x281F0DB8D28D5469
# gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>"
# gpg: aka "Michael S. Tsirkin <mst@redhat.com>"
# Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67
# Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469

* remotes/mst/tags/for_upstream:
Revert "qemu: add a cleanup callback function to EventNotifier"
Revert "virtio: postpone the execution of event_notifier_cleanup function"
Revert "virtio: improve virtio devices initialization time"

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

+9 -27
-4
accel/kvm/kvm-all.c
··· 812 812 if (r < 0) { 813 813 abort(); 814 814 } 815 - 816 - if (e->cleanup) { 817 - e->cleanup(e); 818 - } 819 815 } 820 816 821 817 static void kvm_io_ioeventfd_add(MemoryListener *listener,
+8 -11
hw/virtio/virtio-bus.c
··· 256 256 return k->ioeventfd_assign && k->ioeventfd_enabled(proxy); 257 257 } 258 258 259 - static void virtio_bus_cleanup_event_notifier(EventNotifier *notifier) 260 - { 261 - /* Test and clear notifier after disabling event, 262 - * in case poll callback didn't have time to run. 263 - */ 264 - virtio_queue_host_notifier_read(notifier); 265 - event_notifier_cleanup(notifier); 266 - } 267 - 268 259 /* 269 260 * This function switches ioeventfd on/off in the device. 270 261 * The caller must set or clear the handlers for the EventNotifier. ··· 292 283 r = k->ioeventfd_assign(proxy, notifier, n, true); 293 284 if (r < 0) { 294 285 error_report("%s: unable to assign ioeventfd: %d", __func__, r); 295 - virtio_bus_cleanup_event_notifier(notifier); 286 + goto cleanup_event_notifier; 296 287 } 288 + return 0; 297 289 } else { 298 - notifier->cleanup = virtio_bus_cleanup_event_notifier; 299 290 k->ioeventfd_assign(proxy, notifier, n, false); 300 291 } 301 292 293 + cleanup_event_notifier: 294 + /* Test and clear notifier after disabling event, 295 + * in case poll callback didn't have time to run. 296 + */ 297 + virtio_queue_host_notifier_read(notifier); 298 + event_notifier_cleanup(notifier); 302 299 return r; 303 300 } 304 301
-5
hw/virtio/virtio.c
··· 2574 2574 VirtioBusState *qbus = VIRTIO_BUS(qdev_get_parent_bus(DEVICE(vdev))); 2575 2575 int n, r, err; 2576 2576 2577 - memory_region_transaction_begin(); 2578 2577 for (n = 0; n < VIRTIO_QUEUE_MAX; n++) { 2579 2578 VirtQueue *vq = &vdev->vq[n]; 2580 2579 if (!virtio_queue_get_num(vdev, n)) { ··· 2597 2596 } 2598 2597 event_notifier_set(&vq->host_notifier); 2599 2598 } 2600 - memory_region_transaction_commit(); 2601 2599 return 0; 2602 2600 2603 2601 assign_error: ··· 2611 2609 r = virtio_bus_set_host_notifier(qbus, n, false); 2612 2610 assert(r >= 0); 2613 2611 } 2614 - memory_region_transaction_commit(); 2615 2612 return err; 2616 2613 } 2617 2614 ··· 2628 2625 VirtioBusState *qbus = VIRTIO_BUS(qdev_get_parent_bus(DEVICE(vdev))); 2629 2626 int n, r; 2630 2627 2631 - memory_region_transaction_begin(); 2632 2628 for (n = 0; n < VIRTIO_QUEUE_MAX; n++) { 2633 2629 VirtQueue *vq = &vdev->vq[n]; 2634 2630 ··· 2639 2635 r = virtio_bus_set_host_notifier(qbus, n, false); 2640 2636 assert(r >= 0); 2641 2637 } 2642 - memory_region_transaction_commit(); 2643 2638 } 2644 2639 2645 2640 void virtio_device_stop_ioeventfd(VirtIODevice *vdev)
-1
include/qemu/event_notifier.h
··· 26 26 int rfd; 27 27 int wfd; 28 28 #endif 29 - void (*cleanup)(EventNotifier *); 30 29 }; 31 30 32 31 typedef void EventNotifierHandler(EventNotifier *);
+1 -4
util/event_notifier-posix.c
··· 29 29 { 30 30 e->rfd = fd; 31 31 e->wfd = fd; 32 - e->cleanup = NULL; 33 32 } 34 33 #endif 35 34 ··· 66 65 e->rfd = fds[0]; 67 66 e->wfd = fds[1]; 68 67 } 69 - e->cleanup = NULL; 70 68 if (active) { 71 69 event_notifier_set(e); 72 70 } ··· 82 80 { 83 81 if (e->rfd != e->wfd) { 84 82 close(e->rfd); 83 + e->rfd = -1; 85 84 } 86 85 close(e->wfd); 87 - e->rfd = -1; 88 86 e->wfd = -1; 89 - e->cleanup = NULL; 90 87 } 91 88 92 89 int event_notifier_get_fd(const EventNotifier *e)
-2
util/event_notifier-win32.c
··· 19 19 { 20 20 e->event = CreateEvent(NULL, TRUE, FALSE, NULL); 21 21 assert(e->event); 22 - e->cleanup = NULL; 23 22 return 0; 24 23 } 25 24 ··· 27 26 { 28 27 CloseHandle(e->event); 29 28 e->event = NULL; 30 - e->cleanup = NULL; 31 29 } 32 30 33 31 HANDLE event_notifier_get_handle(EventNotifier *e)