qemu-e2k/accel/tcg
Emilio Cota 1ff4a81bd3 tcg: use QTree instead of GTree
qemu-user can hang in a multi-threaded fork. One common
reason is that when creating a TB, between fork and exec
we manipulate a GTree whose memory allocator (GSlice) is
not fork-safe.

Although POSIX does not mandate it, the system's allocator
(e.g. tcmalloc, libc malloc) is probably fork-safe.

Fix some of these hangs by using QTree, which uses the system's
allocator regardless of the Glib version that we used at
configuration time.

Tested with the test program in the original bug report, i.e.:
```

void garble() {
  int pid = fork();
  if (pid == 0) {
    exit(0);
  } else {
    int wstatus;
    waitpid(pid, &wstatus, 0);
  }
}

void supragarble(unsigned depth) {
  if (depth == 0)
    return ;

  std::thread a(supragarble, depth-1);
  std::thread b(supragarble, depth-1);
  garble();
  a.join();
  b.join();
}

int main() {
  supragarble(10);
}
```

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/285
Reported-by: Valentin David <me@valentindavid.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Emilio Cota <cota@braap.org>
Message-Id: <20230205163758.416992-3-cota@braap.org>
[rth: Add QEMU_DISABLE_CFI for all callback using functions.]
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2023-03-28 15:23:10 -07:00
..
atomic_common.c.inc tcg: Add tcg_gen_{non}atomic_cmpxchg_i128 2023-02-04 06:19:42 -10:00
atomic_template.h Replace config-time define HOST_WORDS_BIGENDIAN 2022-04-06 10:50:37 +02:00
cpu-exec-common.c *: Add missing includes of qemu/plugin.h 2023-03-22 15:06:57 +00:00
cpu-exec.c tcg: Clear plugin_mem_cbs on TB exit 2023-03-22 15:06:57 +00:00
cputlb.c accel/tcg: Trigger watchpoints from atomic_mmu_lookup 2023-03-05 13:44:07 -08:00
debuginfo.c accel/tcg: Add debuginfo support 2023-01-16 10:14:12 -10:00
debuginfo.h coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h 2023-01-20 07:21:46 +01:00
internal.h accel/tcg: Replace tb_pc() with tb->pc 2023-03-01 07:33:05 -10:00
ldst_common.c.inc exec/memop: Adding signedness to quad definitions 2022-01-08 15:46:10 +10:00
meson.build accel/tcg: Restrict 'qapi-commands-machine.h' to system emulation 2023-02-27 22:29:01 +01:00
monitor.c accel/tcg: Restrict 'qapi-commands-machine.h' to system emulation 2023-02-27 22:29:01 +01:00
perf.c accel/tcg: Replace TARGET_TB_PCREL with CF_PCREL 2023-03-01 07:31:44 -10:00
perf.h tcg: add perfmap and jitdump 2023-01-16 10:14:12 -10:00
plugin-gen.c tcg: Create tcg/tcg-temp-internal.h 2023-03-13 06:42:05 -07:00
plugin-helpers.h tcg: exclude non-memory effecting helpers from instrumentation 2023-02-02 11:48:20 +00:00
tb-context.h tcg: Move tb_phys_invalidate_count to tb_ctx 2021-07-09 09:38:33 -07:00
tb-hash.h include/hw/core: Create struct CPUJumpCache 2022-10-04 12:13:12 -07:00
tb-jmp-cache.h accel/tcg: Move jmp-cache CF_PCREL checks to caller 2023-03-01 07:33:03 -10:00
tb-maint.c tcg: use QTree instead of GTree 2023-03-28 15:23:10 -07:00
tcg-accel-ops-icount.c icount: Take iothread lock when running QEMU timers 2022-08-09 10:55:14 +01:00
tcg-accel-ops-icount.h Clean up header guards that don't match their file name 2022-05-11 16:49:06 +02:00
tcg-accel-ops-mttcg.c Revert "accel/tcg: Init TCG cflags in vCPU thread handler" 2022-10-25 22:01:14 +10:00
tcg-accel-ops-mttcg.h Clean up header guards that don't match their file name 2022-05-11 16:49:06 +02:00
tcg-accel-ops-rr.c Revert incorrect cflags initialization. 2022-10-26 10:53:41 -04:00
tcg-accel-ops-rr.h Clean up header guards that don't match their file name 2022-05-11 16:49:06 +02:00
tcg-accel-ops.c tcg: Include "qemu/timer.h" for profile_getclock 2023-03-05 13:44:07 -08:00
tcg-accel-ops.h Clean up header guards that don't match their file name 2022-05-11 16:49:06 +02:00
tcg-all.c replay: Extract core API to 'exec/replay-core.h' 2023-02-27 22:29:01 +01:00
tcg-runtime-gvec.c accel/tcg: Use add/sub overflow routines in tcg-runtime-gvec.c 2021-05-16 07:13:51 -05:00
tcg-runtime.c accel/tcg: Move helper_lookup_tb_ptr to cpu-exec.c 2021-07-09 20:23:06 -07:00
tcg-runtime.h tcg: Add tcg_gen_{non}atomic_cmpxchg_i128 2023-02-04 06:19:42 -10:00
trace-events accel/tcg: Remove trace events from trace-root.h 2022-12-20 17:11:12 -08:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
translate-all.c includes: move tb_flush into its own header 2023-03-07 17:06:33 +00:00
translator.c accel/tcg: Remove translator_loop_temp_check 2023-03-05 13:44:07 -08:00
user-exec-stub.c replay: Extract core API to 'exec/replay-core.h' 2023-02-27 22:29:01 +01:00
user-exec.c accel/tcg: Add 'size' param to probe_access_flags() 2023-02-28 10:32:31 -10:00