]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/extra/0012-virtio-scsi-fix-ctrl-and-event-handler-functions-in-.patch
92a57cf88bd11eba4366696eb372636a18889cb2
[pve-qemu.git] / debian / patches / extra / 0012-virtio-scsi-fix-ctrl-and-event-handler-functions-in-.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Stefan Hajnoczi <stefanha@redhat.com>
3 Date: Wed, 27 Apr 2022 15:35:36 +0100
4 Subject: [PATCH] virtio-scsi: fix ctrl and event handler functions in
5 dataplane mode
6
7 Commit f34e8d8b8d48d73f36a67b6d5e492ef9784b5012 ("virtio-scsi: prepare
8 virtio_scsi_handle_cmd for dataplane") prepared the virtio-scsi cmd
9 virtqueue handler function to be used in both the dataplane and
10 non-datpalane code paths.
11
12 It failed to convert the ctrl and event virtqueue handler functions,
13 which are not designed to be called from the dataplane code path but
14 will be since the ioeventfd is set up for those virtqueues when
15 dataplane starts.
16
17 Convert the ctrl and event virtqueue handler functions now so they
18 operate correctly when called from the dataplane code path. Avoid code
19 duplication by extracting this code into a helper function.
20
21 Fixes: f34e8d8b8d48d73f36a67b6d5e492ef9784b5012 ("virtio-scsi: prepare virtio_scsi_handle_cmd for dataplane")
22 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
23 Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
24 Message-id: 20220427143541.119567-2-stefanha@redhat.com
25 [Fixed s/by used/be used/ typo pointed out by Michael Tokarev
26 <mjt@tls.msk.ru>.
27 --Stefan]
28 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
29 (cherry-picked from commit 2f743ef6366c2df4ef51ef3ae318138cdc0125ab)
30 Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
31 ---
32 hw/scsi/virtio-scsi.c | 42 +++++++++++++++++++++++++++---------------
33 1 file changed, 27 insertions(+), 15 deletions(-)
34
35 diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
36 index 34a968ecfb..417fbc71d6 100644
37 --- a/hw/scsi/virtio-scsi.c
38 +++ b/hw/scsi/virtio-scsi.c
39 @@ -472,16 +472,32 @@ bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq)
40 return progress;
41 }
42
43 +/*
44 + * If dataplane is configured but not yet started, do so now and return true on
45 + * success.
46 + *
47 + * Dataplane is started by the core virtio code but virtqueue handler functions
48 + * can also be invoked when a guest kicks before DRIVER_OK, so this helper
49 + * function helps us deal with manually starting ioeventfd in that case.
50 + */
51 +static bool virtio_scsi_defer_to_dataplane(VirtIOSCSI *s)
52 +{
53 + if (!s->ctx || s->dataplane_started) {
54 + return false;
55 + }
56 +
57 + virtio_device_start_ioeventfd(&s->parent_obj.parent_obj);
58 + return !s->dataplane_fenced;
59 +}
60 +
61 static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
62 {
63 VirtIOSCSI *s = (VirtIOSCSI *)vdev;
64
65 - if (s->ctx) {
66 - virtio_device_start_ioeventfd(vdev);
67 - if (!s->dataplane_fenced) {
68 - return;
69 - }
70 + if (virtio_scsi_defer_to_dataplane(s)) {
71 + return;
72 }
73 +
74 virtio_scsi_acquire(s);
75 virtio_scsi_handle_ctrl_vq(s, vq);
76 virtio_scsi_release(s);
77 @@ -720,12 +736,10 @@ static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)
78 /* use non-QOM casts in the data path */
79 VirtIOSCSI *s = (VirtIOSCSI *)vdev;
80
81 - if (s->ctx && !s->dataplane_started) {
82 - virtio_device_start_ioeventfd(vdev);
83 - if (!s->dataplane_fenced) {
84 - return;
85 - }
86 + if (virtio_scsi_defer_to_dataplane(s)) {
87 + return;
88 }
89 +
90 virtio_scsi_acquire(s);
91 virtio_scsi_handle_cmd_vq(s, vq);
92 virtio_scsi_release(s);
93 @@ -855,12 +869,10 @@ static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
94 {
95 VirtIOSCSI *s = VIRTIO_SCSI(vdev);
96
97 - if (s->ctx) {
98 - virtio_device_start_ioeventfd(vdev);
99 - if (!s->dataplane_fenced) {
100 - return;
101 - }
102 + if (virtio_scsi_defer_to_dataplane(s)) {
103 + return;
104 }
105 +
106 virtio_scsi_acquire(s);
107 virtio_scsi_handle_event_vq(s, vq);
108 virtio_scsi_release(s);