Repository navigation
Fix rare C2 crash (remap state recovery in exit trampolines); support tagged pointers (TBI) - #4
Merged
Merged
Conversation
A thread interrupted inside an exit trampoline of a remapped block was recovered as if still remapped: the trampolines are emitted after the main code, so the last REMAP point before them is the main code's, which is "remapped" when the block ends in a self-loop back-edge. Every path into a trampoline has run the remap epilogue, so this gave each remap candidate its victim's host register and the victim its stale slot. Seen as a rare (about 1 in 60 javac runs) crash in HotSpot's C2 compiler: x24 (remapped into RSI) received x30's value, the return address libjvm+0xb3d454, and PhaseIdealLoop::dom_depth then read its fields from code. Interrupts land in trampolines only on an exit's first, unchained run, and need an epoch change or signal at that moment, hence the rarity. Emit a canonical REMAP 0 point at the start of the trampolines, with a unit test that recovers at a trampoline of a block ending remapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EkLScjRgtBQ8aqLMVan3KC
arm64 Linux ignores bits 63:56 of user data addresses (TBI); under kemu a load through a tagged pointer died with SIGSEGV (si_code SI_KERNEL, address 0), since such an address is non-canonical on x86 and raises #GP. - Interpreter: every data access goes through an Env adapter that strips the tag (bits 63:56 := bit 55). Fault addresses are reported untagged, as arm64 Linux does without SA_EXPOSE_TAGBITS; IC IVAU is untagged too. - Translated code doesn't mask, so untagged programs pay nothing. A new hook in exc_general_protection (kemu_user_gp) recovers the guest state and runs the instruction in the interpreter: it either completes, or the fault is delivered as SEGV_MAPERR/SEGV_ACCERR with the address (this also fixes addresses beyond the 48-bit VA range). - A block that takes 8 such faults is retranslated with Cfg::tbi: the base is copied and untagged (shl 8; sar 8), writeback keeps the tag, atomics/exclusives use the helper. These blocks bypass the xcache. - Tests: tests/kernel/tbi (access forms, writeback, SIMD, atomics, a hot loop that gets retranslated, tagged fault), an ABI check for addresses beyond the VA range, an interpreter unit test, and TBI=1 in jit-test (tagged base registers, TBI-mode translation vs. the interpreter). The tagged-address syscall ABI (PR_SET_TAGGED_ADDR_CTRL) is not supported; syscalls given tagged pointers fail with EFAULT as on arm64 by default. Also adds the kemu.stress=<n> knob's history to DESIGN.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EkLScjRgtBQ8aqLMVan3KC
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EkLScjRgtBQ8aqLMVan3KC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Rare HotSpot C2 crash: wrong register values after an interrupt in an exit trampoline
About 1 in 60
javacruns crashed in C2 (PhaseIdealLoop::dom_depth), dereferencing0xf941c000b0004680. Both halves of that value are AArch64 instructions. The register dump showedx24 == libjvm+0xb3d454, the return address of the precedingbl. So guestx24had received guestx30's value.Cause. The translator remaps hot unpinned registers into unused pinned host registers inside a block (here
x24intoRSI, which normally holdsx30).REMAPpoint at or before it.x24 ← RSI.Fix: emit a canonical
REMAP 0point at the start of the trampolines. A new unit test recovers state at a trampoline of a block that ends remapped. It failed before the fix and passes now.2. Top-byte-ignore (tagged pointers)
arm64 Linux ignores bits 63:56 of user data addresses. Under kemu, a tagged load died with
SIGSEGV/SI_KERNELand address 0, because a tagged address is non-canonical on x86 and raises #GP.Envadapter that strips the tag. Fault addresses are reported untagged, as arm64 Linux does.exc_general_protection(kemu_user_gp, in0009-kemu-x86-fault.patch) recovers the guest state and runs the instruction in the interpreter.SEGV_MAPERR/SEGV_ACCERRwith the address. That also fixes addresses beyond the 48-bit VA range, which previously reported address 0.Cfg::tbi).PR_SET_TAGGED_ADDR_CTRL). Syscalls given tagged pointers returnEFAULT, which is also arm64's default behaviour.Also adds
kemu.stress=<n>, a debug knob that forces state recovery at random points.Testing
kemu_coreunit tests: 28/28. The new trampoline-recovery test fails without fix 1. The new interpreter TBI test is also included.INTR,RELOCand newTBI=1modes.TBI=1uses tagged base registers and TBI-mode translation.tests/kernel/tbi, also added tovm-smoke.sh. It covers plain, register-offset, pair, SIMD and atomic accesses; writeback keeping the tag; a hot loop that gets retranslated (20M tagged load/store pairs in 0.05 s); and a fault through a tagged pointer. It passes with the JIT and withkemu.jit=0.sigsegv-highcheck.vm-smoke.shandvm-jit-stress.sh 2 2pass locally on the final kernel. Thekemu.stress=50variant was still running when this PR was opened; CI runs both.🤖 Generated with Claude Code
https://claude.ai/code/session_01EkLScjRgtBQ8aqLMVan3KC