Skip to content

Commit df8a688

Browse files
iii-irth7680
authored andcommitted
cpus: Make {start,end}_exclusive() recursive
Currently dying to one of the core_dump_signal()s deadlocks, because dump_core_and_abort() calls start_exclusive() two times: first via stop_all_tasks(), and then via preexit_cleanup() -> qemu_plugin_user_exit(). There are a number of ways to solve this: resume after dumping core; check cpu_in_exclusive_context() in qemu_plugin_user_exit(); or make {start,end}_exclusive() recursive. Pick the last option, since it's the most straightforward one. Fixes: da91c19 ("linux-user: Clean up when exiting due to a signal") Reviewed-by: Richard Henderson <[email protected]> Reviewed-by: Alex Bennée <[email protected]> Signed-off-by: Ilya Leoshkevich <[email protected]> Message-Id: <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent 7de0816 commit df8a688

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

cpus-common.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ void start_exclusive(void)
192192
CPUState *other_cpu;
193193
int running_cpus;
194194

195+
if (current_cpu->exclusive_context_count) {
196+
current_cpu->exclusive_context_count++;
197+
return;
198+
}
199+
195200
qemu_mutex_lock(&qemu_cpu_list_lock);
196201
exclusive_idle();
197202

@@ -219,13 +224,16 @@ void start_exclusive(void)
219224
*/
220225
qemu_mutex_unlock(&qemu_cpu_list_lock);
221226

222-
current_cpu->in_exclusive_context = true;
227+
current_cpu->exclusive_context_count = 1;
223228
}
224229

225230
/* Finish an exclusive operation. */
226231
void end_exclusive(void)
227232
{
228-
current_cpu->in_exclusive_context = false;
233+
current_cpu->exclusive_context_count--;
234+
if (current_cpu->exclusive_context_count) {
235+
return;
236+
}
229237

230238
qemu_mutex_lock(&qemu_cpu_list_lock);
231239
qatomic_set(&pending_cpus, 0);

include/hw/core/cpu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ struct CPUState {
349349
bool unplug;
350350
bool crash_occurred;
351351
bool exit_request;
352-
bool in_exclusive_context;
352+
int exclusive_context_count;
353353
uint32_t cflags_next_tb;
354354
/* updates protected by BQL */
355355
uint32_t interrupt_request;
@@ -758,7 +758,7 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data
758758
*/
759759
static inline bool cpu_in_exclusive_context(const CPUState *cpu)
760760
{
761-
return cpu->in_exclusive_context;
761+
return cpu->exclusive_context_count;
762762
}
763763

764764
/**

0 commit comments

Comments
 (0)