From nobody Mon Nov 23 04:18:43 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=itx.no ARC-Seal: i=1; a=rsa-sha256; t=1793188995; cv=none; d=zohomail.com; s=zohoarc; b=lno2RjiKADL2/CgcI047o2a+bfCj1iz6ee5Fk4GAn8N2skFVdbcH108U5WNZtBLfRPRu6UubDtsI72+oHgwIALLN2Ue7DNEIboxZJldOw5Vlgcw8TGRUFGSHqPvqphyBeKa0/0HCVT95udSK6SXM/W9+793bMxS/mC/qT2+YAyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793188995; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=33YIsvOM++XLj5sSgfhneEcEp7KVe8h4lRc912dPYkY=; b=Ei3c2uthoj8hnHnoR25OeQtHUoSeKe7eVq2CmSMMA9Yr0Y/hK7o/gsLh9zGIXf6zKzRo2k71WKx3M6xU7GtsgZTNrSjeOPXFaVeEgNzBzpSdWh0CS1LD9zUlA7OSwMut4r/kx+tmXpUNhF2SF6flj9j474fr7ooXmSh1R9sg3ms= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793188995204257.61962946039625; Wed, 28 Oct 2026 05:03:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM2Ms-0007cl-R2; Wed, 28 Oct 2026 08:02:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xM2Mo-0007Yw-Jz; Wed, 28 Oct 2026 08:02:54 -0400 Received: from itx-kvm-14.itxnorge.no ([91.189.121.228] helo=mx.itxnorge.no) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xM2Ml-0006xd-0J; Wed, 28 Oct 2026 08:02:54 -0400 From: Stian Halseth DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itx.no; s=mx.itx.no; t=1793188967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=33YIsvOM++XLj5sSgfhneEcEp7KVe8h4lRc912dPYkY=; b=BARqDVLch+YQ+iTEhO0g9KogIYbIpJ8LKbMEEgrQxHO1O4WEjoAwnOoIG1fgZ+ne4cNq93 O+k2sGlRhMTyigr++t0DfwiP9V5TaUXlEs9AQBENh/74Yp6dLrIneAEvLKvbkh+0QCKaxU 99OoBedZ+2Dr60fTdDuc/uTxAPa4CT4= To: qemu-devel@nongnu.org Cc: Richard Henderson , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Matt Turner , Stian Halseth , qemu-stable@nongnu.org Subject: [PATCH v3] accel/tcg: Do not flush and retry in place in tb_gen_code Date: Wed, 28 Oct 2026 13:02:33 +0100 Message-ID: <20261028120233.1664444-1-stian@itx.no> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=91.189.121.228; envelope-from=stian@itx.no; helo=mx.itxnorge.no X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @itx.no) X-ZM-MESSAGEID: 1793188997975158500 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=C3=A9e Signed-off-by: Stian Halseth Reviewed-by: Richard Henderson --- 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.n= o/ 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, TCGTBCPUS= tate s) tb =3D 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. = */ --=20 2.43.0