hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/kernel/cgroup/pids.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Process number limiting controller for cgroups.
34 *
....@@ -25,10 +26,6 @@
2526 * a superset of parent/child/pids.current.
2627 *
2728 * Copyright (C) 2015 Aleksa Sarai <cyphar@cyphar.com>
28
- *
29
- * This file is subject to the terms and conditions of version 2 of the GNU
30
- * General Public License. See the file COPYING in the main directory of the
31
- * Linux distribution for more details.
3229 */
3330
3431 #include <linux/kernel.h>
....@@ -36,6 +33,7 @@
3633 #include <linux/atomic.h>
3734 #include <linux/cgroup.h>
3835 #include <linux/slab.h>
36
+#include <linux/sched/task.h>
3937
4038 #define PIDS_MAX (PID_MAX_LIMIT + 1ULL)
4139 #define PIDS_MAX_STR "max"
....@@ -217,13 +215,16 @@
217215 * task_css_check(true) in pids_can_fork() and pids_cancel_fork() relies
218216 * on cgroup_threadgroup_change_begin() held by the copy_process().
219217 */
220
-static int pids_can_fork(struct task_struct *task)
218
+static int pids_can_fork(struct task_struct *task, struct css_set *cset)
221219 {
222220 struct cgroup_subsys_state *css;
223221 struct pids_cgroup *pids;
224222 int err;
225223
226
- css = task_css_check(current, pids_cgrp_id, true);
224
+ if (cset)
225
+ css = cset->subsys[pids_cgrp_id];
226
+ else
227
+ css = task_css_check(current, pids_cgrp_id, true);
227228 pids = css_pids(css);
228229 err = pids_try_charge(pids, 1);
229230 if (err) {
....@@ -238,12 +239,15 @@
238239 return err;
239240 }
240241
241
-static void pids_cancel_fork(struct task_struct *task)
242
+static void pids_cancel_fork(struct task_struct *task, struct css_set *cset)
242243 {
243244 struct cgroup_subsys_state *css;
244245 struct pids_cgroup *pids;
245246
246
- css = task_css_check(current, pids_cgrp_id, true);
247
+ if (cset)
248
+ css = cset->subsys[pids_cgrp_id];
249
+ else
250
+ css = task_css_check(current, pids_cgrp_id, true);
247251 pids = css_pids(css);
248252 pids_uncharge(pids, 1);
249253 }