On Wed, Aug 26, 2026 at 3:51 AM Alex Bennée <[email protected]> wrote: > > Matt Turner <[email protected]> writes: > > > translator_use_goto_tb() refuses to chain unless the destination is on the > > same page as the start of the TB. For guests whose text is much larger than > > a page this is expensive: an emulated alpha gcc compiling a 255k line > > translation unit takes the indirect dispatch path for 8.4 billion of its > > 34.2 billion TB exits, and a large share of those are ordinary direct > > branches that simply crossed an 8 KiB page boundary. > > > > The restriction was made unconditional by d3a2a1d803 ("accel/tcg: > > Introduce translator_use_goto_tb"), whose rationale was: > > > > Various targets avoid the page crossing test for CONFIG_USER_ONLY, > > but that is wrong: mmap and mprotect can change page permissions. > > > > That is true, but in user-only builds the invalidation path already covers > > it. There are no page tables: every mmap, mprotect and munmap reaches > > page_set_flags(), which calls tb_invalidate_phys_range() whenever the flags > > actually change, and tb_phys_invalidate() calls tb_jmp_unlink() to reset > > incoming jumps. A chained cross-page jump is therefore broken whenever the > > destination page's permissions change. This is not true in system mode, > > where TBs are keyed by physical address and a page table change invalidates > > nothing, so the restriction is kept there. > > tests/tcg/alpha/Makefile.target | 17 +++- > > tests/tcg/alpha/gdbstub/xpage-bp.py | 34 +++++++ > > tests/tcg/alpha/test-xpage-chain.c | 144 ++++++++++++++++++++++++++++ > <snip> > > Given alpha linux-user isn't widely built or used it would be better if > we could make the xpage chaining tests multiarch so they are exercised > on all *-user targets.
Done. The explicit branch is gone with the move: a fall-through off the end of a page is a cross-page goto_tb just the same, so the test writes the last instruction of page A and the first of page B, and needs no per-arch branch encoding or displacement arithmetic -- just "set the return value" and "return". 13 architectures supply those two, and the rest skip. I checked each encoding against the cross assembler and ran the test under qemu-user on aarch64, alpha, arm, hppa, loongarch64, m68k, mips, ppc, ppc64le, riscv64, s390x, sh4, sparc64 and x86_64 (ppc64 ELFv1 skips). The gdbstub half moved with it.
