[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 5/8] gdbstub: handle a potentially racing TaskState
From: |
Alex Bennée |
Subject: |
[PULL 5/8] gdbstub: handle a potentially racing TaskState |
Date: |
Mon, 29 Nov 2021 17:14:46 +0000 |
When dealing with multi-threaded userspace programs there is a race
condition with the addition of cpu->opaque (aka TaskState). This is
due to cpu_copy calling cpu_create which updates the global vCPU list.
However the task state isn't set until later. This shouldn't be a
problem because the new thread can't have executed anything yet but
the gdbstub code does liberally iterate through the CPU list in
various places.
This sticking plaster ensure the not yet fully realized vCPU is given
an pid of -1 which should be enough to ensure it doesn't show up
anywhere else.
In the longer term I think the code that manages the association
between vCPUs and attached GDB processes could do with a clean-up and
re-factor.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Cc: Richard Henderson <richard.henderson@linaro.org>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/730
Message-Id: <20211129140932.4115115-6-alex.bennee@linaro.org>
diff --git a/gdbstub.c b/gdbstub.c
index 23baaef40e..141d7bc4ec 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -94,7 +94,7 @@ static inline int cpu_gdb_index(CPUState *cpu)
{
#if defined(CONFIG_USER_ONLY)
TaskState *ts = (TaskState *) cpu->opaque;
- return ts->ts_tid;
+ return ts ? ts->ts_tid : -1;
#else
return cpu->cpu_index + 1;
#endif
--
2.30.2
- [PULL for 6.2 0/8] more tcg, plugin, test and build fixes, Alex Bennée, 2021/11/29
- [PULL 1/8] accel/tcg: introduce CF_NOIRQ, Alex Bennée, 2021/11/29
- [PULL 2/8] accel/tcg: suppress IRQ check for special TBs, Alex Bennée, 2021/11/29
- [PULL 4/8] plugins/meson.build: fix linker issue with weird paths, Alex Bennée, 2021/11/29
- [PULL 5/8] gdbstub: handle a potentially racing TaskState,
Alex Bennée <=
- [PULL 3/8] tests/avocado: fix tcg_plugin mem access count test, Alex Bennée, 2021/11/29
- [PULL 6/8] MAINTAINERS: Remove me as a reviewer for the build and test/avocado, Alex Bennée, 2021/11/29
- [PULL 7/8] MAINTAINERS: Add section for Aarch64 GitLab custom runner, Alex Bennée, 2021/11/29
- [PULL 8/8] tests/plugin/syscall.c: fix compiler warnings, Alex Bennée, 2021/11/29
- Re: [PULL for 6.2 0/8] more tcg, plugin, test and build fixes, Richard Henderson, 2021/11/29