|
|
ddf19c |
From 06a24b54c94345b436d888a48b92fafa967c3d58 Mon Sep 17 00:00:00 2001
|
|
|
ddf19c |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
ddf19c |
Date: Mon, 27 Jan 2020 19:02:25 +0100
|
|
|
ddf19c |
Subject: [PATCH 114/116] virtiofsd: stop all queue threads on exit in
|
|
|
ddf19c |
virtio_loop()
|
|
|
ddf19c |
MIME-Version: 1.0
|
|
|
ddf19c |
Content-Type: text/plain; charset=UTF-8
|
|
|
ddf19c |
Content-Transfer-Encoding: 8bit
|
|
|
ddf19c |
|
|
|
ddf19c |
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ddf19c |
Message-id: <20200127190227.40942-111-dgilbert@redhat.com>
|
|
|
ddf19c |
Patchwork-id: 93564
|
|
|
ddf19c |
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 110/112] virtiofsd: stop all queue threads on exit in virtio_loop()
|
|
|
ddf19c |
Bugzilla: 1694164
|
|
|
ddf19c |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
ddf19c |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ddf19c |
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
|
|
|
ddf19c |
|
|
|
ddf19c |
From: Eryu Guan <eguan@linux.alibaba.com>
|
|
|
ddf19c |
|
|
|
ddf19c |
On guest graceful shutdown, virtiofsd receives VHOST_USER_GET_VRING_BASE
|
|
|
ddf19c |
request from VMM and shuts down virtqueues by calling fv_set_started(),
|
|
|
ddf19c |
which joins fv_queue_thread() threads. So when virtio_loop() returns,
|
|
|
ddf19c |
there should be no thread is still accessing data in fuse session and/or
|
|
|
ddf19c |
virtio dev.
|
|
|
ddf19c |
|
|
|
ddf19c |
But on abnormal exit, e.g. guest got killed for whatever reason,
|
|
|
ddf19c |
vhost-user socket is closed and virtio_loop() breaks out the main loop
|
|
|
ddf19c |
and returns to main(). But it's possible fv_queue_worker()s are still
|
|
|
ddf19c |
working and accessing fuse session and virtio dev, which results in
|
|
|
ddf19c |
crash or use-after-free.
|
|
|
ddf19c |
|
|
|
ddf19c |
Fix it by stopping fv_queue_thread()s before virtio_loop() returns,
|
|
|
ddf19c |
to make sure there's no-one could access fuse session and virtio dev.
|
|
|
ddf19c |
|
|
|
ddf19c |
Reported-by: Qingming Su <qingming.su@linux.alibaba.com>
|
|
|
ddf19c |
Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
|
|
|
ddf19c |
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ddf19c |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ddf19c |
(cherry picked from commit 9883df8ccae6d744a0c8d9cbf9d62b1797d70ebd)
|
|
|
ddf19c |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
ddf19c |
---
|
|
|
ddf19c |
tools/virtiofsd/fuse_virtio.c | 13 +++++++++++++
|
|
|
ddf19c |
1 file changed, 13 insertions(+)
|
|
|
ddf19c |
|
|
|
ddf19c |
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
|
|
|
ddf19c |
index 9f65823..80a6e92 100644
|
|
|
ddf19c |
--- a/tools/virtiofsd/fuse_virtio.c
|
|
|
ddf19c |
+++ b/tools/virtiofsd/fuse_virtio.c
|
|
|
ddf19c |
@@ -815,6 +815,19 @@ int virtio_loop(struct fuse_session *se)
|
|
|
ddf19c |
}
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
+ /*
|
|
|
ddf19c |
+ * Make sure all fv_queue_thread()s quit on exit, as we're about to
|
|
|
ddf19c |
+ * free virtio dev and fuse session, no one should access them anymore.
|
|
|
ddf19c |
+ */
|
|
|
ddf19c |
+ for (int i = 0; i < se->virtio_dev->nqueues; i++) {
|
|
|
ddf19c |
+ if (!se->virtio_dev->qi[i]) {
|
|
|
ddf19c |
+ continue;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_INFO, "%s: Stopping queue %d thread\n", __func__, i);
|
|
|
ddf19c |
+ fv_queue_cleanup_thread(se->virtio_dev, i);
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+
|
|
|
ddf19c |
fuse_log(FUSE_LOG_INFO, "%s: Exit\n", __func__);
|
|
|
ddf19c |
|
|
|
ddf19c |
return 0;
|
|
|
ddf19c |
--
|
|
|
ddf19c |
1.8.3.1
|
|
|
ddf19c |
|