Skip to content

[Bug] LATX_MT=1/2 aborts immediately on x86_64 (itemp register exhausted, SIGTRAP) #524

Closed

Description

@kong5021

On a 16KB-page LoongArch64 host, setting LATX_MT=1 or LATX_MT=2 for the x86_64 translator aborts at startup:

[LATX] itemp register exhausted, status=0x7f
SIGTRAP (core dumped)

The option is accepted because it only checks qemu_real_host_page_size == 16K, which holds on this host — but the code it enables is not compiled for the 64-bit target.

Two things combine (line numbers at master 48a9c55):

  1. target/i386/latx/translator/translate.c:4581-4583 allocates three itemps at the top of gen_test_page_flag(), before the #if TARGET_ABI_BITS == 32 guard at :4602. On a 64-bit build the allocation happens on every memory access, while the 16K body that was meant to consume them is not compiled in.
  2. target/i386/latx/translator/reg-alloc.c:295-310 makes ra_alloc_itemp() abort() when the pool is exhausted, so the graceful fallback immediately below it (translate.c:4584-4596, spilling into a0/a1/a2 via need_restore0/1/2) can never run — it is dead code under register pressure.

Suggested fix (either one):

  • move the three itemp allocations inside the #if TARGET_ABI_BITS == 32 guard, or
  • reject LATX_MT at option-parse time when TARGET_ABI_BITS == 64, with a clear message.

Environment

  • Host CPU: Loongson 3A6000 (LoongArch64)
  • OS: Galaxy Kylin V10 SP1 2503, kernel 5.4.18-125-generic
  • Host page size: 16KB (CONFIG_PAGE_SIZE_16KB=y)
  • Reproduced with both distro package lat 1.6.7 and locally built master 48a9c55
  • getconf PAGESIZE -> 16384

Reproduce

LATX_MT=1 latx-x86_64 /opt/wine-stable/bin/wine64 'C:/npp/notepad++.exe'
LATX_MT=2 latx-x86_64 /opt/wine-stable/bin/wine64 'C:/npp/notepad++.exe'

Both abort immediately with the message above.

Happy to run any patch you suggest — this is a dedicated test box.

Activity

  1. kong5021 commented on Oct 24, 2026

    @kong5021
    Author

    Found the root cause while reading the code: gen_test_page_flag() returns early when option_mem_test is 0 (the x86_64 build takes the #else return; branch), so the three itemps at translate.c:4581 are only allocated once LATX_MT is set — and on a 64-bit build nothing ever consumes them, so ra_alloc_itemp() exhausts and aborts. The minimal fix is to reject LATX_MT at option-parse time on 64-bit targets. Patch below (also fine to turn the warning into exit() if you prefer). Happy to open a PR with this if you'd like.

    diff --git a/linux-user/main.c b/linux-user/main.c
    index d37bd80..24cf674 100644
    --- a/linux-user/main.c
    +++ b/linux-user/main.c
    @@ -842,6 +842,15 @@ static void handle_arg_latx_mem_test(const char *arg)
         } else {
             option_mem_test = value;
         }
    +#if TARGET_ABI_BITS == 64
    +    if (option_mem_test) {
    +        fprintf(stderr,
    +                "LATX_MT is not supported on the x86_64 target: "
    +                "16K-page guest-permission checks are i386-only. "
    +                "Ignoring LATX_MT.\n");
    +        option_mem_test = 0;
    +    }
    +#endif
         if (option_mem_test) {
             if (qemu_real_host_page_size != LATX_HOST_16K_PAGE_SIZE) {
                 option_mem_test = 0;
  2. xiezyang commented on Oct 26, 2026

    @xiezyang
    Contributor

    Thanks for the report. I reproduced the exhaustion on master 48a9c55 and opened #525 with a fix and a minimal regression test.

    The fix keeps LATX_MT available on x86_64 and releases temporary registers that are no longer needed. In the TEST [mem], imm followed by CMOVNE reg, [mem] sequence, the TEST sources are no longer needed after flag calculation and the AND result have been emitted. Releasing them before translating CMOVcc avoids the exhaustion in this reproducer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions