Skip to content

Do not acquire cgroup2fs locks under the registry mutex - #14809

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test/cl982748219
Sep 17, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test/cl982748219

Conversation

@copybara-service

Copy link
Copy Markdown

Do not acquire cgroup2fs locks under the registry mutex

Task creation takes the cgroup registry mutex while holding the new
thread group's signal handlers mutex. The registry in turn took the
cgroup2fs tasksMu when a v1 mount stole or returned the memory
controller. Together with cgroup.kill, which sends signals under
tasksMu, this formed a lock order cycle:

signalHandlers.mu -> registry.mu -> tasksMu -> signalHandlers.mu

The middle edge exists only when v1 and v2 hierarchies are used
together, with a v1 mount taking a controller away from the v2 tree.
Such mixed usage is highly unlikely in practice, which is why the
cycle went unnoticed.

Fix it by making the registry mutex a strict leaf: the steal and
return of v2 controllers now happen outside the registry critical
sections. This is race-free because every registry mutator holds the
cgroup2fs tree lock exclusively for its full duration.

Also fix the stale cgroupfs lock order comment, which had the
registry mutex above the kernfs and TaskSet locks.

Add a test that writes cgroup.kill while the memory controller is
mounted in a v1 hierarchy. Lock dependency checking builds (the
lockdep go build tag) deterministically detected the cycle with it.

@copybara-service copybara-service Bot added the exported Issue was exported automatically label Sep 17, 2026
Task creation takes the cgroup registry mutex while holding the new
thread group's signal handlers mutex. The registry in turn took the
cgroup2fs tasksMu when a v1 mount stole or returned the memory
controller. Together with cgroup.kill, which sends signals under
tasksMu, this formed a lock order cycle:

  signalHandlers.mu -> registry.mu -> tasksMu -> signalHandlers.mu

The middle edge exists only when v1 and v2 hierarchies are used
together, with a v1 mount taking a controller away from the v2 tree.
Such mixed usage is highly unlikely in practice, which is why the
cycle went unnoticed.

Fix it by making the registry mutex a strict leaf: the steal and
return of v2 controllers now happen outside the registry critical
sections. This is race-free because every registry mutator holds the
cgroup2fs tree lock exclusively for its full duration.

Also fix the stale cgroupfs lock order comment, which had the
registry mutex above the kernfs and TaskSet locks.

Add a test that writes cgroup.kill while the memory controller is
mounted in a v1 hierarchy. Lock dependency checking builds (the
lockdep go build tag) deterministically detected the cycle with it.

PiperOrigin-RevId: 983495416
@copybara-service
copybara-service Bot merged commit 1ce6569 into master Sep 17, 2026
6 of 10 checks passed
@copybara-service
copybara-service Bot deleted the test/cl982748219 branch September 17, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exported Issue was exported automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址