[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 107/108] virtiofsd: stop all queue threads on exit in virtio_loop(
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PULL 107/108] virtiofsd: stop all queue threads on exit in virtio_loop() |
Date: |
Thu, 23 Jan 2020 16:46:29 +0000 |
From: Eryu Guan <address@hidden>
On guest graceful shutdown, virtiofsd receives VHOST_USER_GET_VRING_BASE
request from VMM and shuts down virtqueues by calling fv_set_started(),
which joins fv_queue_thread() threads. So when virtio_loop() returns,
there should be no thread is still accessing data in fuse session and/or
virtio dev.
But on abnormal exit, e.g. guest got killed for whatever reason,
vhost-user socket is closed and virtio_loop() breaks out the main loop
and returns to main(). But it's possible fv_queue_worker()s are still
working and accessing fuse session and virtio dev, which results in
crash or use-after-free.
Fix it by stopping fv_queue_thread()s before virtio_loop() returns,
to make sure there's no-one could access fuse session and virtio dev.
Reported-by: Qingming Su <address@hidden>
Signed-off-by: Eryu Guan <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
tools/virtiofsd/fuse_virtio.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
index 9f6582343c..80a6e929df 100644
--- a/tools/virtiofsd/fuse_virtio.c
+++ b/tools/virtiofsd/fuse_virtio.c
@@ -815,6 +815,19 @@ int virtio_loop(struct fuse_session *se)
}
}
+ /*
+ * Make sure all fv_queue_thread()s quit on exit, as we're about to
+ * free virtio dev and fuse session, no one should access them anymore.
+ */
+ for (int i = 0; i < se->virtio_dev->nqueues; i++) {
+ if (!se->virtio_dev->qi[i]) {
+ continue;
+ }
+
+ fuse_log(FUSE_LOG_INFO, "%s: Stopping queue %d thread\n", __func__, i);
+ fv_queue_cleanup_thread(se->virtio_dev, i);
+ }
+
fuse_log(FUSE_LOG_INFO, "%s: Exit\n", __func__);
return 0;
--
2.24.1
- [PULL 098/108] virtiofsd: passthrough_ll: Use cache_readdir for directory open, (continued)
- [PULL 098/108] virtiofsd: passthrough_ll: Use cache_readdir for directory open, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 099/108] virtiofsd: add definition of fuse_buf_writev(), Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 100/108] virtiofsd: use fuse_buf_writev to replace fuse_buf_write for better performance, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 105/108] virtiofsd: Convert lo_destroy to take the lo->mutex lock itself, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 102/108] virtiofsd: prevent FUSE_INIT/FUSE_DESTROY races, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 101/108] virtiofsd: process requests in a thread pool, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 106/108] virtiofsd/passthrough_ll: Pass errno to fuse_reply_err(), Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 104/108] virtiofsd: add --thread-pool-size=NUM option, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 108/108] virtiofsd: add some options to the help message, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 103/108] virtiofsd: fix lo_destroy() resource leaks, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 107/108] virtiofsd: stop all queue threads on exit in virtio_loop(),
Dr. David Alan Gilbert (git) <=
- Re: [PULL 000/108] virtiofs queue, Dr. David Alan Gilbert, 2020/01/23
- Re: [PULL 000/108] virtiofs queue, no-reply, 2020/01/23