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: [email protected]
Fixes: ebf7a5d294a3 ("accel/tcg: Improve buffer overflow in tb_gen_code")
Suggested-by: Alex Bennée <[email protected]>
Signed-off-by: Stian Halseth <[email protected]>
---
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/[email protected]/
v1: https://lore.kernel.org/qemu-devel/[email protected]/
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