cgroupfs: don't add a task in the root cgroup if it is already there.

PiperOrigin-RevId: 377975013
This commit is contained in:
Andrei Vagin
2021-06-07 12:15:39 -07:00
committed by gVisor bot
parent ee1003bde2
commit 7e4e71253e
2 changed files with 11 additions and 1 deletions
+3 -1
View File
@@ -1861,7 +1861,9 @@ func (k *Kernel) PopulateNewCgroupHierarchy(root Cgroup) {
return
}
t.mu.Lock()
t.enterCgroupLocked(root)
// A task can be in the cgroup if it has been created after the
// cgroup hierarchy was registered.
t.enterCgroupIfNotYetLocked(root)
t.mu.Unlock()
})
k.tasks.mu.RUnlock()
+8
View File
@@ -85,6 +85,14 @@ func (t *Task) enterCgroupLocked(c Cgroup) {
c.Enter(t)
}
// +checklocks:t.mu
func (t *Task) enterCgroupIfNotYetLocked(c Cgroup) {
if _, ok := t.cgroups[c]; ok {
return
}
t.enterCgroupLocked(c)
}
// LeaveCgroups removes t out from all its cgroups.
func (t *Task) LeaveCgroups() {
t.mu.Lock()