Skip to content

Commit 80868f5

Browse files
committed
Merge tag 'cgroup-for-6.14-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup fixes from Tejun Heo: - Fix a race window where a newly forked task could escape cgroup.kill - Remove incorrectly included steal time from cpu.stat::usage_usec - Minor update in selftest * tag 'cgroup-for-6.14-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: cgroup: Remove steal time from usage_usec selftests/cgroup: use bash in test_cpuset_v1_hp.sh cgroup: fix race between fork and cgroup.kill
2 parents f4d4680 + db5fd3c commit 80868f5

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

include/linux/cgroup-defs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ enum {
7171

7272
/* Cgroup is frozen. */
7373
CGRP_FROZEN,
74-
75-
/* Control group has to be killed. */
76-
CGRP_KILL,
7774
};
7875

7976
/* cgroup_root->flags */
@@ -461,6 +458,9 @@ struct cgroup {
461458

462459
int nr_threaded_children; /* # of live threaded child cgroups */
463460

461+
/* sequence number for cgroup.kill, serialized by css_set_lock. */
462+
unsigned int kill_seq;
463+
464464
struct kernfs_node *kn; /* cgroup kernfs entry */
465465
struct cgroup_file procs_file; /* handle for "cgroup.procs" */
466466
struct cgroup_file events_file; /* handle for "cgroup.events" */

include/linux/sched/task.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct kernel_clone_args {
4343
void *fn_arg;
4444
struct cgroup *cgrp;
4545
struct css_set *cset;
46+
unsigned int kill_seq;
4647
};
4748

4849
/*

kernel/cgroup/cgroup.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4013,7 +4013,7 @@ static void __cgroup_kill(struct cgroup *cgrp)
40134013
lockdep_assert_held(&cgroup_mutex);
40144014

40154015
spin_lock_irq(&css_set_lock);
4016-
set_bit(CGRP_KILL, &cgrp->flags);
4016+
cgrp->kill_seq++;
40174017
spin_unlock_irq(&css_set_lock);
40184018

40194019
css_task_iter_start(&cgrp->self, CSS_TASK_ITER_PROCS | CSS_TASK_ITER_THREADED, &it);
@@ -4029,10 +4029,6 @@ static void __cgroup_kill(struct cgroup *cgrp)
40294029
send_sig(SIGKILL, task, 0);
40304030
}
40314031
css_task_iter_end(&it);
4032-
4033-
spin_lock_irq(&css_set_lock);
4034-
clear_bit(CGRP_KILL, &cgrp->flags);
4035-
spin_unlock_irq(&css_set_lock);
40364032
}
40374033

40384034
static void cgroup_kill(struct cgroup *cgrp)
@@ -6488,6 +6484,10 @@ static int cgroup_css_set_fork(struct kernel_clone_args *kargs)
64886484
spin_lock_irq(&css_set_lock);
64896485
cset = task_css_set(current);
64906486
get_css_set(cset);
6487+
if (kargs->cgrp)
6488+
kargs->kill_seq = kargs->cgrp->kill_seq;
6489+
else
6490+
kargs->kill_seq = cset->dfl_cgrp->kill_seq;
64916491
spin_unlock_irq(&css_set_lock);
64926492

64936493
if (!(kargs->flags & CLONE_INTO_CGROUP)) {
@@ -6668,6 +6668,7 @@ void cgroup_post_fork(struct task_struct *child,
66686668
struct kernel_clone_args *kargs)
66696669
__releases(&cgroup_threadgroup_rwsem) __releases(&cgroup_mutex)
66706670
{
6671+
unsigned int cgrp_kill_seq = 0;
66716672
unsigned long cgrp_flags = 0;
66726673
bool kill = false;
66736674
struct cgroup_subsys *ss;
@@ -6681,10 +6682,13 @@ void cgroup_post_fork(struct task_struct *child,
66816682

66826683
/* init tasks are special, only link regular threads */
66836684
if (likely(child->pid)) {
6684-
if (kargs->cgrp)
6685+
if (kargs->cgrp) {
66856686
cgrp_flags = kargs->cgrp->flags;
6686-
else
6687+
cgrp_kill_seq = kargs->cgrp->kill_seq;
6688+
} else {
66876689
cgrp_flags = cset->dfl_cgrp->flags;
6690+
cgrp_kill_seq = cset->dfl_cgrp->kill_seq;
6691+
}
66886692

66896693
WARN_ON_ONCE(!list_empty(&child->cg_list));
66906694
cset->nr_tasks++;
@@ -6719,7 +6723,7 @@ void cgroup_post_fork(struct task_struct *child,
67196723
* child down right after we finished preparing it for
67206724
* userspace.
67216725
*/
6722-
kill = test_bit(CGRP_KILL, &cgrp_flags);
6726+
kill = kargs->kill_seq != cgrp_kill_seq;
67236727
}
67246728

67256729
spin_unlock_irq(&css_set_lock);

kernel/cgroup/rstat.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ static void root_cgroup_cputime(struct cgroup_base_stat *bstat)
590590

591591
cputime->sum_exec_runtime += user;
592592
cputime->sum_exec_runtime += sys;
593-
cputime->sum_exec_runtime += cpustat[CPUTIME_STEAL];
594593

595594
#ifdef CONFIG_SCHED_CORE
596595
bstat->forceidle_sum += cpustat[CPUTIME_FORCEIDLE];

tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33
#
44
# Test the special cpuset v1 hotplug case where a cpuset become empty of

0 commit comments

Comments
 (0)