Repository navigation
Do not acquire cgroup2fs locks under the registry mutex - #14809
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
test/cl982748219
branch
from
September 17, 2026 22:42
fe38cc5 to
3e226e1
Compare
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
Bot
force-pushed
the
test/cl982748219
branch
from
September 17, 2026 23:43
3e226e1 to
1ce6569
Compare
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.
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.