Skip to content

Let the kernel mark the robust futexes of an exiting task - #4162

Open
Keno wants to merge 1 commit into
rr-debugger:masterfrom
ChronitonAI:robust-futex-owner-death-wake
Open

Keno wants to merge 1 commit into
rr-debugger:masterfrom
ChronitonAI:robust-futex-owner-death-wake

Conversation

@Keno

@Keno Keno commented Nov 18, 2026

Copy link
Copy Markdown
Member

[Part 3 of the futex series. Encountered, debugged, patch, test by AI. Note that in reviewing this I've found a couple more corner cases that will be separate PRs, so there's probably 2 more PRs in this series]

When a task exits holding a robust futex, the kernel marks it FUTEX_OWNER_DIED and wakes a waiter. rr marked the futexes itself at PTRACE_EVENT_EXIT, so the kernel no longer found the task's tid in them and didn't wake the waiter, which then blocked forever. When we wait for the task to exit, the kernel's writes can't race with other tracees, so leave them to the kernel, as for the child tid.

Tests: robust_futex_owner_died, robust_futex_owner_died_thread, robust_futex_walk.

rr marked an exiting task's robust futexes FUTEX_OWNER_DIED itself at
PTRACE_EVENT_EXIT, so the kernel no longer found the task's tid in
them and didn't wake their waiters, which blocked forever. When we
wait for the task to exit, the kernel's writes can't race with other
tracees, so leave them to the kernel, as for the child tid. Replay
still makes the writes rr records, so record what the kernel writes:
handle list_op_pending last, and also stop at an entry or futex the
kernel can't access and at a misaligned futex.

Tests: robust_futex_owner_died, robust_futex_owner_died_thread,
robust_futex_walk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/RecordSession.cc
// futexes' waiters. Otherwise make the writes now so that the kernel doesn't
// make them later, at a time that might race with other tracee execution.
for (auto& w : robust_futex_writes) {
if (!may_wait_exit) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pid namespace case here will be fixed in a separate PR, but it's a bit more complicated and needs a separate test, so I pulled it out of this one.

Comment thread src/RecordSession.cc
record_robust_futex_change<Arch>(t, head, current);
auto next = t->read_mem(current, &ok);
// The kernel reads the next entry before it handles this one, and it
// handles the pending futex, which may be on the list, last.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems pretty fragile, right? This behaviour could change and then we'd presumably have a bug in super weird edge cases. But maybe there's nothing we can do about it.

This branch has not been deployed

No deployments
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.

2 participants