From: "Alex Bennée" <alex.bennee@linaro.org>
To: Stian Halseth <stian@itx.no>
Cc: qemu-devel@nongnu.org,
Richard Henderson <richard.henderson@linaro.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Matt Turner <mattst88@gmail.com>
Subject: Re: [PATCH] accel/tcg: Do not chain from a TB freed by tb_gen_code's flush
Date: Fri, 23 Oct 2026 18:05:14 +0100 [thread overview]
Message-ID: <8733tws5yt.fsf@draig.linaro.org> (raw)
In-Reply-To: <20261023113245.562358-1-stian@itx.no> (Stian Halseth's message of "Fri, 23 Oct 2026 13:32:45 +0200")
Stian Halseth <stian@itx.no> writes:
> In a serial context, tb_gen_code() flushes a full code buffer 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.
I wonder how much:
/* 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;
}
actually saves? Because we are skipping both cleanup in cpu_loop_exit
(the mem helpers) and cpu_exec_longjmp_cleanup which we get to when we
jump out.
>
> Drop last_tb when tb_gen_code() has flushed.
>
> User-only builds hit this easily since cross-page goto_tb chaining,
> e.g. qemu-sparc64 -tb-size 1 on a program writing next to its PLT.
>
> Fixes: ebf7a5d294a3 ("accel/tcg: Improve buffer overflow in tb_gen_code")
> Fixes: 25e5c6a320db ("accel/tcg: Allow cross-page goto_tb chaining in user-only builds")
> Signed-off-by: Stian Halseth <stian@itx.no>
> ---
> 25e5c6a320db is not in a release yet (v11.1.x does not have it), so the
> crash is new in the 11.2 cycle.
>
> Reproducers available on request: on x86_64 the stale chain happens
> too but has stayed harmless; on sparc64 it crashes every time.
>
> accel/tcg/cpu-exec.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
> index 5b4bca5084..600e8c5fa8 100644
> --- a/accel/tcg/cpu-exec.c
> +++ b/accel/tcg/cpu-exec.c
> @@ -968,11 +968,17 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc)
> if (tb == NULL) {
> CPUJumpCache *jc;
> uint32_t h;
> + unsigned flush_count = qatomic_read(&tb_ctx.tb_flush_count);
>
> mmap_lock();
> tb = tb_gen_code(cpu, s);
> mmap_unlock();
>
> + /* tb_gen_code may have flushed, freeing last_tb. */
> + if (flush_count != qatomic_read(&tb_ctx.tb_flush_count)) {
> + last_tb = NULL;
> + }
> +
> /*
> * We add the TB in the virtual pc hash table
> * for the fast lookup
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2026-10-23 17:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 11:32 [PATCH] accel/tcg: Do not chain from a TB freed by tb_gen_code's flush Stian Halseth
2026-10-23 17:05 ` Alex Bennée [this message]
2026-10-23 17:53 ` Stian Halseth
2026-10-28 10:55 ` Richard Henderson
2026-10-24 0:08 ` Matt Turner
2026-10-24 7:07 ` Stian Halseth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8733tws5yt.fsf@draig.linaro.org \
--to=alex.bennee@linaro.org \
--cc=mattst88@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=stian@itx.no \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.