import OL qemu-kvm-8.2.0-11.el9_4.3
This commit is contained in:
parent
bbdd4d80bd
commit
b93771b478
275
SOURCES/kvm-iotests-test-NBD-TLS-iothread.patch
Normal file
275
SOURCES/kvm-iotests-test-NBD-TLS-iothread.patch
Normal file
@ -0,0 +1,275 @@
|
||||
From 4296c41178438f9dffa16c538b0c1a2e28944f4c Mon Sep 17 00:00:00 2001
|
||||
From: Eric Blake <eblake@redhat.com>
|
||||
Date: Fri, 17 May 2024 21:50:15 -0500
|
||||
Subject: [PATCH 4/4] iotests: test NBD+TLS+iothread
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
RH-Author: Eric Blake <eblake@redhat.com>
|
||||
RH-MergeRequest: 375: Fix regression on nbd+tls
|
||||
RH-Jira: RHEL-33754
|
||||
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
||||
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
||||
RH-Commit: [4/4] 5905c09466f4e65f3ff9973b41f42cbe1d75363c (ebblake/qemu-kvm)
|
||||
|
||||
Prevent regressions when using NBD with TLS in the presence of
|
||||
iothreads, adding coverage the fix to qio channels made in the
|
||||
previous patch.
|
||||
|
||||
The shell function pick_unused_port() was copied from
|
||||
nbdkit.git/tests/functions.sh.in, where it had all authors from Red
|
||||
Hat, agreeing to the resulting relicensing from 2-clause BSD to GPLv2.
|
||||
|
||||
CC: qemu-stable@nongnu.org
|
||||
CC: "Richard W.M. Jones" <rjones@redhat.com>
|
||||
Signed-off-by: Eric Blake <eblake@redhat.com>
|
||||
Message-ID: <20240531180639.1392905-6-eblake@redhat.com>
|
||||
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
|
||||
(cherry picked from commit a73c99378022ebb785481e84cfe1e81097546268)
|
||||
Jira: https://issues.redhat.com/browse/RHEL-33754
|
||||
Signed-off-by: Eric Blake <eblake@redhat.com>
|
||||
---
|
||||
tests/qemu-iotests/tests/nbd-tls-iothread | 168 ++++++++++++++++++
|
||||
tests/qemu-iotests/tests/nbd-tls-iothread.out | 54 ++++++
|
||||
2 files changed, 222 insertions(+)
|
||||
create mode 100755 tests/qemu-iotests/tests/nbd-tls-iothread
|
||||
create mode 100644 tests/qemu-iotests/tests/nbd-tls-iothread.out
|
||||
|
||||
diff --git a/tests/qemu-iotests/tests/nbd-tls-iothread b/tests/qemu-iotests/tests/nbd-tls-iothread
|
||||
new file mode 100755
|
||||
index 0000000000..a2fb07206e
|
||||
--- /dev/null
|
||||
+++ b/tests/qemu-iotests/tests/nbd-tls-iothread
|
||||
@@ -0,0 +1,168 @@
|
||||
+#!/usr/bin/env bash
|
||||
+# group: rw quick
|
||||
+#
|
||||
+# Test of NBD+TLS+iothread
|
||||
+#
|
||||
+# Copyright (C) 2024 Red Hat, Inc.
|
||||
+#
|
||||
+# This program is free software; you can redistribute it and/or modify
|
||||
+# it under the terms of the GNU General Public License as published by
|
||||
+# the Free Software Foundation; either version 2 of the License, or
|
||||
+# (at your option) any later version.
|
||||
+#
|
||||
+# This program is distributed in the hope that it will be useful,
|
||||
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
+# GNU General Public License for more details.
|
||||
+#
|
||||
+# You should have received a copy of the GNU General Public License
|
||||
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
+#
|
||||
+
|
||||
+# creator
|
||||
+owner=eblake@redhat.com
|
||||
+
|
||||
+seq=`basename $0`
|
||||
+echo "QA output created by $seq"
|
||||
+
|
||||
+status=1 # failure is the default!
|
||||
+
|
||||
+_cleanup()
|
||||
+{
|
||||
+ _cleanup_qemu
|
||||
+ _cleanup_test_img
|
||||
+ rm -f "$dst_image"
|
||||
+ tls_x509_cleanup
|
||||
+}
|
||||
+trap "_cleanup; exit \$status" 0 1 2 3 15
|
||||
+
|
||||
+# get standard environment, filters and checks
|
||||
+cd ..
|
||||
+. ./common.rc
|
||||
+. ./common.filter
|
||||
+. ./common.qemu
|
||||
+. ./common.tls
|
||||
+. ./common.nbd
|
||||
+
|
||||
+_supported_fmt qcow2 # Hardcoded to qcow2 command line and QMP below
|
||||
+_supported_proto file
|
||||
+
|
||||
+# pick_unused_port
|
||||
+#
|
||||
+# Picks and returns an "unused" port, setting the global variable
|
||||
+# $port.
|
||||
+#
|
||||
+# This is inherently racy, but we need it because qemu does not currently
|
||||
+# permit NBD+TLS over a Unix domain socket
|
||||
+pick_unused_port ()
|
||||
+{
|
||||
+ if ! (ss --version) >/dev/null 2>&1; then
|
||||
+ _notrun "ss utility required, skipped this test"
|
||||
+ fi
|
||||
+
|
||||
+ # Start at a random port to make it less likely that two parallel
|
||||
+ # tests will conflict.
|
||||
+ port=$(( 50000 + (RANDOM%15000) ))
|
||||
+ while ss -ltn | grep -sqE ":$port\b"; do
|
||||
+ ((port++))
|
||||
+ if [ $port -eq 65000 ]; then port=50000; fi
|
||||
+ done
|
||||
+ echo picked unused port
|
||||
+}
|
||||
+
|
||||
+tls_x509_init
|
||||
+
|
||||
+size=1G
|
||||
+DST_IMG="$TEST_DIR/dst.qcow2"
|
||||
+
|
||||
+echo
|
||||
+echo "== preparing TLS creds and spare port =="
|
||||
+
|
||||
+pick_unused_port
|
||||
+tls_x509_create_root_ca "ca1"
|
||||
+tls_x509_create_server "ca1" "server1"
|
||||
+tls_x509_create_client "ca1" "client1"
|
||||
+tls_obj_base=tls-creds-x509,id=tls0,verify-peer=true,dir="${tls_dir}"
|
||||
+
|
||||
+echo
|
||||
+echo "== preparing image =="
|
||||
+
|
||||
+_make_test_img $size
|
||||
+$QEMU_IMG create -f qcow2 "$DST_IMG" $size | _filter_img_create
|
||||
+
|
||||
+echo
|
||||
+echo === Starting Src QEMU ===
|
||||
+echo
|
||||
+
|
||||
+_launch_qemu -machine q35 \
|
||||
+ -object iothread,id=iothread0 \
|
||||
+ -object "${tls_obj_base}"/client1,endpoint=client \
|
||||
+ -device '{"driver":"pcie-root-port", "id":"root0", "multifunction":true,
|
||||
+ "bus":"pcie.0"}' \
|
||||
+ -device '{"driver":"virtio-scsi-pci", "id":"virtio_scsi_pci0",
|
||||
+ "bus":"root0", "iothread":"iothread0"}' \
|
||||
+ -device '{"driver":"scsi-hd", "id":"image1", "drive":"drive_image1",
|
||||
+ "bus":"virtio_scsi_pci0.0"}' \
|
||||
+ -blockdev '{"driver":"file", "cache":{"direct":true, "no-flush":false},
|
||||
+ "filename":"'"$TEST_IMG"'", "node-name":"drive_sys1"}' \
|
||||
+ -blockdev '{"driver":"qcow2", "node-name":"drive_image1",
|
||||
+ "file":"drive_sys1"}'
|
||||
+h1=$QEMU_HANDLE
|
||||
+_send_qemu_cmd $h1 '{"execute": "qmp_capabilities"}' 'return'
|
||||
+
|
||||
+echo
|
||||
+echo === Starting Dst VM2 ===
|
||||
+echo
|
||||
+
|
||||
+_launch_qemu -machine q35 \
|
||||
+ -object iothread,id=iothread0 \
|
||||
+ -object "${tls_obj_base}"/server1,endpoint=server \
|
||||
+ -device '{"driver":"pcie-root-port", "id":"root0", "multifunction":true,
|
||||
+ "bus":"pcie.0"}' \
|
||||
+ -device '{"driver":"virtio-scsi-pci", "id":"virtio_scsi_pci0",
|
||||
+ "bus":"root0", "iothread":"iothread0"}' \
|
||||
+ -device '{"driver":"scsi-hd", "id":"image1", "drive":"drive_image1",
|
||||
+ "bus":"virtio_scsi_pci0.0"}' \
|
||||
+ -blockdev '{"driver":"file", "cache":{"direct":true, "no-flush":false},
|
||||
+ "filename":"'"$DST_IMG"'", "node-name":"drive_sys1"}' \
|
||||
+ -blockdev '{"driver":"qcow2", "node-name":"drive_image1",
|
||||
+ "file":"drive_sys1"}' \
|
||||
+ -incoming defer
|
||||
+h2=$QEMU_HANDLE
|
||||
+_send_qemu_cmd $h2 '{"execute": "qmp_capabilities"}' 'return'
|
||||
+
|
||||
+echo
|
||||
+echo === Dst VM: Enable NBD server for incoming storage migration ===
|
||||
+echo
|
||||
+
|
||||
+_send_qemu_cmd $h2 '{"execute": "nbd-server-start", "arguments":
|
||||
+ {"addr": {"type": "inet", "data": {"host": "127.0.0.1", "port": "'$port'"}},
|
||||
+ "tls-creds": "tls0"}}' '{"return": {}}' | sed "s/\"$port\"/PORT/g"
|
||||
+_send_qemu_cmd $h2 '{"execute": "block-export-add", "arguments":
|
||||
+ {"node-name": "drive_image1", "type": "nbd", "writable": true,
|
||||
+ "id": "drive_image1"}}' '{"return": {}}'
|
||||
+
|
||||
+echo
|
||||
+echo === Src VM: Mirror to dst NBD for outgoing storage migration ===
|
||||
+echo
|
||||
+
|
||||
+_send_qemu_cmd $h1 '{"execute": "blockdev-add", "arguments":
|
||||
+ {"node-name": "mirror", "driver": "nbd",
|
||||
+ "server": {"type": "inet", "host": "127.0.0.1", "port": "'$port'"},
|
||||
+ "export": "drive_image1", "tls-creds": "tls0",
|
||||
+ "tls-hostname": "127.0.0.1"}}' '{"return": {}}' | sed "s/\"$port\"/PORT/g"
|
||||
+_send_qemu_cmd $h1 '{"execute": "blockdev-mirror", "arguments":
|
||||
+ {"sync": "full", "device": "drive_image1", "target": "mirror",
|
||||
+ "job-id": "drive_image1_53"}}' '{"return": {}}'
|
||||
+_timed_wait_for $h1 '"ready"'
|
||||
+
|
||||
+echo
|
||||
+echo === Cleaning up ===
|
||||
+echo
|
||||
+
|
||||
+_send_qemu_cmd $h1 '{"execute":"quit"}' ''
|
||||
+_send_qemu_cmd $h2 '{"execute":"quit"}' ''
|
||||
+
|
||||
+echo "*** done"
|
||||
+rm -f $seq.full
|
||||
+status=0
|
||||
diff --git a/tests/qemu-iotests/tests/nbd-tls-iothread.out b/tests/qemu-iotests/tests/nbd-tls-iothread.out
|
||||
new file mode 100644
|
||||
index 0000000000..1d83d4f903
|
||||
--- /dev/null
|
||||
+++ b/tests/qemu-iotests/tests/nbd-tls-iothread.out
|
||||
@@ -0,0 +1,54 @@
|
||||
+QA output created by nbd-tls-iothread
|
||||
+
|
||||
+== preparing TLS creds and spare port ==
|
||||
+picked unused port
|
||||
+Generating a self signed certificate...
|
||||
+Generating a signed certificate...
|
||||
+Generating a signed certificate...
|
||||
+
|
||||
+== preparing image ==
|
||||
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824
|
||||
+Formatting 'TEST_DIR/dst.IMGFMT', fmt=IMGFMT size=1073741824
|
||||
+
|
||||
+=== Starting Src QEMU ===
|
||||
+
|
||||
+{"execute": "qmp_capabilities"}
|
||||
+{"return": {}}
|
||||
+
|
||||
+=== Starting Dst VM2 ===
|
||||
+
|
||||
+{"execute": "qmp_capabilities"}
|
||||
+{"return": {}}
|
||||
+
|
||||
+=== Dst VM: Enable NBD server for incoming storage migration ===
|
||||
+
|
||||
+{"execute": "nbd-server-start", "arguments":
|
||||
+ {"addr": {"type": "inet", "data": {"host": "127.0.0.1", "port": PORT}},
|
||||
+ "tls-creds": "tls0"}}
|
||||
+{"return": {}}
|
||||
+{"execute": "block-export-add", "arguments":
|
||||
+ {"node-name": "drive_image1", "type": "nbd", "writable": true,
|
||||
+ "id": "drive_image1"}}
|
||||
+{"return": {}}
|
||||
+
|
||||
+=== Src VM: Mirror to dst NBD for outgoing storage migration ===
|
||||
+
|
||||
+{"execute": "blockdev-add", "arguments":
|
||||
+ {"node-name": "mirror", "driver": "nbd",
|
||||
+ "server": {"type": "inet", "host": "127.0.0.1", "port": PORT},
|
||||
+ "export": "drive_image1", "tls-creds": "tls0",
|
||||
+ "tls-hostname": "127.0.0.1"}}
|
||||
+{"return": {}}
|
||||
+{"execute": "blockdev-mirror", "arguments":
|
||||
+ {"sync": "full", "device": "drive_image1", "target": "mirror",
|
||||
+ "job-id": "drive_image1_53"}}
|
||||
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "drive_image1_53"}}
|
||||
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "drive_image1_53"}}
|
||||
+{"return": {}}
|
||||
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "drive_image1_53"}}
|
||||
+
|
||||
+=== Cleaning up ===
|
||||
+
|
||||
+{"execute":"quit"}
|
||||
+{"execute":"quit"}
|
||||
+*** done
|
||||
--
|
||||
2.39.3
|
||||
|
@ -0,0 +1,76 @@
|
||||
From 8a8fa4ab4dc05502550ca207926cd0c93a3341ea Mon Sep 17 00:00:00 2001
|
||||
From: Igor Mammedov <imammedo@redhat.com>
|
||||
Date: Mon, 8 Apr 2024 12:43:49 +0200
|
||||
Subject: [PATCH] kvm: error out of kvm_irqchip_add_msi_route() in case of full
|
||||
route table
|
||||
|
||||
RH-Author: Igor Mammedov <imammedo@redhat.com>
|
||||
RH-MergeRequest: 374: kvm: error out of kvm_irqchip_add_msi_route() in case of full route table
|
||||
RH-Jira: RHEL-32990
|
||||
RH-Acked-by: Ani Sinha <anisinha@redhat.com>
|
||||
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
||||
RH-Commit: [1/1] df31f2d0cafe10a1ac22a2bebb85dc17c1e891e0
|
||||
|
||||
RH-Jira: RHEL-32990
|
||||
|
||||
subj is calling kvm_add_routing_entry() which simply extends
|
||||
KVMState::irq_routes::entries[]
|
||||
but doesn't check if number of routes goes beyond limit the kernel
|
||||
is willing to accept. Which later leads toi the assert
|
||||
|
||||
qemu-kvm: ../accel/kvm/kvm-all.c:1833: kvm_irqchip_commit_routes: Assertion `ret == 0' failed
|
||||
|
||||
typically it happens during guest boot for large enough guest
|
||||
|
||||
Reproduced with:
|
||||
./qemu --enable-kvm -m 8G -smp 64 -machine pc \
|
||||
`for b in {1..2}; do echo -n "-device pci-bridge,id=pci$b,chassis_nr=$b ";
|
||||
for i in {0..31}; do touch /tmp/vblk$b$i;
|
||||
echo -n "-drive file=/tmp/vblk$b$i,if=none,id=drive$b$i,format=raw
|
||||
-device virtio-blk-pci,drive=drive$b$i,bus=pci$b ";
|
||||
done; done`
|
||||
|
||||
While crash at boot time is bad, the same might happen at hotplug time
|
||||
which is unacceptable.
|
||||
So instead calling kvm_add_routing_entry() unconditionally, check first
|
||||
that number of routes won't exceed KVM_CAP_IRQ_ROUTING. This way virtio
|
||||
device insteads killin qemu, will gracefully fail to initialize device
|
||||
as expected with following warnings on console:
|
||||
virtio-blk failed to set guest notifier (-28), ensure -accel kvm is set.
|
||||
virtio_bus_start_ioeventfd: failed. Fallback to userspace (slower).
|
||||
|
||||
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
|
||||
---
|
||||
accel/kvm/kvm-all.c | 15 ++++++++++-----
|
||||
1 file changed, 10 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
|
||||
index e39a810a4e..f1a4564cbd 100644
|
||||
--- a/accel/kvm/kvm-all.c
|
||||
+++ b/accel/kvm/kvm-all.c
|
||||
@@ -2000,12 +2000,17 @@ int kvm_irqchip_add_msi_route(KVMRouteChange *c, int vector, PCIDevice *dev)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
- trace_kvm_irqchip_add_msi_route(dev ? dev->name : (char *)"N/A",
|
||||
- vector, virq);
|
||||
+ if (s->irq_routes->nr < s->gsi_count) {
|
||||
+ trace_kvm_irqchip_add_msi_route(dev ? dev->name : (char *)"N/A",
|
||||
+ vector, virq);
|
||||
|
||||
- kvm_add_routing_entry(s, &kroute);
|
||||
- kvm_arch_add_msi_route_post(&kroute, vector, dev);
|
||||
- c->changes++;
|
||||
+ kvm_add_routing_entry(s, &kroute);
|
||||
+ kvm_arch_add_msi_route_post(&kroute, vector, dev);
|
||||
+ c->changes++;
|
||||
+ } else {
|
||||
+ kvm_irqchip_release_virq(s, virq);
|
||||
+ return -ENOSPC;
|
||||
+ }
|
||||
|
||||
return virq;
|
||||
}
|
||||
--
|
||||
2.39.3
|
||||
|
@ -0,0 +1,329 @@
|
||||
From d1dd79b558fb9b23ae14165ec8edf0085e927091 Mon Sep 17 00:00:00 2001
|
||||
From: Eric Blake <eblake@redhat.com>
|
||||
Date: Mon, 8 Apr 2024 11:00:44 -0500
|
||||
Subject: [PATCH 2/4] nbd/server: Mark negotiation functions as coroutine_fn
|
||||
|
||||
RH-Author: Eric Blake <eblake@redhat.com>
|
||||
RH-MergeRequest: 375: Fix regression on nbd+tls
|
||||
RH-Jira: RHEL-33754
|
||||
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
||||
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
||||
RH-Commit: [2/4] 6dc8ecca16df5ae5cc6dc36e7b96f991396fcf24 (ebblake/qemu-kvm)
|
||||
|
||||
nbd_negotiate() is already marked coroutine_fn. And given the fix in
|
||||
the previous patch to have nbd_negotiate_handle_starttls not create
|
||||
and wait on a g_main_loop (as that would violate coroutine
|
||||
constraints), it is worth marking the rest of the related static
|
||||
functions reachable only during option negotiation as also being
|
||||
coroutine_fn.
|
||||
|
||||
Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
|
||||
Signed-off-by: Eric Blake <eblake@redhat.com>
|
||||
Message-ID: <20240408160214.1200629-6-eblake@redhat.com>
|
||||
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
|
||||
[eblake: drop one spurious coroutine_fn marking]
|
||||
Signed-off-by: Eric Blake <eblake@redhat.com>
|
||||
(cherry picked from commit 4fa333e08dd96395a99ea8dd9e4c73a29dd23344)
|
||||
Jira: https://issues.redhat.com/browse/RHEL-33754
|
||||
Signed-off-by: Eric Blake <eblake@redhat.com>
|
||||
---
|
||||
nbd/server.c | 102 +++++++++++++++++++++++++++++----------------------
|
||||
1 file changed, 59 insertions(+), 43 deletions(-)
|
||||
|
||||
diff --git a/nbd/server.c b/nbd/server.c
|
||||
index 98ae0e1632..892797bb11 100644
|
||||
--- a/nbd/server.c
|
||||
+++ b/nbd/server.c
|
||||
@@ -195,8 +195,9 @@ static inline void set_be_option_rep(NBDOptionReply *rep, uint32_t option,
|
||||
|
||||
/* Send a reply header, including length, but no payload.
|
||||
* Return -errno on error, 0 on success. */
|
||||
-static int nbd_negotiate_send_rep_len(NBDClient *client, uint32_t type,
|
||||
- uint32_t len, Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_send_rep_len(NBDClient *client, uint32_t type,
|
||||
+ uint32_t len, Error **errp)
|
||||
{
|
||||
NBDOptionReply rep;
|
||||
|
||||
@@ -211,15 +212,15 @@ static int nbd_negotiate_send_rep_len(NBDClient *client, uint32_t type,
|
||||
|
||||
/* Send a reply header with default 0 length.
|
||||
* Return -errno on error, 0 on success. */
|
||||
-static int nbd_negotiate_send_rep(NBDClient *client, uint32_t type,
|
||||
- Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_send_rep(NBDClient *client, uint32_t type, Error **errp)
|
||||
{
|
||||
return nbd_negotiate_send_rep_len(client, type, 0, errp);
|
||||
}
|
||||
|
||||
/* Send an error reply.
|
||||
* Return -errno on error, 0 on success. */
|
||||
-static int G_GNUC_PRINTF(4, 0)
|
||||
+static coroutine_fn int G_GNUC_PRINTF(4, 0)
|
||||
nbd_negotiate_send_rep_verr(NBDClient *client, uint32_t type,
|
||||
Error **errp, const char *fmt, va_list va)
|
||||
{
|
||||
@@ -259,7 +260,7 @@ nbd_sanitize_name(const char *name)
|
||||
|
||||
/* Send an error reply.
|
||||
* Return -errno on error, 0 on success. */
|
||||
-static int G_GNUC_PRINTF(4, 5)
|
||||
+static coroutine_fn int G_GNUC_PRINTF(4, 5)
|
||||
nbd_negotiate_send_rep_err(NBDClient *client, uint32_t type,
|
||||
Error **errp, const char *fmt, ...)
|
||||
{
|
||||
@@ -275,7 +276,7 @@ nbd_negotiate_send_rep_err(NBDClient *client, uint32_t type,
|
||||
/* Drop remainder of the current option, and send a reply with the
|
||||
* given error type and message. Return -errno on read or write
|
||||
* failure; or 0 if connection is still live. */
|
||||
-static int G_GNUC_PRINTF(4, 0)
|
||||
+static coroutine_fn int G_GNUC_PRINTF(4, 0)
|
||||
nbd_opt_vdrop(NBDClient *client, uint32_t type, Error **errp,
|
||||
const char *fmt, va_list va)
|
||||
{
|
||||
@@ -288,7 +289,7 @@ nbd_opt_vdrop(NBDClient *client, uint32_t type, Error **errp,
|
||||
return ret;
|
||||
}
|
||||
|
||||
-static int G_GNUC_PRINTF(4, 5)
|
||||
+static coroutine_fn int G_GNUC_PRINTF(4, 5)
|
||||
nbd_opt_drop(NBDClient *client, uint32_t type, Error **errp,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
@@ -302,7 +303,7 @@ nbd_opt_drop(NBDClient *client, uint32_t type, Error **errp,
|
||||
return ret;
|
||||
}
|
||||
|
||||
-static int G_GNUC_PRINTF(3, 4)
|
||||
+static coroutine_fn int G_GNUC_PRINTF(3, 4)
|
||||
nbd_opt_invalid(NBDClient *client, Error **errp, const char *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
@@ -319,8 +320,9 @@ nbd_opt_invalid(NBDClient *client, Error **errp, const char *fmt, ...)
|
||||
* If @check_nul, require that no NUL bytes appear in buffer.
|
||||
* Return -errno on I/O error, 0 if option was completely handled by
|
||||
* sending a reply about inconsistent lengths, or 1 on success. */
|
||||
-static int nbd_opt_read(NBDClient *client, void *buffer, size_t size,
|
||||
- bool check_nul, Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_opt_read(NBDClient *client, void *buffer, size_t size,
|
||||
+ bool check_nul, Error **errp)
|
||||
{
|
||||
if (size > client->optlen) {
|
||||
return nbd_opt_invalid(client, errp,
|
||||
@@ -343,7 +345,8 @@ static int nbd_opt_read(NBDClient *client, void *buffer, size_t size,
|
||||
/* Drop size bytes from the unparsed payload of the current option.
|
||||
* Return -errno on I/O error, 0 if option was completely handled by
|
||||
* sending a reply about inconsistent lengths, or 1 on success. */
|
||||
-static int nbd_opt_skip(NBDClient *client, size_t size, Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_opt_skip(NBDClient *client, size_t size, Error **errp)
|
||||
{
|
||||
if (size > client->optlen) {
|
||||
return nbd_opt_invalid(client, errp,
|
||||
@@ -366,8 +369,9 @@ static int nbd_opt_skip(NBDClient *client, size_t size, Error **errp)
|
||||
* Return -errno on I/O error, 0 if option was completely handled by
|
||||
* sending a reply about inconsistent lengths, or 1 on success.
|
||||
*/
|
||||
-static int nbd_opt_read_name(NBDClient *client, char **name, uint32_t *length,
|
||||
- Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_opt_read_name(NBDClient *client, char **name, uint32_t *length,
|
||||
+ Error **errp)
|
||||
{
|
||||
int ret;
|
||||
uint32_t len;
|
||||
@@ -402,8 +406,8 @@ static int nbd_opt_read_name(NBDClient *client, char **name, uint32_t *length,
|
||||
|
||||
/* Send a single NBD_REP_SERVER reply to NBD_OPT_LIST, including payload.
|
||||
* Return -errno on error, 0 on success. */
|
||||
-static int nbd_negotiate_send_rep_list(NBDClient *client, NBDExport *exp,
|
||||
- Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_send_rep_list(NBDClient *client, NBDExport *exp, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
size_t name_len, desc_len;
|
||||
@@ -444,7 +448,8 @@ static int nbd_negotiate_send_rep_list(NBDClient *client, NBDExport *exp,
|
||||
|
||||
/* Process the NBD_OPT_LIST command, with a potential series of replies.
|
||||
* Return -errno on error, 0 on success. */
|
||||
-static int nbd_negotiate_handle_list(NBDClient *client, Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_handle_list(NBDClient *client, Error **errp)
|
||||
{
|
||||
NBDExport *exp;
|
||||
assert(client->opt == NBD_OPT_LIST);
|
||||
@@ -459,7 +464,8 @@ static int nbd_negotiate_handle_list(NBDClient *client, Error **errp)
|
||||
return nbd_negotiate_send_rep(client, NBD_REP_ACK, errp);
|
||||
}
|
||||
|
||||
-static void nbd_check_meta_export(NBDClient *client, NBDExport *exp)
|
||||
+static coroutine_fn void
|
||||
+nbd_check_meta_export(NBDClient *client, NBDExport *exp)
|
||||
{
|
||||
if (exp != client->contexts.exp) {
|
||||
client->contexts.count = 0;
|
||||
@@ -468,8 +474,9 @@ static void nbd_check_meta_export(NBDClient *client, NBDExport *exp)
|
||||
|
||||
/* Send a reply to NBD_OPT_EXPORT_NAME.
|
||||
* Return -errno on error, 0 on success. */
|
||||
-static int nbd_negotiate_handle_export_name(NBDClient *client, bool no_zeroes,
|
||||
- Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_handle_export_name(NBDClient *client, bool no_zeroes,
|
||||
+ Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
g_autofree char *name = NULL;
|
||||
@@ -536,9 +543,9 @@ static int nbd_negotiate_handle_export_name(NBDClient *client, bool no_zeroes,
|
||||
/* Send a single NBD_REP_INFO, with a buffer @buf of @length bytes.
|
||||
* The buffer does NOT include the info type prefix.
|
||||
* Return -errno on error, 0 if ready to send more. */
|
||||
-static int nbd_negotiate_send_info(NBDClient *client,
|
||||
- uint16_t info, uint32_t length, void *buf,
|
||||
- Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_send_info(NBDClient *client, uint16_t info, uint32_t length,
|
||||
+ void *buf, Error **errp)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -565,7 +572,8 @@ static int nbd_negotiate_send_info(NBDClient *client,
|
||||
* -errno transmission error occurred or @fatal was requested, errp is set
|
||||
* 0 error message successfully sent to client, errp is not set
|
||||
*/
|
||||
-static int nbd_reject_length(NBDClient *client, bool fatal, Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_reject_length(NBDClient *client, bool fatal, Error **errp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -583,7 +591,8 @@ static int nbd_reject_length(NBDClient *client, bool fatal, Error **errp)
|
||||
/* Handle NBD_OPT_INFO and NBD_OPT_GO.
|
||||
* Return -errno on error, 0 if ready for next option, and 1 to move
|
||||
* into transmission phase. */
|
||||
-static int nbd_negotiate_handle_info(NBDClient *client, Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_handle_info(NBDClient *client, Error **errp)
|
||||
{
|
||||
int rc;
|
||||
g_autofree char *name = NULL;
|
||||
@@ -755,7 +764,8 @@ struct NBDTLSServerHandshakeData {
|
||||
Coroutine *co;
|
||||
};
|
||||
|
||||
-static void nbd_server_tls_handshake(QIOTask *task, void *opaque)
|
||||
+static void
|
||||
+nbd_server_tls_handshake(QIOTask *task, void *opaque)
|
||||
{
|
||||
struct NBDTLSServerHandshakeData *data = opaque;
|
||||
|
||||
@@ -768,8 +778,8 @@ static void nbd_server_tls_handshake(QIOTask *task, void *opaque)
|
||||
|
||||
/* Handle NBD_OPT_STARTTLS. Return NULL to drop connection, or else the
|
||||
* new channel for all further (now-encrypted) communication. */
|
||||
-static QIOChannel *nbd_negotiate_handle_starttls(NBDClient *client,
|
||||
- Error **errp)
|
||||
+static coroutine_fn QIOChannel *
|
||||
+nbd_negotiate_handle_starttls(NBDClient *client, Error **errp)
|
||||
{
|
||||
QIOChannel *ioc;
|
||||
QIOChannelTLS *tioc;
|
||||
@@ -821,10 +831,9 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDClient *client,
|
||||
*
|
||||
* For NBD_OPT_LIST_META_CONTEXT @context_id is ignored, 0 is used instead.
|
||||
*/
|
||||
-static int nbd_negotiate_send_meta_context(NBDClient *client,
|
||||
- const char *context,
|
||||
- uint32_t context_id,
|
||||
- Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_send_meta_context(NBDClient *client, const char *context,
|
||||
+ uint32_t context_id, Error **errp)
|
||||
{
|
||||
NBDOptionReplyMetaContext opt;
|
||||
struct iovec iov[] = {
|
||||
@@ -849,8 +858,9 @@ static int nbd_negotiate_send_meta_context(NBDClient *client,
|
||||
* Return true if @query matches @pattern, or if @query is empty when
|
||||
* the @client is performing _LIST_.
|
||||
*/
|
||||
-static bool nbd_meta_empty_or_pattern(NBDClient *client, const char *pattern,
|
||||
- const char *query)
|
||||
+static coroutine_fn bool
|
||||
+nbd_meta_empty_or_pattern(NBDClient *client, const char *pattern,
|
||||
+ const char *query)
|
||||
{
|
||||
if (!*query) {
|
||||
trace_nbd_negotiate_meta_query_parse("empty");
|
||||
@@ -867,7 +877,8 @@ static bool nbd_meta_empty_or_pattern(NBDClient *client, const char *pattern,
|
||||
/*
|
||||
* Return true and adjust @str in place if it begins with @prefix.
|
||||
*/
|
||||
-static bool nbd_strshift(const char **str, const char *prefix)
|
||||
+static coroutine_fn bool
|
||||
+nbd_strshift(const char **str, const char *prefix)
|
||||
{
|
||||
size_t len = strlen(prefix);
|
||||
|
||||
@@ -883,8 +894,9 @@ static bool nbd_strshift(const char **str, const char *prefix)
|
||||
* Handle queries to 'base' namespace. For now, only the base:allocation
|
||||
* context is available. Return true if @query has been handled.
|
||||
*/
|
||||
-static bool nbd_meta_base_query(NBDClient *client, NBDMetaContexts *meta,
|
||||
- const char *query)
|
||||
+static coroutine_fn bool
|
||||
+nbd_meta_base_query(NBDClient *client, NBDMetaContexts *meta,
|
||||
+ const char *query)
|
||||
{
|
||||
if (!nbd_strshift(&query, "base:")) {
|
||||
return false;
|
||||
@@ -903,8 +915,9 @@ static bool nbd_meta_base_query(NBDClient *client, NBDMetaContexts *meta,
|
||||
* and qemu:allocation-depth contexts are available. Return true if @query
|
||||
* has been handled.
|
||||
*/
|
||||
-static bool nbd_meta_qemu_query(NBDClient *client, NBDMetaContexts *meta,
|
||||
- const char *query)
|
||||
+static coroutine_fn bool
|
||||
+nbd_meta_qemu_query(NBDClient *client, NBDMetaContexts *meta,
|
||||
+ const char *query)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -968,8 +981,9 @@ static bool nbd_meta_qemu_query(NBDClient *client, NBDMetaContexts *meta,
|
||||
*
|
||||
* Return -errno on I/O error, 0 if option was completely handled by
|
||||
* sending a reply about inconsistent lengths, or 1 on success. */
|
||||
-static int nbd_negotiate_meta_query(NBDClient *client,
|
||||
- NBDMetaContexts *meta, Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_meta_query(NBDClient *client,
|
||||
+ NBDMetaContexts *meta, Error **errp)
|
||||
{
|
||||
int ret;
|
||||
g_autofree char *query = NULL;
|
||||
@@ -1008,7 +1022,8 @@ static int nbd_negotiate_meta_query(NBDClient *client,
|
||||
* Handle NBD_OPT_LIST_META_CONTEXT and NBD_OPT_SET_META_CONTEXT
|
||||
*
|
||||
* Return -errno on I/O error, or 0 if option was completely handled. */
|
||||
-static int nbd_negotiate_meta_queries(NBDClient *client, Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_meta_queries(NBDClient *client, Error **errp)
|
||||
{
|
||||
int ret;
|
||||
g_autofree char *export_name = NULL;
|
||||
@@ -1136,7 +1151,8 @@ static int nbd_negotiate_meta_queries(NBDClient *client, Error **errp)
|
||||
* 1 if client sent NBD_OPT_ABORT, i.e. on valid disconnect,
|
||||
* errp is not set
|
||||
*/
|
||||
-static int nbd_negotiate_options(NBDClient *client, Error **errp)
|
||||
+static coroutine_fn int
|
||||
+nbd_negotiate_options(NBDClient *client, Error **errp)
|
||||
{
|
||||
uint32_t flags;
|
||||
bool fixedNewstyle = false;
|
||||
--
|
||||
2.39.3
|
||||
|
@ -0,0 +1,207 @@
|
||||
From ef01aeba9f6c4c886719261333a04bc32484f0d0 Mon Sep 17 00:00:00 2001
|
||||
From: Zhu Yangyang <zhuyangyang14@huawei.com>
|
||||
Date: Mon, 8 Apr 2024 11:00:43 -0500
|
||||
Subject: [PATCH 1/4] nbd/server: do not poll within a coroutine context
|
||||
|
||||
RH-Author: Eric Blake <eblake@redhat.com>
|
||||
RH-MergeRequest: 375: Fix regression on nbd+tls
|
||||
RH-Jira: RHEL-33754
|
||||
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
||||
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
||||
RH-Commit: [1/4] 88ca2c90e0c412ba8c1cfd7ea91e01ec58220e9b (ebblake/qemu-kvm)
|
||||
|
||||
Coroutines are not supposed to block. Instead, they should yield.
|
||||
|
||||
The client performs TLS upgrade outside of an AIOContext, during
|
||||
synchronous handshake; this still requires g_main_loop. But the
|
||||
server responds to TLS upgrade inside a coroutine, so a nested
|
||||
g_main_loop is wrong. Since the two callbacks no longer share more
|
||||
than the setting of data.complete and data.error, it's just as easy to
|
||||
use static helpers instead of trying to share a common code path. It
|
||||
is also possible to add assertions that no other code is interfering
|
||||
with the eventual path to qio reaching the callback, whether or not it
|
||||
required a yield or main loop.
|
||||
|
||||
Fixes: f95910f ("nbd: implement TLS support in the protocol negotiation")
|
||||
Signed-off-by: Zhu Yangyang <zhuyangyang14@huawei.com>
|
||||
[eblake: move callbacks to their use point, add assertions]
|
||||
Signed-off-by: Eric Blake <eblake@redhat.com>
|
||||
Message-ID: <20240408160214.1200629-5-eblake@redhat.com>
|
||||
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
|
||||
(cherry picked from commit ae6d91a7e9b77abb029ed3fa9fad461422286942)
|
||||
Jira: https://issues.redhat.com/browse/RHEL-33754
|
||||
Signed-off-by: Eric Blake <eblake@redhat.com>
|
||||
---
|
||||
nbd/client.c | 28 ++++++++++++++++++++++++----
|
||||
nbd/common.c | 11 -----------
|
||||
nbd/nbd-internal.h | 10 ----------
|
||||
nbd/server.c | 28 +++++++++++++++++++++++-----
|
||||
4 files changed, 47 insertions(+), 30 deletions(-)
|
||||
|
||||
diff --git a/nbd/client.c b/nbd/client.c
|
||||
index 29ffc609a4..c89c750467 100644
|
||||
--- a/nbd/client.c
|
||||
+++ b/nbd/client.c
|
||||
@@ -596,13 +596,31 @@ static int nbd_request_simple_option(QIOChannel *ioc, int opt, bool strict,
|
||||
return 1;
|
||||
}
|
||||
|
||||
+/* Callback to learn when QIO TLS upgrade is complete */
|
||||
+struct NBDTLSClientHandshakeData {
|
||||
+ bool complete;
|
||||
+ Error *error;
|
||||
+ GMainLoop *loop;
|
||||
+};
|
||||
+
|
||||
+static void nbd_client_tls_handshake(QIOTask *task, void *opaque)
|
||||
+{
|
||||
+ struct NBDTLSClientHandshakeData *data = opaque;
|
||||
+
|
||||
+ qio_task_propagate_error(task, &data->error);
|
||||
+ data->complete = true;
|
||||
+ if (data->loop) {
|
||||
+ g_main_loop_quit(data->loop);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
|
||||
QCryptoTLSCreds *tlscreds,
|
||||
const char *hostname, Error **errp)
|
||||
{
|
||||
int ret;
|
||||
QIOChannelTLS *tioc;
|
||||
- struct NBDTLSHandshakeData data = { 0 };
|
||||
+ struct NBDTLSClientHandshakeData data = { 0 };
|
||||
|
||||
ret = nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, true, errp);
|
||||
if (ret <= 0) {
|
||||
@@ -619,18 +637,20 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
|
||||
return NULL;
|
||||
}
|
||||
qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-client-tls");
|
||||
- data.loop = g_main_loop_new(g_main_context_default(), FALSE);
|
||||
trace_nbd_receive_starttls_tls_handshake();
|
||||
qio_channel_tls_handshake(tioc,
|
||||
- nbd_tls_handshake,
|
||||
+ nbd_client_tls_handshake,
|
||||
&data,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
if (!data.complete) {
|
||||
+ data.loop = g_main_loop_new(g_main_context_default(), FALSE);
|
||||
g_main_loop_run(data.loop);
|
||||
+ assert(data.complete);
|
||||
+ g_main_loop_unref(data.loop);
|
||||
}
|
||||
- g_main_loop_unref(data.loop);
|
||||
+
|
||||
if (data.error) {
|
||||
error_propagate(errp, data.error);
|
||||
object_unref(OBJECT(tioc));
|
||||
diff --git a/nbd/common.c b/nbd/common.c
|
||||
index 3247c1d618..589a748cfe 100644
|
||||
--- a/nbd/common.c
|
||||
+++ b/nbd/common.c
|
||||
@@ -47,17 +47,6 @@ int nbd_drop(QIOChannel *ioc, size_t size, Error **errp)
|
||||
}
|
||||
|
||||
|
||||
-void nbd_tls_handshake(QIOTask *task,
|
||||
- void *opaque)
|
||||
-{
|
||||
- struct NBDTLSHandshakeData *data = opaque;
|
||||
-
|
||||
- qio_task_propagate_error(task, &data->error);
|
||||
- data->complete = true;
|
||||
- g_main_loop_quit(data->loop);
|
||||
-}
|
||||
-
|
||||
-
|
||||
const char *nbd_opt_lookup(uint32_t opt)
|
||||
{
|
||||
switch (opt) {
|
||||
diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h
|
||||
index dfa02f77ee..91895106a9 100644
|
||||
--- a/nbd/nbd-internal.h
|
||||
+++ b/nbd/nbd-internal.h
|
||||
@@ -72,16 +72,6 @@ static inline int nbd_write(QIOChannel *ioc, const void *buffer, size_t size,
|
||||
return qio_channel_write_all(ioc, buffer, size, errp) < 0 ? -EIO : 0;
|
||||
}
|
||||
|
||||
-struct NBDTLSHandshakeData {
|
||||
- GMainLoop *loop;
|
||||
- bool complete;
|
||||
- Error *error;
|
||||
-};
|
||||
-
|
||||
-
|
||||
-void nbd_tls_handshake(QIOTask *task,
|
||||
- void *opaque);
|
||||
-
|
||||
int nbd_drop(QIOChannel *ioc, size_t size, Error **errp);
|
||||
|
||||
#endif
|
||||
diff --git a/nbd/server.c b/nbd/server.c
|
||||
index c3484cc1eb..98ae0e1632 100644
|
||||
--- a/nbd/server.c
|
||||
+++ b/nbd/server.c
|
||||
@@ -748,6 +748,23 @@ static int nbd_negotiate_handle_info(NBDClient *client, Error **errp)
|
||||
return rc;
|
||||
}
|
||||
|
||||
+/* Callback to learn when QIO TLS upgrade is complete */
|
||||
+struct NBDTLSServerHandshakeData {
|
||||
+ bool complete;
|
||||
+ Error *error;
|
||||
+ Coroutine *co;
|
||||
+};
|
||||
+
|
||||
+static void nbd_server_tls_handshake(QIOTask *task, void *opaque)
|
||||
+{
|
||||
+ struct NBDTLSServerHandshakeData *data = opaque;
|
||||
+
|
||||
+ qio_task_propagate_error(task, &data->error);
|
||||
+ data->complete = true;
|
||||
+ if (!qemu_coroutine_entered(data->co)) {
|
||||
+ aio_co_wake(data->co);
|
||||
+ }
|
||||
+}
|
||||
|
||||
/* Handle NBD_OPT_STARTTLS. Return NULL to drop connection, or else the
|
||||
* new channel for all further (now-encrypted) communication. */
|
||||
@@ -756,7 +773,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDClient *client,
|
||||
{
|
||||
QIOChannel *ioc;
|
||||
QIOChannelTLS *tioc;
|
||||
- struct NBDTLSHandshakeData data = { 0 };
|
||||
+ struct NBDTLSServerHandshakeData data = { 0 };
|
||||
|
||||
assert(client->opt == NBD_OPT_STARTTLS);
|
||||
|
||||
@@ -777,17 +794,18 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDClient *client,
|
||||
|
||||
qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-server-tls");
|
||||
trace_nbd_negotiate_handle_starttls_handshake();
|
||||
- data.loop = g_main_loop_new(g_main_context_default(), FALSE);
|
||||
+ data.co = qemu_coroutine_self();
|
||||
qio_channel_tls_handshake(tioc,
|
||||
- nbd_tls_handshake,
|
||||
+ nbd_server_tls_handshake,
|
||||
&data,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
if (!data.complete) {
|
||||
- g_main_loop_run(data.loop);
|
||||
+ qemu_coroutine_yield();
|
||||
+ assert(data.complete);
|
||||
}
|
||||
- g_main_loop_unref(data.loop);
|
||||
+
|
||||
if (data.error) {
|
||||
object_unref(OBJECT(tioc));
|
||||
error_propagate(errp, data.error);
|
||||
--
|
||||
2.39.3
|
||||
|
129
SOURCES/kvm-qio-Inherit-follow_coroutine_ctx-across-TLS.patch
Normal file
129
SOURCES/kvm-qio-Inherit-follow_coroutine_ctx-across-TLS.patch
Normal file
@ -0,0 +1,129 @@
|
||||
From 69d6b5f98d665fbcb86e42df40bcc5e9c79b397f Mon Sep 17 00:00:00 2001
|
||||
From: Eric Blake <eblake@redhat.com>
|
||||
Date: Fri, 17 May 2024 21:50:14 -0500
|
||||
Subject: [PATCH 3/4] qio: Inherit follow_coroutine_ctx across TLS
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
RH-Author: Eric Blake <eblake@redhat.com>
|
||||
RH-MergeRequest: 375: Fix regression on nbd+tls
|
||||
RH-Jira: RHEL-33754
|
||||
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
||||
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
||||
RH-Commit: [3/4] 14ddea7e3c81898bb3fe4be51a40749d67a5c0c0 (ebblake/qemu-kvm)
|
||||
|
||||
Since qemu 8.2, the combination of NBD + TLS + iothread crashes on an
|
||||
assertion failure:
|
||||
|
||||
qemu-kvm: ../io/channel.c:534: void qio_channel_restart_read(void *): Assertion `qemu_get_current_aio_context() == qemu_coroutine_get_aio_context(co)' failed.
|
||||
|
||||
It turns out that when we removed AioContext locking, we did so by
|
||||
having NBD tell its qio channels that it wanted to opt in to
|
||||
qio_channel_set_follow_coroutine_ctx(); but while we opted in on the
|
||||
main channel, we did not opt in on the TLS wrapper channel.
|
||||
qemu-iotests has coverage of NBD+iothread and NBD+TLS, but apparently
|
||||
no coverage of NBD+TLS+iothread, or we would have noticed this
|
||||
regression sooner. (I'll add that in the next patch)
|
||||
|
||||
But while we could manually opt in to the TLS channel in nbd/server.c
|
||||
(a one-line change), it is more generic if all qio channels that wrap
|
||||
other channels inherit the follow status, in the same way that they
|
||||
inherit feature bits.
|
||||
|
||||
CC: Stefan Hajnoczi <stefanha@redhat.com>
|
||||
CC: Daniel P. Berrangé <berrange@redhat.com>
|
||||
CC: qemu-stable@nongnu.org
|
||||
Fixes: https://issues.redhat.com/browse/RHEL-34786
|
||||
Fixes: 06e0f098 ("io: follow coroutine AioContext in qio_channel_yield()", v8.2.0)
|
||||
Signed-off-by: Eric Blake <eblake@redhat.com>
|
||||
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
|
||||
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
|
||||
Message-ID: <20240518025246.791593-5-eblake@redhat.com>
|
||||
(cherry picked from commit 199e84de1c903ba5aa1f7256310bbc4a20dd930b)
|
||||
Jira: https://issues.redhat.com/browse/RHEL-33754
|
||||
Signed-off-by: Eric Blake <eblake@redhat.com>
|
||||
---
|
||||
io/channel-tls.c | 26 +++++++++++++++-----------
|
||||
io/channel-websock.c | 1 +
|
||||
2 files changed, 16 insertions(+), 11 deletions(-)
|
||||
|
||||
diff --git a/io/channel-tls.c b/io/channel-tls.c
|
||||
index 58fe1aceee..a8ad89c3d1 100644
|
||||
--- a/io/channel-tls.c
|
||||
+++ b/io/channel-tls.c
|
||||
@@ -69,37 +69,40 @@ qio_channel_tls_new_server(QIOChannel *master,
|
||||
const char *aclname,
|
||||
Error **errp)
|
||||
{
|
||||
- QIOChannelTLS *ioc;
|
||||
+ QIOChannelTLS *tioc;
|
||||
+ QIOChannel *ioc;
|
||||
|
||||
- ioc = QIO_CHANNEL_TLS(object_new(TYPE_QIO_CHANNEL_TLS));
|
||||
+ tioc = QIO_CHANNEL_TLS(object_new(TYPE_QIO_CHANNEL_TLS));
|
||||
+ ioc = QIO_CHANNEL(tioc);
|
||||
|
||||
- ioc->master = master;
|
||||
+ tioc->master = master;
|
||||
+ ioc->follow_coroutine_ctx = master->follow_coroutine_ctx;
|
||||
if (qio_channel_has_feature(master, QIO_CHANNEL_FEATURE_SHUTDOWN)) {
|
||||
- qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SHUTDOWN);
|
||||
+ qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN);
|
||||
}
|
||||
object_ref(OBJECT(master));
|
||||
|
||||
- ioc->session = qcrypto_tls_session_new(
|
||||
+ tioc->session = qcrypto_tls_session_new(
|
||||
creds,
|
||||
NULL,
|
||||
aclname,
|
||||
QCRYPTO_TLS_CREDS_ENDPOINT_SERVER,
|
||||
errp);
|
||||
- if (!ioc->session) {
|
||||
+ if (!tioc->session) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
qcrypto_tls_session_set_callbacks(
|
||||
- ioc->session,
|
||||
+ tioc->session,
|
||||
qio_channel_tls_write_handler,
|
||||
qio_channel_tls_read_handler,
|
||||
- ioc);
|
||||
+ tioc);
|
||||
|
||||
- trace_qio_channel_tls_new_server(ioc, master, creds, aclname);
|
||||
- return ioc;
|
||||
+ trace_qio_channel_tls_new_server(tioc, master, creds, aclname);
|
||||
+ return tioc;
|
||||
|
||||
error:
|
||||
- object_unref(OBJECT(ioc));
|
||||
+ object_unref(OBJECT(tioc));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -116,6 +119,7 @@ qio_channel_tls_new_client(QIOChannel *master,
|
||||
ioc = QIO_CHANNEL(tioc);
|
||||
|
||||
tioc->master = master;
|
||||
+ ioc->follow_coroutine_ctx = master->follow_coroutine_ctx;
|
||||
if (qio_channel_has_feature(master, QIO_CHANNEL_FEATURE_SHUTDOWN)) {
|
||||
qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN);
|
||||
}
|
||||
diff --git a/io/channel-websock.c b/io/channel-websock.c
|
||||
index a12acc27cf..de39f0d182 100644
|
||||
--- a/io/channel-websock.c
|
||||
+++ b/io/channel-websock.c
|
||||
@@ -883,6 +883,7 @@ qio_channel_websock_new_server(QIOChannel *master)
|
||||
ioc = QIO_CHANNEL(wioc);
|
||||
|
||||
wioc->master = master;
|
||||
+ ioc->follow_coroutine_ctx = master->follow_coroutine_ctx;
|
||||
if (qio_channel_has_feature(master, QIO_CHANNEL_FEATURE_SHUTDOWN)) {
|
||||
qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN);
|
||||
}
|
||||
--
|
||||
2.39.3
|
||||
|
162
SOURCES/kvm-virtio-pci-fix-use-of-a-released-vector.patch
Normal file
162
SOURCES/kvm-virtio-pci-fix-use-of-a-released-vector.patch
Normal file
@ -0,0 +1,162 @@
|
||||
From ccd8ffa5cd7f9bcfddeda7a9fa1ad86d4bad870e Mon Sep 17 00:00:00 2001
|
||||
From: Cindy Lu <lulu@redhat.com>
|
||||
Date: Fri, 12 Apr 2024 14:26:55 +0800
|
||||
Subject: [PATCH] virtio-pci: fix use of a released vector
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
RH-Author: Cindy Lu <lulu@redhat.com>
|
||||
RH-MergeRequest: 366: virtio-pci: fix use of a released vector
|
||||
RH-Jira: RHEL-32837
|
||||
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
|
||||
RH-Acked-by: Jason Wang <jasowang@redhat.com>
|
||||
RH-Commit: [1/1] edd26ffb8727635310aed42e42925afe87df2287
|
||||
|
||||
During the booting process of the non-standard image, the behavior of the
|
||||
called function in qemu is as follows:
|
||||
|
||||
1. vhost_net_stop() was triggered by guest image. This will call the function
|
||||
virtio_pci_set_guest_notifiers() with assgin= false,
|
||||
virtio_pci_set_guest_notifiers() will release the irqfd for vector 0
|
||||
|
||||
2. virtio_reset() was triggered, this will set configure vector to VIRTIO_NO_VECTOR
|
||||
|
||||
3.vhost_net_start() was called (at this time, the configure vector is
|
||||
still VIRTIO_NO_VECTOR) and then call virtio_pci_set_guest_notifiers() with
|
||||
assgin=true, so the irqfd for vector 0 is still not "init" during this process
|
||||
|
||||
4. The system continues to boot and sets the vector back to 0. After that
|
||||
msix_fire_vector_notifier() was triggered to unmask the vector 0 and meet the crash
|
||||
|
||||
To fix the issue, we need to support changing the vector after VIRTIO_CONFIG_S_DRIVER_OK is set.
|
||||
|
||||
(gdb) bt
|
||||
0 __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0)
|
||||
at pthread_kill.c:44
|
||||
1 0x00007fc87148ec53 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
|
||||
2 0x00007fc87143e956 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
|
||||
3 0x00007fc8714287f4 in __GI_abort () at abort.c:79
|
||||
4 0x00007fc87142871b in __assert_fail_base
|
||||
(fmt=0x7fc8715bbde0 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x5606413efd53 "ret == 0", file=0x5606413ef87d "../accel/kvm/kvm-all.c", line=1837, function=<optimized out>) at assert.c:92
|
||||
5 0x00007fc871437536 in __GI___assert_fail
|
||||
(assertion=0x5606413efd53 "ret == 0", file=0x5606413ef87d "../accel/kvm/kvm-all.c", line=1837, function=0x5606413f06f0 <__PRETTY_FUNCTION__.19> "kvm_irqchip_commit_routes") at assert.c:101
|
||||
6 0x0000560640f884b5 in kvm_irqchip_commit_routes (s=0x560642cae1f0) at ../accel/kvm/kvm-all.c:1837
|
||||
7 0x0000560640c98f8e in virtio_pci_one_vector_unmask
|
||||
(proxy=0x560643c65f00, queue_no=4294967295, vector=0, msg=..., n=0x560643c6e4c8)
|
||||
at ../hw/virtio/virtio-pci.c:1005
|
||||
8 0x0000560640c99201 in virtio_pci_vector_unmask (dev=0x560643c65f00, vector=0, msg=...)
|
||||
at ../hw/virtio/virtio-pci.c:1070
|
||||
9 0x0000560640bc402e in msix_fire_vector_notifier (dev=0x560643c65f00, vector=0, is_masked=false)
|
||||
at ../hw/pci/msix.c:120
|
||||
10 0x0000560640bc40f1 in msix_handle_mask_update (dev=0x560643c65f00, vector=0, was_masked=true)
|
||||
at ../hw/pci/msix.c:140
|
||||
11 0x0000560640bc4503 in msix_table_mmio_write (opaque=0x560643c65f00, addr=12, val=0, size=4)
|
||||
at ../hw/pci/msix.c:231
|
||||
12 0x0000560640f26d83 in memory_region_write_accessor
|
||||
(mr=0x560643c66540, addr=12, value=0x7fc86b7bc628, size=4, shift=0, mask=4294967295, attrs=...)
|
||||
at ../system/memory.c:497
|
||||
13 0x0000560640f270a6 in access_with_adjusted_size
|
||||
|
||||
(addr=12, value=0x7fc86b7bc628, size=4, access_size_min=1, access_size_max=4, access_fn=0x560640f26c8d <memory_region_write_accessor>, mr=0x560643c66540, attrs=...) at ../system/memory.c:573
|
||||
14 0x0000560640f2a2b5 in memory_region_dispatch_write (mr=0x560643c66540, addr=12, data=0, op=MO_32, attrs=...)
|
||||
at ../system/memory.c:1521
|
||||
15 0x0000560640f37bac in flatview_write_continue
|
||||
(fv=0x7fc65805e0b0, addr=4273803276, attrs=..., ptr=0x7fc871e9c028, len=4, addr1=12, l=4, mr=0x560643c66540)
|
||||
at ../system/physmem.c:2714
|
||||
16 0x0000560640f37d0f in flatview_write
|
||||
(fv=0x7fc65805e0b0, addr=4273803276, attrs=..., buf=0x7fc871e9c028, len=4) at ../system/physmem.c:2756
|
||||
17 0x0000560640f380bf in address_space_write
|
||||
(as=0x560642161ae0 <address_space_memory>, addr=4273803276, attrs=..., buf=0x7fc871e9c028, len=4)
|
||||
at ../system/physmem.c:2863
|
||||
18 0x0000560640f3812c in address_space_rw
|
||||
(as=0x560642161ae0 <address_space_memory>, addr=4273803276, attrs=..., buf=0x7fc871e9c028, len=4, is_write=true) at ../system/physmem.c:2873
|
||||
--Type <RET> for more, q to quit, c to continue without paging--
|
||||
19 0x0000560640f8aa55 in kvm_cpu_exec (cpu=0x560642f205e0) at ../accel/kvm/kvm-all.c:2915
|
||||
20 0x0000560640f8d731 in kvm_vcpu_thread_fn (arg=0x560642f205e0) at ../accel/kvm/kvm-accel-ops.c:51
|
||||
21 0x00005606411949f4 in qemu_thread_start (args=0x560642f292b0) at ../util/qemu-thread-posix.c:541
|
||||
22 0x00007fc87148cdcd in start_thread (arg=<optimized out>) at pthread_create.c:442
|
||||
23 0x00007fc871512630 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
|
||||
(gdb)
|
||||
|
||||
MST: coding style and typo fixups
|
||||
|
||||
Fixes: f9a09ca3ea ("vhost: add support for configure interrupt")
|
||||
Cc: qemu-stable@nongnu.org
|
||||
Signed-off-by: Cindy Lu <lulu@redhat.com>
|
||||
Message-ID: <2321ade5f601367efe7380c04e3f61379c59b48f.1713173550.git.mst@redhat.com>
|
||||
Cc: Lei Yang <leiyang@redhat.com>
|
||||
Cc: Jason Wang <jasowang@redhat.com>
|
||||
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
||||
Tested-by: Cindy Lu <lulu@redhat.com>
|
||||
(cherry picked from commit 2ce6cff94df2650c460f809e5ad263f1d22507c0)
|
||||
Signed-off-by: Cindy Lu <lulu@redhat.com>
|
||||
---
|
||||
hw/virtio/virtio-pci.c | 37 +++++++++++++++++++++++++++++++++++--
|
||||
1 file changed, 35 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
|
||||
index e433879542..08faefe29a 100644
|
||||
--- a/hw/virtio/virtio-pci.c
|
||||
+++ b/hw/virtio/virtio-pci.c
|
||||
@@ -1424,6 +1424,38 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
|
||||
return offset;
|
||||
}
|
||||
|
||||
+static void virtio_pci_set_vector(VirtIODevice *vdev,
|
||||
+ VirtIOPCIProxy *proxy,
|
||||
+ int queue_no, uint16_t old_vector,
|
||||
+ uint16_t new_vector)
|
||||
+{
|
||||
+ bool kvm_irqfd = (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
|
||||
+ msix_enabled(&proxy->pci_dev) && kvm_msi_via_irqfd_enabled();
|
||||
+
|
||||
+ if (new_vector == old_vector) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * If the device uses irqfd and the vector changes after DRIVER_OK is
|
||||
+ * set, we need to release the old vector and set up the new one.
|
||||
+ * Otherwise just need to set the new vector on the device.
|
||||
+ */
|
||||
+ if (kvm_irqfd && old_vector != VIRTIO_NO_VECTOR) {
|
||||
+ kvm_virtio_pci_vector_release_one(proxy, queue_no);
|
||||
+ }
|
||||
+ /* Set the new vector on the device. */
|
||||
+ if (queue_no == VIRTIO_CONFIG_IRQ_IDX) {
|
||||
+ vdev->config_vector = new_vector;
|
||||
+ } else {
|
||||
+ virtio_queue_set_vector(vdev, queue_no, new_vector);
|
||||
+ }
|
||||
+ /* If the new vector changed need to set it up. */
|
||||
+ if (kvm_irqfd && new_vector != VIRTIO_NO_VECTOR) {
|
||||
+ kvm_virtio_pci_vector_use_one(proxy, queue_no);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy,
|
||||
uint8_t bar, uint64_t offset, uint64_t length,
|
||||
uint8_t id)
|
||||
@@ -1570,7 +1602,8 @@ static void virtio_pci_common_write(void *opaque, hwaddr addr,
|
||||
} else {
|
||||
val = VIRTIO_NO_VECTOR;
|
||||
}
|
||||
- vdev->config_vector = val;
|
||||
+ virtio_pci_set_vector(vdev, proxy, VIRTIO_CONFIG_IRQ_IDX,
|
||||
+ vdev->config_vector, val);
|
||||
break;
|
||||
case VIRTIO_PCI_COMMON_STATUS:
|
||||
if (!(val & VIRTIO_CONFIG_S_DRIVER_OK)) {
|
||||
@@ -1610,7 +1643,7 @@ static void virtio_pci_common_write(void *opaque, hwaddr addr,
|
||||
} else {
|
||||
val = VIRTIO_NO_VECTOR;
|
||||
}
|
||||
- virtio_queue_set_vector(vdev, vdev->queue_sel, val);
|
||||
+ virtio_pci_set_vector(vdev, proxy, vdev->queue_sel, vector, val);
|
||||
break;
|
||||
case VIRTIO_PCI_COMMON_Q_ENABLE:
|
||||
if (val == 1) {
|
||||
--
|
||||
2.39.3
|
||||
|
@ -149,7 +149,7 @@ Obsoletes: %{name}-block-ssh <= %{epoch}:%{version} \
|
||||
Summary: QEMU is a machine emulator and virtualizer
|
||||
Name: qemu-kvm
|
||||
Version: 8.2.0
|
||||
Release: 11%{?rcrel}%{?dist}%{?cc_suffix}
|
||||
Release: 11%{?rcrel}%{?dist}%{?cc_suffix}.3
|
||||
# Epoch because we pushed a qemu-1.0 package. AIUI this can't ever be dropped
|
||||
# Epoch 15 used for RHEL 8
|
||||
# Epoch 17 used for RHEL 9 (due to release versioning offset in RHEL 8.5)
|
||||
@ -610,6 +610,18 @@ Patch175: kvm-Revert-chardev-use-a-child-source-for-qio-input-sour.patch
|
||||
Patch176: kvm-coroutine-cap-per-thread-local-pool-size.patch
|
||||
# For RHEL-28947 - Qemu crashing with "failed to set up stack guard page: Cannot allocate memory"
|
||||
Patch177: kvm-coroutine-reserve-5-000-mappings.patch
|
||||
# For RHEL-32837 - qemu-kvm running Vyatta hits assert when doing KVM_SET_GSI_ROUTING [rhel-9.4.z]
|
||||
Patch178: kvm-virtio-pci-fix-use-of-a-released-vector.patch
|
||||
# For RHEL-32990 - qemu crash with kvm_irqchip_commit_routes: Assertion `ret == 0' failed if booting with many virtio disks and vcpus [rhel-9.4.z]
|
||||
Patch179: kvm-kvm-error-out-of-kvm_irqchip_add_msi_route-in-case-o.patch
|
||||
# For RHEL-33754 - Qemu hang when quit dst vm after storage migration(nbd+tls) [rhel-9.4.z]
|
||||
Patch180: kvm-nbd-server-do-not-poll-within-a-coroutine-context.patch
|
||||
# For RHEL-33754 - Qemu hang when quit dst vm after storage migration(nbd+tls) [rhel-9.4.z]
|
||||
Patch181: kvm-nbd-server-Mark-negotiation-functions-as-coroutine_f.patch
|
||||
# For RHEL-33754 - Qemu hang when quit dst vm after storage migration(nbd+tls) [rhel-9.4.z]
|
||||
Patch182: kvm-qio-Inherit-follow_coroutine_ctx-across-TLS.patch
|
||||
# For RHEL-33754 - Qemu hang when quit dst vm after storage migration(nbd+tls) [rhel-9.4.z]
|
||||
Patch183: kvm-iotests-test-NBD-TLS-iothread.patch
|
||||
|
||||
%if %{have_clang}
|
||||
BuildRequires: clang
|
||||
@ -1671,6 +1683,24 @@ useradd -r -u 107 -g qemu -G kvm -d / -s /sbin/nologin \
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Fri Jun 07 2024 Miroslav Rezanina <mrezanin@redhat.com> - 8.2.0-11.el9_4.3
|
||||
- kvm-nbd-server-do-not-poll-within-a-coroutine-context.patch [RHEL-33754]
|
||||
- kvm-nbd-server-Mark-negotiation-functions-as-coroutine_f.patch [RHEL-33754]
|
||||
- kvm-qio-Inherit-follow_coroutine_ctx-across-TLS.patch [RHEL-33754]
|
||||
- kvm-iotests-test-NBD-TLS-iothread.patch [RHEL-33754]
|
||||
- Resolves: RHEL-33754
|
||||
(Qemu hang when quit dst vm after storage migration(nbd+tls) [rhel-9.4.z])
|
||||
|
||||
* Mon May 20 2024 Miroslav Rezanina <mrezanin@redhat.com> - 8.2.0-11.el9_4.2
|
||||
- kvm-kvm-error-out-of-kvm_irqchip_add_msi_route-in-case-o.patch [RHEL-32990]
|
||||
- Resolves: RHEL-32990
|
||||
(qemu crash with kvm_irqchip_commit_routes: Assertion `ret == 0' failed if booting with many virtio disks and vcpus [rhel-9.4.z])
|
||||
|
||||
* Thu Apr 18 2024 Miroslav Rezanina <mrezanin@redhat.com> - 8.2.0-11.el9_4.1
|
||||
- kvm-virtio-pci-fix-use-of-a-released-vector.patch [RHEL-32837]
|
||||
- Resolves: RHEL-32837
|
||||
(qemu-kvm running Vyatta hits assert when doing KVM_SET_GSI_ROUTING [rhel-9.4.z])
|
||||
|
||||
* Tue Mar 26 2024 Miroslav Rezanina <mrezanin@redhat.com> - 8.2.0-11
|
||||
- kvm-coroutine-cap-per-thread-local-pool-size.patch [RHEL-28947]
|
||||
- kvm-coroutine-reserve-5-000-mappings.patch [RHEL-28947]
|
||||
|
Loading…
Reference in New Issue
Block a user