[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/12] linux-user: properly "unrealize" vCPU object
From: |
Alex Bennée |
Subject: |
[PULL 11/12] linux-user: properly "unrealize" vCPU object |
Date: |
Wed, 27 May 2020 15:54:54 +0100 |
We shouldn't be messing around with the CPU list in linux-user save
for the very special case of do_fork(). When threads end we need to
properly follow QOM object lifetime handling and allow the eventual
cpu_common_unrealizefn to both remove the CPU and ensure any clean-up
actions are taken place, for example calling plugin exit hooks.
There is still a race condition to avoid so use the linux-user
specific clone_lock instead of the cpu_list_lock to avoid it.
Signed-off-by: Alex Bennée <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Cc: Nikolay Igotti <address@hidden>
Cc: Paolo Bonzini <address@hidden>
Cc: Daniel P. Berrange <address@hidden>
Cc: Eduardo Habkost <address@hidden>
Cc: Markus Armbruster <address@hidden>
Message-Id: <address@hidden>
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 05f03919ff0..7f6700c54e3 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7635,30 +7635,33 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
return -TARGET_ERESTARTSYS;
}
- cpu_list_lock();
+ pthread_mutex_lock(&clone_lock);
if (CPU_NEXT(first_cpu)) {
- TaskState *ts;
+ TaskState *ts = cpu->opaque;
- /* Remove the CPU from the list. */
- QTAILQ_REMOVE_RCU(&cpus, cpu, node);
+ object_property_set_bool(OBJECT(cpu), false, "realized", NULL);
+ object_unref(OBJECT(cpu));
+ /*
+ * At this point the CPU should be unrealized and removed
+ * from cpu lists. We can clean-up the rest of the thread
+ * data without the lock held.
+ */
- cpu_list_unlock();
+ pthread_mutex_unlock(&clone_lock);
- ts = cpu->opaque;
if (ts->child_tidptr) {
put_user_u32(0, ts->child_tidptr);
do_sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
NULL, NULL, 0);
}
thread_cpu = NULL;
- object_unref(OBJECT(cpu));
g_free(ts);
rcu_unregister_thread();
pthread_exit(NULL);
}
- cpu_list_unlock();
+ pthread_mutex_unlock(&clone_lock);
preexit_cleanup(cpu_env, arg1);
_exit(arg1);
return 0; /* avoid warning */
--
2.20.1
- [PULL 02/12] tests/vm: pass --genisoimage to basevm script, (continued)
- [PULL 02/12] tests/vm: pass --genisoimage to basevm script, Alex Bennée, 2020/05/27
- [PULL 04/12] tests/tcg: fix invocation of the memory record/replay tests, Alex Bennée, 2020/05/27
- [PULL 05/12] tests/fp: enable extf80_le_quite tests, Alex Bennée, 2020/05/27
- [PULL 03/12] travis.yml: Use clang++ in the Clang tests, Alex Bennée, 2020/05/27
- [PULL 08/12] tests/docker: add debian11 base image, Alex Bennée, 2020/05/27
- [PULL 06/12] tests/fp: split and audit the conversion tests, Alex Bennée, 2020/05/27
- [PULL 07/12] tests/tcg: better detect confused gdb which can't connect, Alex Bennée, 2020/05/27
- [PULL 09/12] tests/docker: use a gcc-10 based image for arm64 tests, Alex Bennée, 2020/05/27
- [PULL 12/12] tests/tcg: add new threadcount test, Alex Bennée, 2020/05/27
- [PULL 10/12] cpus-common: ensure auto-assigned cpu_indexes don't clash, Alex Bennée, 2020/05/27
- [PULL 11/12] linux-user: properly "unrealize" vCPU object,
Alex Bennée <=
- Re: [PULL 00/12] testing and plugin fixes, Peter Maydell, 2020/05/28
- Re: [PULL 00/12] testing and plugin fixes, Alex Bennée, 2020/05/28
- Re: [PULL 00/12] testing and plugin fixes, Alex Bennée, 2020/05/28
- Re: [PULL 00/12] testing and plugin fixes, Peter Maydell, 2020/05/28
- Re: [PULL 00/12] testing and plugin fixes, Philippe Mathieu-Daudé, 2020/05/28
- Re: [PULL 00/12] testing and plugin fixes, Peter Maydell, 2020/05/28
- Re: [PULL 00/12] testing and plugin fixes, Philippe Mathieu-Daudé, 2020/05/28
- Re: [PULL 00/12] testing and plugin fixes, Peter Maydell, 2020/05/28
- Re: [PULL 00/12] testing and plugin fixes, Alex Bennée, 2020/05/28
- Re: [PULL 00/12] testing and plugin fixes, Gerd Hoffmann, 2020/05/28