Blame SOURCES/kvm-vhost-Always-store-new-kick-fd-on-vhost_svq_set_svq_.patch

586cba
From 6cde15c70c86819033337771eb522e94e3ea9e34 Mon Sep 17 00:00:00 2001
586cba
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
586cba
Date: Tue, 23 Aug 2022 20:20:07 +0200
586cba
Subject: [PATCH 09/23] vhost: Always store new kick fd on
586cba
 vhost_svq_set_svq_kick_fd
586cba
MIME-Version: 1.0
586cba
Content-Type: text/plain; charset=UTF-8
586cba
Content-Transfer-Encoding: 8bit
586cba
586cba
RH-Author: Eugenio Pérez <eperezma@redhat.com>
586cba
RH-MergeRequest: 116: vdpa: Restore device state on destination
586cba
RH-Bugzilla: 2114060
586cba
RH-Acked-by: Cindy Lu <lulu@redhat.com>
586cba
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
586cba
RH-Commit: [8/21] a09b8851c39d7cea67414560f6d322e988b9d59a (eperezmartin/qemu-kvm)
586cba
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2114060
586cba
Upstream status: git@github.com:jasowang/qemu.git net-next
586cba
586cba
We can unbind twice a file descriptor if we call twice
586cba
vhost_svq_set_svq_kick_fd because of this. Since it comes from vhost and
586cba
not from SVQ, that file descriptor could be a different thing that
586cba
guest's vhost notifier.
586cba
586cba
Likewise, it can happens the same if a guest start and stop the device
586cba
multiple times.
586cba
586cba
Reported-by: Lei Yang <leiyang@redhat.com>
586cba
Fixes: dff4426fa6 ("vhost: Add Shadow VirtQueue kick forwarding capabilities")
586cba
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
586cba
Acked-by: Jason Wang <jasowang@redhat.com>
586cba
Signed-off-by: Jason Wang <jasowang@redhat.com>
586cba
(cherry picked from commit 6867f29c1425add7e0e8d1d8d58cc0ffbb8df0e4)
586cba
---
586cba
 hw/virtio/vhost-shadow-virtqueue.c | 4 ++--
586cba
 1 file changed, 2 insertions(+), 2 deletions(-)
586cba
586cba
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
586cba
index e53aac45f6..f420311b89 100644
586cba
--- a/hw/virtio/vhost-shadow-virtqueue.c
586cba
+++ b/hw/virtio/vhost-shadow-virtqueue.c
586cba
@@ -602,13 +602,13 @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd)
586cba
         event_notifier_set_handler(svq_kick, NULL);
586cba
     }
586cba
 
586cba
+    event_notifier_init_fd(svq_kick, svq_kick_fd);
586cba
     /*
586cba
      * event_notifier_set_handler already checks for guest's notifications if
586cba
      * they arrive at the new file descriptor in the switch, so there is no
586cba
      * need to explicitly check for them.
586cba
      */
586cba
     if (poll_start) {
586cba
-        event_notifier_init_fd(svq_kick, svq_kick_fd);
586cba
         event_notifier_set(svq_kick);
586cba
         event_notifier_set_handler(svq_kick, vhost_handle_guest_kick_notifier);
586cba
     }
586cba
@@ -655,7 +655,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev,
586cba
  */
586cba
 void vhost_svq_stop(VhostShadowVirtqueue *svq)
586cba
 {
586cba
-    event_notifier_set_handler(&svq->svq_kick, NULL);
586cba
+    vhost_svq_set_svq_kick_fd(svq, VHOST_FILE_UNBIND);
586cba
     g_autofree VirtQueueElement *next_avail_elem = NULL;
586cba
 
586cba
     if (!svq->vq) {
586cba
-- 
586cba
2.31.1
586cba