accel/tcg/translate-all.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
When the code buffer is full in a serial context, tb_gen_code() flushes
it and retries in place. cpu_exec_loop() then chains its last_tb, now
freed, into the new TB. When that TB is invalidated, tb_jmp_unlink()
follows the stale entry and qemu crashes inside its SIGSEGV handler.
Always queue the flush and leave through cpu_loop_exit(), as before
commit ebf7a5d294a3. This also brings back the cleanup in
cpu_loop_exit() and cpu_exec_longjmp_cleanup() that the retry skipped.
Since commit 25e5c6a320db ("accel/tcg: Allow cross-page goto_tb
chaining in user-only builds"), user-only builds hit this easily,
e.g. qemu-sparc64 -tb-size 1 on a program writing next to its PLT.
Cc: qemu-stable@nongnu.org
Fixes: ebf7a5d294a3 ("accel/tcg: Improve buffer overflow in tb_gen_code")
Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Stian Halseth <stian@itx.no>
---
v3:
- Drop the in-place retry instead of clearing last_tb after it
(Alex, Richard)
- Matt's Reviewed-by dropped, since the code changed
v2: https://lore.kernel.org/qemu-devel/20261024070347.1202239-1-stian@itx.no/
v1: https://lore.kernel.org/qemu-devel/20261023113245.562358-1-stian@itx.no/
accel/tcg/translate-all.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 328d96aba3..531a4e6ffd 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -289,11 +289,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, TCGTBCPUState s)
tb = tcg_tb_alloc(tcg_ctx);
if (unlikely(!tb)) {
/* flush must be done */
- if (cpu_in_serial_context(cpu)) {
- trace_tb_gen_code_buffer_overflow("tcg_tb_alloc");
- tb_flush__exclusive_or_serial();
- goto buffer_overflow;
- }
+ trace_tb_gen_code_buffer_overflow("tcg_tb_alloc");
queue_tb_flush(cpu);
mmap_unlock();
/* Make the execution loop process the flush as soon as possible. */
--
2.43.0
On 10/28/26 07:02, Stian Halseth wrote:
> When the code buffer is full in a serial context, tb_gen_code() flushes
> it and retries in place. cpu_exec_loop() then chains its last_tb, now
> freed, into the new TB. When that TB is invalidated, tb_jmp_unlink()
> follows the stale entry and qemu crashes inside its SIGSEGV handler.
>
> Always queue the flush and leave through cpu_loop_exit(), as before
> commit ebf7a5d294a3. This also brings back the cleanup in
> cpu_loop_exit() and cpu_exec_longjmp_cleanup() that the retry skipped.
>
> Since commit 25e5c6a320db ("accel/tcg: Allow cross-page goto_tb
> chaining in user-only builds"), user-only builds hit this easily,
> e.g. qemu-sparc64 -tb-size 1 on a program writing next to its PLT.
>
> Cc:qemu-stable@nongnu.org
> Fixes: ebf7a5d294a3 ("accel/tcg: Improve buffer overflow in tb_gen_code")
> Suggested-by: Alex Bennée<alex.bennee@linaro.org>
> Signed-off-by: Stian Halseth<stian@itx.no>
> ---
> v3:
> - Drop the in-place retry instead of clearing last_tb after it
> (Alex, Richard)
> - Matt's Reviewed-by dropped, since the code changed
>
> v2:https://lore.kernel.org/qemu-devel/20261024070347.1202239-1-stian@itx.no/
> v1:https://lore.kernel.org/qemu-devel/20261023113245.562358-1-stian@itx.no/
>
> accel/tcg/translate-all.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Queued to tcg-next.
r~
© 2016 - 2026 Red Hat, Inc.