Skip to content

fix(sched): closed the kill-before-block race in all blocking paths - #135

Open
FlareCoding wants to merge 1 commit into
masterfrom
pr/sched-block-protocol
Open

fix(sched): closed the kill-before-block race in all blocking paths#135
FlareCoding wants to merge 1 commit into
masterfrom
pr/sched-block-protocol

Conversation

@FlareCoding

@FlareCoding FlareCoding commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • force_wake_for_kill only acts on tasks already sleeping or BLOCKED, so a kill landing while the victim was still entering a block was silently lost — delayed until natural wakeup for sleeps, or until an unrelated wake for futexes. This is the root cause of the kill-suite CI flakes.
  • Blocking now uses a sched-owned protocol — prepare_to_block_task / block_task_interrupted_by_kill / cancel_block_task — adopted by the interruption-capable sites (sleep, futex, poll). poll_wait already hand-rolled exactly this pattern; its bespoke copy is deleted in favor of the shared one, which also adds the store-load fence pairing the hand-rolled version lacked.
  • Wait-queue waits keep their existing semantics (callers are not kill-aware; aborting there would turn kill-unaware wait loops into hot spins). wait() now uses the atomic-release state transition and both docs state the contract honestly. A wait_killable variant plus caller audit is explicit follow-up work.
  • Proof: new deterministic regression test (kill_before_sleep_aborts_sleep) fails on the unfixed kernel at exactly the 5 s natural expiry and passes with the fix; full suite 510/510 across repeated runs on both architectures.

Note

High Risk
Changes core scheduler blocking, kill delivery, and synchronization primitives (sleep, futex, poll); incorrect fencing or unwind logic could cause lost wakeups, stuck tasks, or spurious EINTR.

Overview
Fixes a race where force_wake_for_kill could miss a task still entering a block, so kills were delayed until natural wakeup (or unrelated wakes). The scheduler now owns a shared prepare → kill-check → cancel blocking protocol with SEQ_CST fences pairing force_wake_for_kill and block_task_interrupted_by_kill.

Sleep, futex wait, and poll_wait adopt that protocol: they unwind timers/waiters and return without yielding when a kill is seen at the commit point. poll_wait drops its local abort helper in favor of the shared cancel_block_task. sync::wait only switches to atomic prepare_to_block_task; docs state it is not kill-interruptible without caller loops on is_kill_pending().

Tests use wall-clock spin timeouts and wait_until_blocked instead of brief_delay, plus a new kill_before_sleep_aborts_sleep regression for pre-enqueue kills.

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

@cursor

cursor Bot commented Jul 28, 2026

Copy link
Copy Markdown

Current version of PR was reviewed by /review-bugbot on Jul 27, 20:32 PDT. It flagged 0 findings.

Bugbot on commit aa0aff5 is skipped.

@FlareCoding
FlareCoding force-pushed the pr/sched-block-protocol branch from aa0aff5 to dcc3660 Compare July 28, 2026 04:04

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit dcc3660. Configure here.

Comment thread kernel/sync/wait_queue.cpp Outdated
force_wake_for_kill only affects tasks already sleeping or BLOCKED, so
kills landing during block entry were lost until natural wakeup, or
forever for untimed waits. Blocking paths now publish BLOCKED, re-check
the kill behind a paired fence, and unwind instead of sleeping; poll's
bespoke version of this pattern moved into sched as the shared
protocol.

Co-authored-by: Cursor <cursoragent@cursor.com>
@FlareCoding
FlareCoding force-pushed the pr/sched-block-protocol branch from dcc3660 to 520abb2 Compare July 28, 2026 05:48
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.

1 participant