Ai
1 Star 0 Fork 146

clockguo/qemu

forked from src-openEuler/qemu
关闭
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
plugins-make-qemu_plugin_user_exit-s-locking-order-c.patch 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
XuFei 提交于 2023-04-22 21:43 +08:00 . QEMU update to version 6.2.0-71(master)
From a729d2730d9d30f6610e43f070cedd1d60ba022f Mon Sep 17 00:00:00 2001
From: qihao <qihao@cmss.chinamobile.com>
Date: Thu, 30 Mar 2023 17:58:32 +0800
Subject: [PATCH] plugins: make qemu_plugin_user_exit's locking order
consistent with fork_start's
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
cheery-pick from 2bbbc1be8d9a21b25d0c80b9a7345074d54abd51
To fix potential deadlocks as reported by tsan.
Signed-off-by: qihao_yewu <qihao_yewu@cmss.chinamobile.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Emilio Cota <cota@braap.org>
Message-Id: <20230111151628.320011-6-cota@braap.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230124180127.1881110-31-alex.bennee@linaro.org>
---
plugins/core.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/plugins/core.c b/plugins/core.c
index 792262da08..e935e3c0c9 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -500,10 +500,18 @@ void qemu_plugin_user_exit(void)
enum qemu_plugin_event ev;
CPUState *cpu;
- QEMU_LOCK_GUARD(&plugin.lock);
+ /*
+ * Locking order: we must acquire locks in an order that is consistent
+ * with the one in fork_start(). That is:
+ * - start_exclusive(), which acquires qemu_cpu_list_lock,
+ * must be called before acquiring plugin.lock.
+ * - tb_flush(), which acquires mmap_lock(), must be called
+ * while plugin.lock is not held.
+ */
start_exclusive();
+ qemu_rec_mutex_lock(&plugin.lock);
/* un-register all callbacks except the final AT_EXIT one */
for (ev = 0; ev < QEMU_PLUGIN_EV_MAX; ev++) {
if (ev != QEMU_PLUGIN_EV_ATEXIT) {
@@ -514,12 +522,12 @@ void qemu_plugin_user_exit(void)
}
}
- tb_flush(current_cpu);
-
CPU_FOREACH(cpu) {
qemu_plugin_disable_mem_helpers(cpu);
}
+ qemu_rec_mutex_unlock(&plugin.lock);
+ tb_flush(current_cpu);
end_exclusive();
/* now it's safe to handle the exit case */
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/JianguoZhang/qemu.git
git@gitee.com:JianguoZhang/qemu.git
JianguoZhang
qemu
qemu
master

搜索帮助