[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/14] bsd-user: Sync fork_start/fork_end with linux-user
From: |
Warner Losh |
Subject: |
[PULL 11/14] bsd-user: Sync fork_start/fork_end with linux-user |
Date: |
Tue, 23 Jul 2024 12:07:22 -0600 |
From: Jessica Clarke <jrtc27@jrtc27.com>
This reorders some of the calls, deduplicates code between branches and,
most importantly, fixes a double end_exclusive call in the parent that
will cause exclusive_context_count to go negative.
Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
Pull-Request: https://github.com/qemu-bsd-user/qemu-bsd-user/pull/52
Reviewed-by: Warner Losh <imp@bsdimp.com>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/main.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 82e94a03160..cc980e6f401 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -35,6 +35,7 @@
#include "qemu/path.h"
#include "qemu/help_option.h"
#include "qemu/module.h"
+#include "qemu/plugin.h"
#include "exec/exec-all.h"
#include "user/guest-base.h"
#include "tcg/startup.h"
@@ -103,8 +104,9 @@ unsigned long target_sgrowsiz = TARGET_SGROWSIZ; /* amount
to grow stack */
void fork_start(void)
{
start_exclusive();
- cpu_list_lock();
mmap_fork_start();
+ cpu_list_lock();
+ qemu_plugin_user_prefork_lock();
gdbserver_fork_start();
}
@@ -112,31 +114,31 @@ void fork_end(pid_t pid)
{
bool child = pid == 0;
+ qemu_plugin_user_postfork(child);
+ mmap_fork_end(child);
if (child) {
CPUState *cpu, *next_cpu;
/*
- * Child processes created by fork() only have a single thread.
Discard
- * information about the parent threads.
+ * Child processes created by fork() only have a single thread.
+ * Discard information about the parent threads.
*/
CPU_FOREACH_SAFE(cpu, next_cpu) {
if (cpu != thread_cpu) {
QTAILQ_REMOVE_RCU(&cpus_queue, cpu, node);
}
}
- mmap_fork_end(child);
- /*
- * qemu_init_cpu_list() takes care of reinitializing the exclusive
- * state, so we don't need to end_exclusive() here.
- */
qemu_init_cpu_list();
get_task_state(thread_cpu)->ts_tid = qemu_get_thread_id();
- gdbserver_fork_end(thread_cpu, pid);
} else {
- mmap_fork_end(child);
cpu_list_unlock();
- gdbserver_fork_end(thread_cpu, pid);
- end_exclusive();
}
+ gdbserver_fork_end(thread_cpu, pid);
+ /*
+ * qemu_init_cpu_list() reinitialized the child exclusive state, but we
+ * also need to keep current_cpu consistent, so call end_exclusive() for
+ * both child and parent.
+ */
+ end_exclusive();
}
void cpu_loop(CPUArchState *env)
--
2.45.1
- [PULL 00/14] Bsd user for 9.1 patches, Warner Losh, 2024/07/23
- [PULL 01/14] bsd-user:Add CPU initialization and management functions, Warner Losh, 2024/07/23
- [PULL 03/14] bsd-user:Add ARM AArch64 support and capabilities, Warner Losh, 2024/07/23
- [PULL 06/14] bsd-user:Add setup_sigframe_arch function for ARM AArch64, Warner Losh, 2024/07/23
- [PULL 11/14] bsd-user: Sync fork_start/fork_end with linux-user,
Warner Losh <=
- [PULL 05/14] bsd-user:Add get_mcontext function for ARM AArch64, Warner Losh, 2024/07/23
- [PULL 09/14] bsd-user: Simplify the implementation of execve, Warner Losh, 2024/07/23
- [PULL 04/14] bsd-user:Add ARM AArch64 signal handling support, Warner Losh, 2024/07/23
- [PULL 10/14] bsd-user: Hard wire aarch64 to be 4k pages only, Warner Losh, 2024/07/23
- [PULL 07/14] bsd-user:Add set_mcontext function for ARM AArch64, Warner Losh, 2024/07/23
- [PULL 13/14] bsd-user: Make compile for non-linux user-mode stuff, Warner Losh, 2024/07/23
- [PULL 02/14] bsd-user:Add AArch64 register handling and related functions, Warner Losh, 2024/07/23
- [PULL 08/14] bsd-user:Add AArch64 improvements and signal handling functions, Warner Losh, 2024/07/23
- [PULL 12/14] bsd-user: Define TARGET_SIGSTACK_ALIGN and use it to round stack, Warner Losh, 2024/07/23
- [PULL 14/14] bsd-user: Add aarch64 build to tree, Warner Losh, 2024/07/23