aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kernel/cgroup.c13
-rw-r--r--kernel/cgroup_pids.c34
2 files changed, 37 insertions, 10 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 75c0ff00aca6..33a2f63d4a10 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -61,7 +61,6 @@
61#include <linux/cpuset.h> 61#include <linux/cpuset.h>
62#include <linux/proc_ns.h> 62#include <linux/proc_ns.h>
63#include <linux/nsproxy.h> 63#include <linux/nsproxy.h>
64#include <linux/proc_ns.h>
65#include <net/sock.h> 64#include <net/sock.h>
66 65
67/* 66/*
@@ -1160,18 +1159,12 @@ static void cgroup_exit_root_id(struct cgroup_root *root)
1160{ 1159{
1161 lockdep_assert_held(&cgroup_mutex); 1160 lockdep_assert_held(&cgroup_mutex);
1162 1161
1163 if (root->hierarchy_id) { 1162 idr_remove(&cgroup_hierarchy_idr, root->hierarchy_id);
1164 idr_remove(&cgroup_hierarchy_idr, root->hierarchy_id);
1165 root->hierarchy_id = 0;
1166 }
1167} 1163}
1168 1164
1169static void cgroup_free_root(struct cgroup_root *root) 1165static void cgroup_free_root(struct cgroup_root *root)
1170{ 1166{
1171 if (root) { 1167 if (root) {
1172 /* hierarchy ID should already have been released */
1173 WARN_ON_ONCE(root->hierarchy_id);
1174
1175 idr_destroy(&root->cgroup_idr); 1168 idr_destroy(&root->cgroup_idr);
1176 kfree(root); 1169 kfree(root);
1177 } 1170 }
@@ -5146,6 +5139,8 @@ static struct cgroup_subsys_state *css_create(struct cgroup *cgrp,
5146 lockdep_assert_held(&cgroup_mutex); 5139 lockdep_assert_held(&cgroup_mutex);
5147 5140
5148 css = ss->css_alloc(parent_css); 5141 css = ss->css_alloc(parent_css);
5142 if (!css)
5143 css = ERR_PTR(-ENOMEM);
5149 if (IS_ERR(css)) 5144 if (IS_ERR(css))
5150 return css; 5145 return css;
5151 5146
@@ -6172,7 +6167,7 @@ struct cgroup_subsys_state *css_tryget_online_from_dir(struct dentry *dentry,
6172struct cgroup_subsys_state *css_from_id(int id, struct cgroup_subsys *ss) 6167struct cgroup_subsys_state *css_from_id(int id, struct cgroup_subsys *ss)
6173{ 6168{
6174 WARN_ON_ONCE(!rcu_read_lock_held()); 6169 WARN_ON_ONCE(!rcu_read_lock_held());
6175 return id > 0 ? idr_find(&ss->css_idr, id) : NULL; 6170 return idr_find(&ss->css_idr, id);
6176} 6171}
6177 6172
6178/** 6173/**
diff --git a/kernel/cgroup_pids.c b/kernel/cgroup_pids.c
index 303097b37429..2bd673783f1a 100644
--- a/kernel/cgroup_pids.c
+++ b/kernel/cgroup_pids.c
@@ -49,6 +49,12 @@ struct pids_cgroup {
49 */ 49 */
50 atomic64_t counter; 50 atomic64_t counter;
51 int64_t limit; 51 int64_t limit;
52
53 /* Handle for "pids.events" */
54 struct cgroup_file events_file;
55
56 /* Number of times fork failed because limit was hit. */
57 atomic64_t events_limit;
52}; 58};
53 59
54static struct pids_cgroup *css_pids(struct cgroup_subsys_state *css) 60static struct pids_cgroup *css_pids(struct cgroup_subsys_state *css)
@@ -72,6 +78,7 @@ pids_css_alloc(struct cgroup_subsys_state *parent)
72 78
73 pids->limit = PIDS_MAX; 79 pids->limit = PIDS_MAX;
74 atomic64_set(&pids->counter, 0); 80 atomic64_set(&pids->counter, 0);
81 atomic64_set(&pids->events_limit, 0);
75 return &pids->css; 82 return &pids->css;
76} 83}
77 84
@@ -213,10 +220,21 @@ static int pids_can_fork(struct task_struct *task)
213{ 220{
214 struct cgroup_subsys_state *css; 221 struct cgroup_subsys_state *css;
215 struct pids_cgroup *pids; 222 struct pids_cgroup *pids;
223 int err;
216 224
217 css = task_css_check(current, pids_cgrp_id, true); 225 css = task_css_check(current, pids_cgrp_id, true);
218 pids = css_pids(css); 226 pids = css_pids(css);
219 return pids_try_charge(pids, 1); 227 err = pids_try_charge(pids, 1);
228 if (err) {
229 /* Only log the first time events_limit is incremented. */
230 if (atomic64_inc_return(&pids->events_limit) == 1) {
231 pr_info("cgroup: fork rejected by pids controller in ");
232 pr_cont_cgroup_path(task_cgroup(current, pids_cgrp_id));
233 pr_cont("\n");
234 }
235 cgroup_file_notify(&pids->events_file);
236 }
237 return err;
220} 238}
221 239
222static void pids_cancel_fork(struct task_struct *task) 240static void pids_cancel_fork(struct task_struct *task)
@@ -288,6 +306,14 @@ static s64 pids_current_read(struct cgroup_subsys_state *css,
288 return atomic64_read(&pids->counter); 306 return atomic64_read(&pids->counter);
289} 307}
290 308
309static int pids_events_show(struct seq_file *sf, void *v)
310{
311 struct pids_cgroup *pids = css_pids(seq_css(sf));
312
313 seq_printf(sf, "max %lld\n", (s64)atomic64_read(&pids->events_limit));
314 return 0;
315}
316
291static struct cftype pids_files[] = { 317static struct cftype pids_files[] = {
292 { 318 {
293 .name = "max", 319 .name = "max",
@@ -300,6 +326,12 @@ static struct cftype pids_files[] = {
300 .read_s64 = pids_current_read, 326 .read_s64 = pids_current_read,
301 .flags = CFTYPE_NOT_ON_ROOT, 327 .flags = CFTYPE_NOT_ON_ROOT,
302 }, 328 },
329 {
330 .name = "events",
331 .seq_show = pids_events_show,
332 .file_offset = offsetof(struct pids_cgroup, events_file),
333 .flags = CFTYPE_NOT_ON_ROOT,
334 },
303 { } /* terminate */ 335 { } /* terminate */
304}; 336};
305 337