mbox series

[0/3] linux-user: Call tcg_flush_jmp_cache() before re-using threads

Message ID 20250102182521.65428-1-philmd@linaro.org
Headers show
Series linux-user: Call tcg_flush_jmp_cache() before re-using threads | expand

Message

Philippe Mathieu-Daudé Jan. 2, 2025, 6:25 p.m. UTC
Fix a bug reported by Ilya in:
https://lore.kernel.org/qemu-devel/uuuk6a2vo24yrrqrchjxaeko3utqshrdu6txcnqziokpg7dkom@4l4kd3dqh6jc/

Commit bb6cf6f0168 ("accel/tcg: Factor tcg_cpu_reset_hold()
out") wanted to restrict tlb_flush() to system emulation,
but inadvertently also restricted tcg_flush_jmp_cache(),
which was before called on user emulation via:

  Realize -> Reset -> cpu_common_reset_hold()

Since threads (vCPUs) use a common CPUJumpCache, when many
threads are created / joined, they eventually end re-using
a CPUJumpCache entry, which was cleared when the first vCPU
was allocated (via Realize) but then stayed dirty.

Have cpu_exec_reset_hold() call the common tcg_exec_reset()
helper on user emulation, eventually calling tcg_flush_jmp_cache().

Philippe Mathieu-Daudé (3):
  linux-user: Only include 'exec/tb-flush.h' header when necessary
  accel/tcg: Factor out common tcg_exec_reset() helper
  accel/tcg: Implement cpu_exec_reset_hold() on user emulation

 accel/tcg/internal-common.h | 1 +
 linux-user/user-internals.h | 1 -
 accel/tcg/cpu-exec-common.c | 6 ++++++
 accel/tcg/tcg-accel-ops.c   | 4 ++--
 accel/tcg/user-exec-stub.c  | 4 ----
 accel/tcg/user-exec.c       | 5 +++++
 linux-user/mmap.c           | 1 +
 linux-user/syscall.c        | 1 +
 8 files changed, 16 insertions(+), 7 deletions(-)