[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 72/78] 9p: Lock directory streams with a CoMutex
From: |
Michael Roth |
Subject: |
[PATCH 72/78] 9p: Lock directory streams with a CoMutex |
Date: |
Tue, 16 Jun 2020 09:15:41 -0500 |
From: Greg Kurz <groug@kaod.org>
Locking was introduced in QEMU 2.7 to address the deprecation of
readdir_r(3) in glibc 2.24. It turns out that the frontend code is
the worst place to handle a critical section with a pthread mutex:
the code runs in a coroutine on behalf of the QEMU mainloop and then
yields control, waiting for the fsdev backend to process the request
in a worker thread. If the client resends another readdir request for
the same fid before the previous one finally unlocked the mutex, we're
deadlocked.
This never bit us because the linux client serializes readdir requests
for the same fid, but it is quite easy to demonstrate with a custom
client.
A good solution could be to narrow the critical section in the worker
thread code and to return a copy of the dirent to the frontend, but
this causes quite some changes in both 9p.c and codir.c. So, instead
of that, in order for people to easily backport the fix to older QEMU
versions, let's simply use a CoMutex since all the users for this
sit in coroutines.
Fixes: 7cde47d4a89d ("9p: add locking to V9fsDir")
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Message-Id: <158981894794.109297.3530035833368944254.stgit@bahia.lan>
Signed-off-by: Greg Kurz <groug@kaod.org>
(cherry picked from commit ed463454efd0ac3042ff772bfe1b1d846dc281a5)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
hw/9pfs/9p.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
index 3904f82901..069c86333f 100644
--- a/hw/9pfs/9p.h
+++ b/hw/9pfs/9p.h
@@ -186,22 +186,22 @@ typedef struct V9fsXattr
typedef struct V9fsDir {
DIR *stream;
- QemuMutex readdir_mutex;
+ CoMutex readdir_mutex;
} V9fsDir;
static inline void v9fs_readdir_lock(V9fsDir *dir)
{
- qemu_mutex_lock(&dir->readdir_mutex);
+ qemu_co_mutex_lock(&dir->readdir_mutex);
}
static inline void v9fs_readdir_unlock(V9fsDir *dir)
{
- qemu_mutex_unlock(&dir->readdir_mutex);
+ qemu_co_mutex_unlock(&dir->readdir_mutex);
}
static inline void v9fs_readdir_init(V9fsDir *dir)
{
- qemu_mutex_init(&dir->readdir_mutex);
+ qemu_co_mutex_init(&dir->readdir_mutex);
}
/*
--
2.17.1
- [PATCH 63/78] hw/i386/amd_iommu.c: Fix corruption of log events passed to guest, (continued)
- [PATCH 63/78] hw/i386/amd_iommu.c: Fix corruption of log events passed to guest, Michael Roth, 2020/06/16
- [PATCH 64/78] tcg/i386: Fix INDEX_op_dup2_vec, Michael Roth, 2020/06/16
- [PATCH 65/78] dump: Fix writing of ELF section, Michael Roth, 2020/06/16
- [PATCH 66/78] xen-block: Fix double qlist remove and request leak, Michael Roth, 2020/06/16
- [PATCH 67/78] vhost-user-gpu: Release memory returned by vu_queue_pop() with free(), Michael Roth, 2020/06/16
- [PATCH 68/78] target/ppc: Fix mtmsr(d) L=1 variant that loses interrupts, Michael Roth, 2020/06/16
- [PATCH 69/78] hostmem: don't use mbind() if host-nodes is empty, Michael Roth, 2020/06/16
- [PATCH 70/78] target/arm: Clear tail in gvec_fmul_idx_*, gvec_fmla_idx_*, Michael Roth, 2020/06/16
- [PATCH 06/78] block: Activate recursively even for already active nodes, Michael Roth, 2020/06/16
- [PATCH 71/78] qemu-nbd: Close inherited stderr, Michael Roth, 2020/06/16
- [PATCH 72/78] 9p: Lock directory streams with a CoMutex,
Michael Roth <=
[PATCH 73/78] net: Do not include a newline in the id of -nic devices, Michael Roth, 2020/06/16
[PATCH 75/78] virtio-balloon: fix free page hinting without an iothread, Michael Roth, 2020/06/16
[PATCH 76/78] virtio-balloon: fix free page hinting check on unrealize, Michael Roth, 2020/06/16
[PATCH 74/78] nbd/server: Avoid long error message assertions CVE-2020-10761, Michael Roth, 2020/06/16
[PATCH 77/78] virtio-balloon: unref the iothread when unrealizing, Michael Roth, 2020/06/16