* [PULL v2 00/10] tcg patch queue
@ 2021-01-24 18:11 Richard Henderson
2021-01-24 18:11 ` [PULL v2 10/10] tcg: Restart code generation when we run out of temps Richard Henderson
2021-01-25 10:35 ` [PULL v2 00/10] tcg patch queue Peter Maydell
0 siblings, 2 replies; 4+ messages in thread
From: Richard Henderson @ 2021-01-24 18:11 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
V2 replaces the tcg const temp overflow patch.
r~
The following changes since commit 0e32462630687a18039464511bd0447ada5709c3:
Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-6.0-pull-request' into staging (2021-01-22 10:35:55 +0000)
are available in the Git repository at:
https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20210124
for you to fetch changes up to ae30e86661b0f48562cd95918d37cbeec5d02262:
tcg: Restart code generation when we run out of temps (2021-01-24 08:03:27 -1000)
----------------------------------------------------------------
Fix tcg constant temp overflow.
Fix running during atomic single-step.
Partial support for apple silicon.
Cleanups for accel/tcg.
----------------------------------------------------------------
Douglas Crosher (1):
tcg: update the cpu running flag in cpu_exec_step_atomic
Philippe Mathieu-Daudé (4):
accel/tcg: Make cpu_gen_init() static
accel/tcg: Restrict tb_gen_code() from other accelerators
accel/tcg: Declare missing cpu_loop_exit*() stubs
accel/tcg: Restrict cpu_io_recompile() from other accelerators
Richard Henderson (4):
qemu/compiler: Split out qemu_build_not_reached_always
tcg: Optimize inline dup_const for MO_64
accel/tcg: Move tb_flush_jmp_cache() to cputlb.c
tcg: Restart code generation when we run out of temps
Roman Bolshakov (1):
tcg: Toggle page execution for Apple Silicon
accel/tcg/internal.h | 20 ++++++++++++++++++++
include/exec/exec-all.h | 11 -----------
include/qemu/compiler.h | 5 +++--
include/qemu/osdep.h | 28 ++++++++++++++++++++++++++++
include/tcg/tcg.h | 6 +++++-
accel/stubs/tcg-stub.c | 10 ++++++++++
accel/tcg/cpu-exec.c | 7 +++++++
accel/tcg/cputlb.c | 19 +++++++++++++++++++
accel/tcg/translate-all.c | 38 +++++++++++++++++++-------------------
tcg/tcg.c | 12 +++++++++---
10 files changed, 120 insertions(+), 36 deletions(-)
create mode 100644 accel/tcg/internal.h
^ permalink raw reply [flat|nested] 4+ messages in thread* [PULL v2 10/10] tcg: Restart code generation when we run out of temps 2021-01-24 18:11 [PULL v2 00/10] tcg patch queue Richard Henderson @ 2021-01-24 18:11 ` Richard Henderson 2021-01-25 9:15 ` Roman Bolshakov 2021-01-25 10:35 ` [PULL v2 00/10] tcg patch queue Peter Maydell 1 sibling, 1 reply; 4+ messages in thread From: Richard Henderson @ 2021-01-24 18:11 UTC (permalink / raw) To: qemu-devel; +Cc: peter.maydell, Philippe Mathieu-Daudé Some large translation blocks can generate so many unique constants that we run out of temps to hold them. In this case, longjmp back to the start of code generation and restart with a smaller translation block. Buglink: https://bugs.launchpad.net/bugs/1912065 Tested-by: BALATON Zoltan <balaton@eik.bme.hu> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- include/tcg/tcg.h | 3 +++ accel/tcg/translate-all.c | 15 ++++++++++++++- tcg/tcg.c | 11 ++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index c5a9d65d5f..0f0695e90d 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -680,6 +680,9 @@ struct TCGContext { uint16_t gen_insn_end_off[TCG_MAX_INSNS]; target_ulong gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS]; + + /* Exit to translator on overflow. */ + sigjmp_buf jmp_trans; }; static inline bool temp_readonly(TCGTemp *ts) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index d09c187e0f..81d4c83f22 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1926,11 +1926,17 @@ TranslationBlock *tb_gen_code(CPUState *cpu, ti = profile_getclock(); #endif + gen_code_size = sigsetjmp(tcg_ctx->jmp_trans, 0); + if (unlikely(gen_code_size != 0)) { + goto error_return; + } + tcg_func_start(tcg_ctx); tcg_ctx->cpu = env_cpu(env); gen_intermediate_code(cpu, tb, max_insns); tcg_ctx->cpu = NULL; + max_insns = tb->icount; trace_translate_block(tb, tb->pc, tb->tc.ptr); @@ -1955,6 +1961,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, gen_code_size = tcg_gen_code(tcg_ctx, tb); if (unlikely(gen_code_size < 0)) { + error_return: switch (gen_code_size) { case -1: /* @@ -1966,6 +1973,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, * flush the TBs, allocate a new TB, re-initialize it per * above, and re-do the actual code generation. */ + qemu_log_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT, + "Restarting code generation for " + "code_gen_buffer overflow\n"); goto buffer_overflow; case -2: @@ -1978,9 +1988,12 @@ TranslationBlock *tb_gen_code(CPUState *cpu, * Try again with half as many insns as we attempted this time. * If a single insn overflows, there's a bug somewhere... */ - max_insns = tb->icount; assert(max_insns > 1); max_insns /= 2; + qemu_log_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT, + "Restarting code generation with " + "smaller translation block (max %d insns)\n", + max_insns); goto tb_overflow; default: diff --git a/tcg/tcg.c b/tcg/tcg.c index 67b08f708d..9e1b0d73c7 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1205,18 +1205,23 @@ void tcg_func_start(TCGContext *s) QSIMPLEQ_INIT(&s->labels); } -static inline TCGTemp *tcg_temp_alloc(TCGContext *s) +static TCGTemp *tcg_temp_alloc(TCGContext *s) { int n = s->nb_temps++; - tcg_debug_assert(n < TCG_MAX_TEMPS); + + if (n >= TCG_MAX_TEMPS) { + /* Signal overflow, starting over with fewer guest insns. */ + siglongjmp(s->jmp_trans, -2); + } return memset(&s->temps[n], 0, sizeof(TCGTemp)); } -static inline TCGTemp *tcg_global_alloc(TCGContext *s) +static TCGTemp *tcg_global_alloc(TCGContext *s) { TCGTemp *ts; tcg_debug_assert(s->nb_globals == s->nb_temps); + tcg_debug_assert(s->nb_globals < TCG_MAX_TEMPS); s->nb_globals++; ts = tcg_temp_alloc(s); ts->kind = TEMP_GLOBAL; -- 2.25.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PULL v2 10/10] tcg: Restart code generation when we run out of temps 2021-01-24 18:11 ` [PULL v2 10/10] tcg: Restart code generation when we run out of temps Richard Henderson @ 2021-01-25 9:15 ` Roman Bolshakov 0 siblings, 0 replies; 4+ messages in thread From: Roman Bolshakov @ 2021-01-25 9:15 UTC (permalink / raw) To: Richard Henderson; +Cc: peter.maydell, qemu-devel, Philippe Mathieu-Daudé On Sun, Jan 24, 2021 at 08:11:22AM -1000, Richard Henderson wrote: > Some large translation blocks can generate so many unique > constants that we run out of temps to hold them. In this > case, longjmp back to the start of code generation and > restart with a smaller translation block. > > Buglink: https://bugs.launchpad.net/bugs/1912065 > Tested-by: BALATON Zoltan <balaton@eik.bme.hu> > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > include/tcg/tcg.h | 3 +++ > accel/tcg/translate-all.c | 15 ++++++++++++++- > tcg/tcg.c | 11 ++++++++--- > 3 files changed, 25 insertions(+), 4 deletions(-) > > diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h > index c5a9d65d5f..0f0695e90d 100644 > --- a/include/tcg/tcg.h > +++ b/include/tcg/tcg.h > @@ -680,6 +680,9 @@ struct TCGContext { > > uint16_t gen_insn_end_off[TCG_MAX_INSNS]; > target_ulong gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS]; > + > + /* Exit to translator on overflow. */ > + sigjmp_buf jmp_trans; > }; > > static inline bool temp_readonly(TCGTemp *ts) > diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c > index d09c187e0f..81d4c83f22 100644 > --- a/accel/tcg/translate-all.c > +++ b/accel/tcg/translate-all.c > @@ -1926,11 +1926,17 @@ TranslationBlock *tb_gen_code(CPUState *cpu, > ti = profile_getclock(); > #endif > > + gen_code_size = sigsetjmp(tcg_ctx->jmp_trans, 0); > + if (unlikely(gen_code_size != 0)) { > + goto error_return; > + } > + > tcg_func_start(tcg_ctx); > > tcg_ctx->cpu = env_cpu(env); > gen_intermediate_code(cpu, tb, max_insns); > tcg_ctx->cpu = NULL; > + max_insns = tb->icount; > > trace_translate_block(tb, tb->pc, tb->tc.ptr); > > @@ -1955,6 +1961,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, > > gen_code_size = tcg_gen_code(tcg_ctx, tb); > if (unlikely(gen_code_size < 0)) { > + error_return: > switch (gen_code_size) { > case -1: > /* > @@ -1966,6 +1973,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, > * flush the TBs, allocate a new TB, re-initialize it per > * above, and re-do the actual code generation. > */ > + qemu_log_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT, > + "Restarting code generation for " > + "code_gen_buffer overflow\n"); > goto buffer_overflow; > > case -2: > @@ -1978,9 +1988,12 @@ TranslationBlock *tb_gen_code(CPUState *cpu, > * Try again with half as many insns as we attempted this time. > * If a single insn overflows, there's a bug somewhere... > */ > - max_insns = tb->icount; > assert(max_insns > 1); > max_insns /= 2; > + qemu_log_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT, > + "Restarting code generation with " > + "smaller translation block (max %d insns)\n", > + max_insns); > goto tb_overflow; > > default: > diff --git a/tcg/tcg.c b/tcg/tcg.c > index 67b08f708d..9e1b0d73c7 100644 > --- a/tcg/tcg.c > +++ b/tcg/tcg.c > @@ -1205,18 +1205,23 @@ void tcg_func_start(TCGContext *s) > QSIMPLEQ_INIT(&s->labels); > } > > -static inline TCGTemp *tcg_temp_alloc(TCGContext *s) > +static TCGTemp *tcg_temp_alloc(TCGContext *s) > { > int n = s->nb_temps++; > - tcg_debug_assert(n < TCG_MAX_TEMPS); > + > + if (n >= TCG_MAX_TEMPS) { > + /* Signal overflow, starting over with fewer guest insns. */ > + siglongjmp(s->jmp_trans, -2); > + } > return memset(&s->temps[n], 0, sizeof(TCGTemp)); > } > > -static inline TCGTemp *tcg_global_alloc(TCGContext *s) > +static TCGTemp *tcg_global_alloc(TCGContext *s) > { > TCGTemp *ts; > > tcg_debug_assert(s->nb_globals == s->nb_temps); > + tcg_debug_assert(s->nb_globals < TCG_MAX_TEMPS); > s->nb_globals++; > ts = tcg_temp_alloc(s); > ts->kind = TEMP_GLOBAL; > -- > 2.25.1 > > Hi Richard, Thanks for providing the fix. Tested-by: Roman Bolshakov <r.bolshakov@yadro.com> Regards, Roman ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PULL v2 00/10] tcg patch queue 2021-01-24 18:11 [PULL v2 00/10] tcg patch queue Richard Henderson 2021-01-24 18:11 ` [PULL v2 10/10] tcg: Restart code generation when we run out of temps Richard Henderson @ 2021-01-25 10:35 ` Peter Maydell 1 sibling, 0 replies; 4+ messages in thread From: Peter Maydell @ 2021-01-25 10:35 UTC (permalink / raw) To: Richard Henderson; +Cc: QEMU Developers On Sun, 24 Jan 2021 at 18:11, Richard Henderson <richard.henderson@linaro.org> wrote: > > > V2 replaces the tcg const temp overflow patch. > > > r~ > > > The following changes since commit 0e32462630687a18039464511bd0447ada5709c3: > > Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-6.0-pull-request' into staging (2021-01-22 10:35:55 +0000) > > are available in the Git repository at: > > https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20210124 > > for you to fetch changes up to ae30e86661b0f48562cd95918d37cbeec5d02262: > > tcg: Restart code generation when we run out of temps (2021-01-24 08:03:27 -1000) > > ---------------------------------------------------------------- > Fix tcg constant temp overflow. > Fix running during atomic single-step. > Partial support for apple silicon. > Cleanups for accel/tcg. Applied, thanks. Please update the changelog at https://wiki.qemu.org/ChangeLog/6.0 for any user-visible changes. -- PMM ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-01-25 10:37 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-01-24 18:11 [PULL v2 00/10] tcg patch queue Richard Henderson 2021-01-24 18:11 ` [PULL v2 10/10] tcg: Restart code generation when we run out of temps Richard Henderson 2021-01-25 9:15 ` Roman Bolshakov 2021-01-25 10:35 ` [PULL v2 00/10] tcg patch queue Peter Maydell
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).