accel/tcg: Call tcg_flush_jmp_cache() again when creating user-mode cpu
v2 cover accel/tcg: Call tcg_flush_jmp_cache() again when creating user-mode cpu
Since v1:
- Dropped patch #1 (use meson subdir_done)
Fix a bug introduced during a refactor in commit bb6cf6f016 ("accel/tcg: Factor tcg_cpu_reset_hold() out"), affecting user emulation. (cpu_reset is called during thread creation, after cpu_realize).
This issue was noticed by Ilya when running WASM:
https://lore.kernel.org/qemu-devel/20221027141856.w5umjgklawgu7pqv@heavy/
Philippe Mathieu-Daudé (4):
accel/tcg: Move system emulation files under sysemu/ subdirectory accel/tcg: Do not define cpu_exec_reset_hold() as stub accel/tcg: Introduce common tcg_exec_cpu_reset_hold() method accel/tcg: Always call tcg_flush_jmp_cache() on reset
accel/tcg/internal-common.h | 2 ++
accel/tcg/{ => sysemu}/tcg-accel-ops-icount.h | 0
accel/tcg/{ => sysemu}/tcg-accel-ops-mttcg.h | 0
accel/tcg/{ => sysemu}/tcg-accel-ops-rr.h | 0
accel/tcg/{ => sysemu}/tcg-accel-ops.h | 0
accel/tcg/cpu-exec.c | 6 ++++++
accel/tcg/{ => sysemu}/icount-common.c | 0
accel/tcg/{ => sysemu}/monitor.c | 4 ++--
accel/tcg/{ => sysemu}/tcg-accel-ops-icount.c | 0
accel/tcg/{ => sysemu}/tcg-accel-ops-mttcg.c | 0
accel/tcg/{ => sysemu}/tcg-accel-ops-rr.c | 0
accel/tcg/{ => sysemu}/tcg-accel-ops.c | 5 ++---
accel/tcg/translate-all.c | 5 -----
accel/tcg/user-exec-stub.c | 4 ----
accel/tcg/user-exec.c | 5 +++++
accel/tcg/meson.build | 14 ++------------
accel/tcg/sysemu/meson.build | 11 +++++++++++
17 files changed, 30 insertions(+), 26 deletions(-)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-icount.h (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-mttcg.h (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-rr.h (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops.h (100%)
rename accel/tcg/{ => sysemu}/icount-common.c (100%)
rename accel/tcg/{ => sysemu}/monitor.c (99%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-icount.c (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-mttcg.c (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-rr.c (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops.c (99%)
create mode 100644 accel/tcg/sysemu/meson.buildSignature · 1 line
2.41.0
PATCH v2 1/4 accel/tcg: Move system emulation files under sysemu/ subdirectory
Some files are specific to system emulation. Move them under their own sysemu/ directory. This might help to notice what is affected (user, system or both) when doing global refactors.
---
accel/tcg/{ => sysemu}/tcg-accel-ops-icount.h | 0
accel/tcg/{ => sysemu}/tcg-accel-ops-mttcg.h | 0
accel/tcg/{ => sysemu}/tcg-accel-ops-rr.h | 0
accel/tcg/{ => sysemu}/tcg-accel-ops.h | 0
accel/tcg/{ => sysemu}/icount-common.c | 0
accel/tcg/{ => sysemu}/monitor.c | 4 ++--
accel/tcg/{ => sysemu}/tcg-accel-ops-icount.c | 0
accel/tcg/{ => sysemu}/tcg-accel-ops-mttcg.c | 0
accel/tcg/{ => sysemu}/tcg-accel-ops-rr.c | 0
accel/tcg/{ => sysemu}/tcg-accel-ops.c | 0
accel/tcg/meson.build | 14 ++------------
accel/tcg/sysemu/meson.build | 11 +++++++++++
12 files changed, 15 insertions(+), 14 deletions(-)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-icount.h (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-mttcg.h (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-rr.h (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops.h (100%)
rename accel/tcg/{ => sysemu}/icount-common.c (100%)
rename accel/tcg/{ => sysemu}/monitor.c (99%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-icount.c (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-mttcg.c (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops-rr.c (100%)
rename accel/tcg/{ => sysemu}/tcg-accel-ops.c (100%)
create mode 100644 accel/tcg/sysemu/meson.buildaccel/tcg/sysemu/tcg-accel-ops-icount.h renamed from accel/tcg/tcg-accel-ops-icount.h +0 -0
accel/tcg/sysemu/tcg-accel-ops-mttcg.h renamed from accel/tcg/tcg-accel-ops-mttcg.h +0 -0
accel/tcg/sysemu/tcg-accel-ops-rr.h renamed from accel/tcg/tcg-accel-ops-rr.h +0 -0
accel/tcg/sysemu/tcg-accel-ops.h renamed from accel/tcg/tcg-accel-ops.h +0 -0
accel/tcg/sysemu/icount-common.c renamed from accel/tcg/icount-common.c +0 -0
accel/tcg/sysemu/monitor.c renamed from accel/tcg/monitor.c +2 -2
@@ -17,8 +17,8 @@#include "sysemu/cpu-timers.h" #include "sysemu/tcg.h" #include "tcg/tcg.h" -#include "internal-common.h" -#include "tb-context.h" +#include "../internal-common.h" +#include "../tb-context.h" static void dump_drift_info (GString *buf)
accel/tcg/sysemu/tcg-accel-ops-icount.c renamed from accel/tcg/tcg-accel-ops-icount.c +0 -0
accel/tcg/sysemu/tcg-accel-ops-mttcg.c renamed from accel/tcg/tcg-accel-ops-mttcg.c +0 -0
accel/tcg/sysemu/tcg-accel-ops-rr.c renamed from accel/tcg/tcg-accel-ops-rr.c +0 -0
accel/tcg/sysemu/tcg-accel-ops.c renamed from accel/tcg/tcg-accel-ops.c +0 -0
accel/tcg/meson.build +2 -12
@@ -18,19 +18,9 @@ if get_option('plugins') endif specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_specific_ss) -specific_ss.add(when: ['CONFIG_SYSTEM_ONLY', 'CONFIG_TCG'], if_true: files( +specific_ss.add(when: ['CONFIG_SYSTEM_ONLY', 'CONFIG_TCG'], if_true: files( # SoftMMU 'cputlb.c', 'watchpoint.c', )) -system_ss.add(when: ['CONFIG_TCG'], if_true: files( - 'icount-common.c', - 'monitor.c', -)) - -tcg_module_ss.add(when: ['CONFIG_SYSTEM_ONLY', 'CONFIG_TCG'], if_true: files( - 'tcg-accel-ops.c', - 'tcg-accel-ops-mttcg.c', - 'tcg-accel-ops-icount.c', - 'tcg-accel-ops-rr.c', -)) +subdir('sysemu')
accel/tcg/sysemu/meson.build new file +11 -0
@@ -0,0 +1,11 @@ +system_ss.add(files( + 'icount-common.c', + 'monitor.c', +)) + +tcg_module_ss.add(when: ['CONFIG_SYSTEM_ONLY'], if_true: files( + 'tcg-accel-ops.c', + 'tcg-accel-ops-mttcg.c', + 'tcg-accel-ops-icount.c', + 'tcg-accel-ops-rr.c', +))
Signature · 1 line
2.41.0
Re: [PATCH v2 1/4] accel/tcg: Move system emulation files under sysemu/ subdirectory
Quoted 64 lines · Philippe Mathieu-Daudé
Some files are specific to system emulation. Move them under their own sysemu/ directory. This might help to notice what is affected (user, system or both) when doing global refactors.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/{ => sysemu}/tcg-accel-ops-icount.h | 0 accel/tcg/{ => sysemu}/tcg-accel-ops-mttcg.h | 0 accel/tcg/{ => sysemu}/tcg-accel-ops-rr.h | 0 accel/tcg/{ => sysemu}/tcg-accel-ops.h | 0 accel/tcg/{ => sysemu}/icount-common.c | 0 accel/tcg/{ => sysemu}/monitor.c | 4 ++-- accel/tcg/{ => sysemu}/tcg-accel-ops-icount.c | 0 accel/tcg/{ => sysemu}/tcg-accel-ops-mttcg.c | 0 accel/tcg/{ => sysemu}/tcg-accel-ops-rr.c | 0 accel/tcg/{ => sysemu}/tcg-accel-ops.c | 0 accel/tcg/meson.build | 14 ++------------ accel/tcg/sysemu/meson.build | 11 +++++++++++ 12 files changed, 15 insertions(+), 14 deletions(-)rename accel/tcg/{ =>
sysemu}/tcg-accel-ops-icount.h(100%) rename accel/tcg/{ =>sysemu}/tcg-accel-ops-mttcg.h(100%) rename accel/tcg/{ =>sysemu}/tcg-accel-ops-rr.h(100%) rename accel/tcg/{ =>sysemu}/tcg-accel-ops.h(100%) rename accel/tcg/{ =>sysemu}/icount-common.c(100%) rename accel/tcg/{ =>sysemu}/monitor.c(99%) rename accel/tcg/{ =>sysemu}/tcg-accel-ops-icount.c(100%) rename accel/tcg/{ =>sysemu}/tcg-accel-ops-mttcg.c(100%) rename accel/tcg/{ =>sysemu}/tcg-accel-ops-rr.c(100%) rename accel/tcg/{ =>sysemu}/tcg-accel-ops.c(100%) create mode 100644 accel/tcg/sysemu/meson.buildaccel/tcg/meson.build +2
-12@@ -18,19 +18,9 @@ if get_option('plugins') endif specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_specific_ss) -specific_ss.add(when: ['CONFIG_SYSTEM_ONLY', 'CONFIG_TCG'], if_true: files( +specific_ss.add(when: ['CONFIG_SYSTEM_ONLY', 'CONFIG_TCG'], if_true: files( # SoftMMU 'cputlb.c', 'watchpoint.c', )) -system_ss.add(when: ['CONFIG_TCG'], if_true: files( - 'icount-common.c', - 'monitor.c', -)) - -tcg_module_ss.add(when: ['CONFIG_SYSTEM_ONLY', 'CONFIG_TCG'], if_true: files( - 'tcg-accel-ops.c', - 'tcg-accel-ops-mttcg.c', - 'tcg-accel-ops-icount.c', - 'tcg-accel-ops-rr.c', -)) +subdir('sysemu')accel/tcg/sysemu/meson.build new file +0
-0
accel/tcg/sysemu/meson.build line 1
Quoted 1 line
accel/tcg/sysemu/meson.build new file +1
-0@@ -0,0 +1,11 @@ +system_ss.add(files(
Oops, broken rebase, sorry...
Quoted 10 lines
accel/tcg/sysemu/meson.build new file +10
-0+ 'icount-common.c', + 'monitor.c', +)) + +tcg_module_ss.add(when: ['CONFIG_SYSTEM_ONLY'], if_true: files( + 'tcg-accel-ops.c', + 'tcg-accel-ops-mttcg.c', + 'tcg-accel-ops-icount.c', + 'tcg-accel-ops-rr.c', +))
PATCH v2 2/4 accel/tcg: Do not define cpu_exec_reset_hold() as stub
In reply to Philippe Mathieu-DaudéIn commit 1b5120d74b ("accel: Introduce cpu_exec_reset_hold()") we defined the user emulation backend cpu_exec_reset_hold() as a stub. This was a mistake, since common fields are set in CPU reset, and user emulation needs these fields to be resetted. Move cpu_exec_reset_hold() back.
--- accel/tcg/user-exec-stub.c | 4 ---- accel/tcg/user-exec.c | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-)
accel/tcg/user-exec-stub.c +0 -4
@@ -14,10 +14,6 @@ void qemu_init_vcpu(CPUState *cpu) { } -void cpu_exec_reset_hold (CPUState *cpu) -{ -} -/* User mode emulation does not support record/replay yet. */ bool replay_exception (void )
accel/tcg/user-exec.c +4 -0
@@ -37,6 +37,10 @@ __thread uintptr_t helper_retaddr;//#define DEBUG_SIGNAL +void cpu_exec_reset_hold (CPUState *cpu) +{ +} +/* * Adjust the pc to pass to cpu_restore_state; return the memop type. */
Signature · 1 line
2.41.0
PATCH v2 3/4 accel/tcg: Introduce common tcg_exec_cpu_reset_hold() method
In reply to Philippe Mathieu-DaudéIntroduce a method called by cpu_reset(), common
to both system and user emulation.
--- accel/tcg/internal-common.h | 2 ++ accel/tcg/cpu-exec.c | 4 ++++ accel/tcg/sysemu/tcg-accel-ops.c | 3 ++- accel/tcg/user-exec.c | 1 + 4 files changed, 9 insertions(+), 1 deletion(-)
accel/tcg/internal-common.h +2 -0
@@ -23,4 +23,6 @@ static inline bool cpu_in_serial_context(CPUState *cs) return !(cs->tcg_cflags & CF_PARALLEL) || cpu_in_exclusive_context(cs); } +void tcg_exec_cpu_reset_hold (CPUState *cpu); +#endif
accel/tcg/cpu-exec.c +4 -0
@@ -1096,3 +1096,7 @@ void tcg_exec_unrealizefn(CPUState *cpu)tlb_destroy (cpu);g_free_rcu (cpu->tb_jmp_cache, rcu); } + +void tcg_exec_cpu_reset_hold (CPUState *cpu) +{ +}
accel/tcg/sysemu/tcg-accel-ops.c +2 -1
@@ -36,7 +36,7 @@#include "exec/hwaddr.h" #include "exec/tb-flush.h" #include "exec/gdbstub.h" - +#include "../internal-common.h" #include "hw/core/cpu.h" #include "tcg-accel-ops.h"
@@ -82,6 +82,7 @@ int tcg_cpu_exec(CPUState *cpu)static void tcg_cpu_reset_hold (CPUState *cpu) { +tcg_exec_cpu_reset_hold (cpu);tcg_flush_jmp_cache (cpu);tlb_flush (cpu);
accel/tcg/user-exec.c +1 -0
@@ -39,6 +39,7 @@ __thread uintptr_t helper_retaddr;void cpu_exec_reset_hold (CPUState *cpu) { +tcg_exec_cpu_reset_hold (cpu); }/*
Signature · 1 line
2.41.0
PATCH v2 4/4 accel/tcg: Always call tcg_flush_jmp_cache() on reset
In reply to Philippe Mathieu-DaudéIn commit bb6cf6f016 ("accel/tcg: Factor tcg_cpu_reset_hold() out") we unfortunately restricted the tcg_flush_jmp_cache() to system emulation. Move it to the common tcg_exec_cpu_reset_hold() handler so user emulation gets the jmp_cache initialized when threads are created.
Remove the NULL check in tcg_flush_jmp_cache() from commit 4e4fa6c12d ("accel/tcg: Complete cpu initialization before registration") which was a band-aid fix for incorrect commit bb6cf6f016.
--- accel/tcg/cpu-exec.c | 2 ++ accel/tcg/sysemu/tcg-accel-ops.c | 2 -- accel/tcg/translate-all.c | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-)
accel/tcg/cpu-exec.c +2 -0
@@ -36,6 +36,7 @@#include "exec/replay-core.h" #include "sysemu/tcg.h" #include "exec/helper-proto-common.h" +#include "exec/tb-flush.h" #include "tb-jmp-cache.h" #include "tb-hash.h" #include "tb-context.h"
@@ -1099,4 +1100,5 @@ void tcg_exec_unrealizefn(CPUState *cpu)void tcg_exec_cpu_reset_hold (CPUState *cpu) { +tcg_flush_jmp_cache (cpu); }
accel/tcg/sysemu/tcg-accel-ops.c +0 -2
@@ -34,7 +34,6 @@#include "qemu/timer.h" #include "exec/exec-all.h" #include "exec/hwaddr.h" -#include "exec/tb-flush.h" #include "exec/gdbstub.h" #include "../internal-common.h" #include "hw/core/cpu.h"
@@ -83,7 +82,6 @@ int tcg_cpu_exec(CPUState *cpu)static void tcg_cpu_reset_hold (CPUState *cpu) {tcg_exec_cpu_reset_hold (cpu); -tcg_flush_jmp_cache (cpu);tlb_flush (cpu); }
accel/tcg/translate-all.c +0 -5
@@ -663,11 +663,6 @@ void tcg_flush_jmp_cache(CPUState *cpu) {CPUJumpCache *jc = cpu->tb_jmp_cache; -/* During early initialization, the cache may not yet be allocated. */ -if (unlikely (jc ==NULL )) { -return ; - } -for (int i =0 ; i <TB_JMP_CACHE_SIZE ; i++) {qatomic_set (&jc->array[i].tb,NULL ); }
Signature · 1 line
2.41.0