Skip to content

Let the TSan crash tests see the main thread's sleep on aarch64 - #874

Merged
fcostaoliveira merged 2 commits into
masterfrom
fix/crash-test-sleep-probe-aarch64
Oct 26, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
fix/crash-test-sleep-probe-aarch64

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #843.

The TSan crash tests SIGSTOP memtier and signal the main thread only once /proc/<pid>/task/<pid>/syscall shows it in a libc nanosleep/clock_nanosleep (#828). On arm64 the kernel clears the system call number before a group stop (do_signal() calls forget_syscall() before get_signal()). A thread stopped in a sleep therefore reads -1 sp pc, with pc moved back 4 bytes to the svc instruction so the call can restart. The aarch64 entry in _SYS_SLEEP could never match, and the tests timed out with "not seen asleep within 10.0 s".

Confirmed on aarch64 hardware (Ubuntu 24.04 container, kernel 6.8). A process blocked in sleep reads 115 … pc while running and -1 sp pc-4 after SIGSTOP. wchan doesn't help, because a stopped thread always shows do_signal_stop.

Fix (test only, tests/test_crash_handler_integration.py):

  • The helper reads the main thread's syscall file once just before the SIGSTOP.
  • On aarch64, a stopped -1 read whose pc is exactly 4 bytes before the pc of a sleep seen in that earlier read counts as that sleep.
  • The sleep-number table and the check that the pc is in libc are unchanged.
  • x86_64 takes the same path as before, plus one extra read before the stop.

I didn't drop the aarch64 entry and fall back to a plain kill(2), because that's what #828 replaced after it hung 14 of 60 runs.

Results (aarch64 TSan build):

master this PR
crash tests using the helper 5 of 6 time out on every run (TCP and TLS) all 6 pass, in 4 TCP and 4 TLS runs

With the fix, the crash stack shows the signal arriving in libc clock_nanosleep, called from sleep. A unit check of the helper with mocked /proc files passes all 14 cases for both architectures.

Not changed: a sleep resumed after SIGCONT shows as restart_syscall and is still refused. The issue calls this a nit, and the tests don't hit it.

🤖 Generated with Claude Code


Note

Low Risk
Test-only changes to TSan crash integration helpers; no production crash-handler or runtime behavior is modified.

Overview
Fixes aarch64 TSan crash-handler integration tests that timed out because the helper could not recognize the main thread as sleeping in libc after SIGSTOP.

The TSan signaling path still stops memtier and only delivers the crash signal when the main thread is in libc nanosleep/clock_nanosleep. The change splits syscall inspection into _main_thread_syscall() and extends _main_thread_sleeping() with an optional pre-SIGSTOP snapshot. On arm64, when /proc/.../syscall shows syscall number -1 after a group stop but the PC is 4 bytes before the PC from that snapshot, the code reuses the earlier syscall number (kernel clears it via forget_syscall()). _signal_tsan_main() now reads syscall state immediately before SIGSTOP and passes it through. x86_64 behavior is unchanged aside from one extra read; libc mapping checks and the sleep syscall table are the same.

Reviewed by Cursor Bugbot for commit 2b28c96. Bugbot is set up for automated code reviews on this repo. Configure here.

fcostaoliveira and others added 2 commits October 25, 2026 08:28
The TSan crash tests SIGSTOP memtier and send the SIGSEGV only when
/proc/<pid>/task/<pid>/syscall shows the main thread in nanosleep or
clock_nanosleep. On arm64, do_signal() calls forget_syscall() before
get_signal(), where the group stop happens, so a thread stopped in a sleep
reads "-1 sp pc" and the aarch64 entry in _SYS_SLEEP could never match.
Every test using the helper failed after 10 s with "not seen asleep" on an
aarch64 TSan build (5 of 6 tests in the file, confirmed in an Ubuntu 24.04
aarch64 container).

The pc is still reported, moved back to the svc instruction so the call
restarts. So read the syscall file once more just before the SIGSTOP, and on
aarch64 accept a stop whose pc is 4 bytes before the pc of a sleep seen in
that read. The libc check on pc stays. x86_64 keeps its number and is
checked exactly as before.

Fixes #843.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira merged commit 04f0f5d into master Oct 26, 2026
58 of 59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: _main_thread_sleeping() can never see a sleep on aarch64, because arm64 clears the syscall number before a SIGSTOP group stop

1 participant