Blame SOURCES/kvm-virtio-scsi-fix-ctrl-and-event-handler-functions-in-.patch

29b115
From 5aaf33dbbbc89d58a52337985641723b9ee13541 Mon Sep 17 00:00:00 2001
29b115
From: Stefan Hajnoczi <stefanha@redhat.com>
29b115
Date: Wed, 27 Apr 2022 15:35:36 +0100
29b115
Subject: [PATCH 09/16] virtio-scsi: fix ctrl and event handler functions in
29b115
 dataplane mode
29b115
29b115
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
29b115
RH-MergeRequest: 88: virtio-scsi: fix 100% CPU consumption with IOThreads
29b115
RH-Commit: [1/6] 3087889041b960f14a6b3893243f78523a78f637 (stefanha/centos-stream-qemu-kvm)
29b115
RH-Bugzilla: 2079347
29b115
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
29b115
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
29b115
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
29b115
29b115
Commit f34e8d8b8d48d73f36a67b6d5e492ef9784b5012 ("virtio-scsi: prepare
29b115
virtio_scsi_handle_cmd for dataplane") prepared the virtio-scsi cmd
29b115
virtqueue handler function to be used in both the dataplane and
29b115
non-datpalane code paths.
29b115
29b115
It failed to convert the ctrl and event virtqueue handler functions,
29b115
which are not designed to be called from the dataplane code path but
29b115
will be since the ioeventfd is set up for those virtqueues when
29b115
dataplane starts.
29b115
29b115
Convert the ctrl and event virtqueue handler functions now so they
29b115
operate correctly when called from the dataplane code path. Avoid code
29b115
duplication by extracting this code into a helper function.
29b115
29b115
Fixes: f34e8d8b8d48d73f36a67b6d5e492ef9784b5012 ("virtio-scsi: prepare virtio_scsi_handle_cmd for dataplane")
29b115
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
29b115
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
29b115
Message-id: 20220427143541.119567-2-stefanha@redhat.com
29b115
[Fixed s/by used/be used/ typo pointed out by Michael Tokarev
29b115
<mjt@tls.msk.ru>.
29b115
--Stefan]
29b115
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
29b115
(cherry picked from commit 2f743ef6366c2df4ef51ef3ae318138cdc0125ab)
29b115
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
29b115
---
29b115
 hw/scsi/virtio-scsi.c | 42 +++++++++++++++++++++++++++---------------
29b115
 1 file changed, 27 insertions(+), 15 deletions(-)
29b115
29b115
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
29b115
index 7f6da33a8a..7b69eeed64 100644
29b115
--- a/hw/scsi/virtio-scsi.c
29b115
+++ b/hw/scsi/virtio-scsi.c
29b115
@@ -472,16 +472,32 @@ bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq)
29b115
     return progress;
29b115
 }
29b115
 
29b115
+/*
29b115
+ * If dataplane is configured but not yet started, do so now and return true on
29b115
+ * success.
29b115
+ *
29b115
+ * Dataplane is started by the core virtio code but virtqueue handler functions
29b115
+ * can also be invoked when a guest kicks before DRIVER_OK, so this helper
29b115
+ * function helps us deal with manually starting ioeventfd in that case.
29b115
+ */
29b115
+static bool virtio_scsi_defer_to_dataplane(VirtIOSCSI *s)
29b115
+{
29b115
+    if (!s->ctx || s->dataplane_started) {
29b115
+        return false;
29b115
+    }
29b115
+
29b115
+    virtio_device_start_ioeventfd(&s->parent_obj.parent_obj);
29b115
+    return !s->dataplane_fenced;
29b115
+}
29b115
+
29b115
 static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
29b115
 {
29b115
     VirtIOSCSI *s = (VirtIOSCSI *)vdev;
29b115
 
29b115
-    if (s->ctx) {
29b115
-        virtio_device_start_ioeventfd(vdev);
29b115
-        if (!s->dataplane_fenced) {
29b115
-            return;
29b115
-        }
29b115
+    if (virtio_scsi_defer_to_dataplane(s)) {
29b115
+        return;
29b115
     }
29b115
+
29b115
     virtio_scsi_acquire(s);
29b115
     virtio_scsi_handle_ctrl_vq(s, vq);
29b115
     virtio_scsi_release(s);
29b115
@@ -720,12 +736,10 @@ static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)
29b115
     /* use non-QOM casts in the data path */
29b115
     VirtIOSCSI *s = (VirtIOSCSI *)vdev;
29b115
 
29b115
-    if (s->ctx && !s->dataplane_started) {
29b115
-        virtio_device_start_ioeventfd(vdev);
29b115
-        if (!s->dataplane_fenced) {
29b115
-            return;
29b115
-        }
29b115
+    if (virtio_scsi_defer_to_dataplane(s)) {
29b115
+        return;
29b115
     }
29b115
+
29b115
     virtio_scsi_acquire(s);
29b115
     virtio_scsi_handle_cmd_vq(s, vq);
29b115
     virtio_scsi_release(s);
29b115
@@ -855,12 +869,10 @@ static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
29b115
 {
29b115
     VirtIOSCSI *s = VIRTIO_SCSI(vdev);
29b115
 
29b115
-    if (s->ctx) {
29b115
-        virtio_device_start_ioeventfd(vdev);
29b115
-        if (!s->dataplane_fenced) {
29b115
-            return;
29b115
-        }
29b115
+    if (virtio_scsi_defer_to_dataplane(s)) {
29b115
+        return;
29b115
     }
29b115
+
29b115
     virtio_scsi_acquire(s);
29b115
     virtio_scsi_handle_event_vq(s, vq);
29b115
     virtio_scsi_release(s);
29b115
-- 
29b115
2.31.1
29b115