aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cgroup.c248
-rw-r--r--kernel/elfcore.c10
-rw-r--r--kernel/pid_namespace.c8
-rw-r--r--kernel/signal.c2
4 files changed, 12 insertions, 256 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 8bd9cfdc70d7..e0839bcd48c8 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -125,38 +125,6 @@ struct cfent {
125}; 125};
126 126
127/* 127/*
128 * CSS ID -- ID per subsys's Cgroup Subsys State(CSS). used only when
129 * cgroup_subsys->use_id != 0.
130 */
131#define CSS_ID_MAX (65535)
132struct css_id {
133 /*
134 * The css to which this ID points. This pointer is set to valid value
135 * after cgroup is populated. If cgroup is removed, this will be NULL.
136 * This pointer is expected to be RCU-safe because destroy()
137 * is called after synchronize_rcu(). But for safe use, css_tryget()
138 * should be used for avoiding race.
139 */
140 struct cgroup_subsys_state __rcu *css;
141 /*
142 * ID of this css.
143 */
144 unsigned short id;
145 /*
146 * Depth in hierarchy which this ID belongs to.
147 */
148 unsigned short depth;
149 /*
150 * ID is freed by RCU. (and lookup routine is RCU safe.)
151 */
152 struct rcu_head rcu_head;
153 /*
154 * Hierarchy of CSS ID belongs to.
155 */
156 unsigned short stack[0]; /* Array of Length (depth+1) */
157};
158
159/*
160 * cgroup_event represents events which userspace want to receive. 128 * cgroup_event represents events which userspace want to receive.
161 */ 129 */
162struct cgroup_event { 130struct cgroup_event {
@@ -387,9 +355,6 @@ struct cgrp_cset_link {
387static struct css_set init_css_set; 355static struct css_set init_css_set;
388static struct cgrp_cset_link init_cgrp_cset_link; 356static struct cgrp_cset_link init_cgrp_cset_link;
389 357
390static int cgroup_init_idr(struct cgroup_subsys *ss,
391 struct cgroup_subsys_state *css);
392
393/* 358/*
394 * css_set_lock protects the list of css_set objects, and the chain of 359 * css_set_lock protects the list of css_set objects, and the chain of
395 * tasks off each css_set. Nests outside task->alloc_lock due to 360 * tasks off each css_set. Nests outside task->alloc_lock due to
@@ -841,8 +806,6 @@ static struct backing_dev_info cgroup_backing_dev_info = {
841 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK, 806 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
842}; 807};
843 808
844static int alloc_css_id(struct cgroup_subsys_state *child_css);
845
846static struct inode *cgroup_new_inode(umode_t mode, struct super_block *sb) 809static struct inode *cgroup_new_inode(umode_t mode, struct super_block *sb)
847{ 810{
848 struct inode *inode = new_inode(sb); 811 struct inode *inode = new_inode(sb);
@@ -4240,21 +4203,6 @@ static int cgroup_populate_dir(struct cgroup *cgrp, unsigned long subsys_mask)
4240 goto err; 4203 goto err;
4241 } 4204 }
4242 } 4205 }
4243
4244 /* This cgroup is ready now */
4245 for_each_root_subsys(cgrp->root, ss) {
4246 struct cgroup_subsys_state *css = cgroup_css(cgrp, ss);
4247 struct css_id *id = rcu_dereference_protected(css->id, true);
4248
4249 /*
4250 * Update id->css pointer and make this css visible from
4251 * CSS ID functions. This pointer will be dereferened
4252 * from RCU-read-side without locks.
4253 */
4254 if (id)
4255 rcu_assign_pointer(id->css, css);
4256 }
4257
4258 return 0; 4206 return 0;
4259err: 4207err:
4260 cgroup_clear_dir(cgrp, subsys_mask); 4208 cgroup_clear_dir(cgrp, subsys_mask);
@@ -4323,7 +4271,6 @@ static void init_css(struct cgroup_subsys_state *css, struct cgroup_subsys *ss,
4323 css->cgroup = cgrp; 4271 css->cgroup = cgrp;
4324 css->ss = ss; 4272 css->ss = ss;
4325 css->flags = 0; 4273 css->flags = 0;
4326 css->id = NULL;
4327 4274
4328 if (cgrp->parent) 4275 if (cgrp->parent)
4329 css->parent = cgroup_css(cgrp->parent, ss); 4276 css->parent = cgroup_css(cgrp->parent, ss);
@@ -4455,12 +4402,6 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4455 goto err_free_all; 4402 goto err_free_all;
4456 4403
4457 init_css(css, ss, cgrp); 4404 init_css(css, ss, cgrp);
4458
4459 if (ss->use_id) {
4460 err = alloc_css_id(css);
4461 if (err)
4462 goto err_free_all;
4463 }
4464 } 4405 }
4465 4406
4466 /* 4407 /*
@@ -4925,12 +4866,6 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)
4925 4866
4926 /* our new subsystem will be attached to the dummy hierarchy. */ 4867 /* our new subsystem will be attached to the dummy hierarchy. */
4927 init_css(css, ss, cgroup_dummy_top); 4868 init_css(css, ss, cgroup_dummy_top);
4928 /* init_idr must be after init_css() because it sets css->id. */
4929 if (ss->use_id) {
4930 ret = cgroup_init_idr(ss, css);
4931 if (ret)
4932 goto err_unload;
4933 }
4934 4869
4935 /* 4870 /*
4936 * Now we need to entangle the css into the existing css_sets. unlike 4871 * Now we need to entangle the css into the existing css_sets. unlike
@@ -4996,9 +4931,6 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)
4996 4931
4997 offline_css(cgroup_css(cgroup_dummy_top, ss)); 4932 offline_css(cgroup_css(cgroup_dummy_top, ss));
4998 4933
4999 if (ss->use_id)
5000 idr_destroy(&ss->idr);
5001
5002 /* deassign the subsys_id */ 4934 /* deassign the subsys_id */
5003 cgroup_subsys[ss->subsys_id] = NULL; 4935 cgroup_subsys[ss->subsys_id] = NULL;
5004 4936
@@ -5025,8 +4957,7 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)
5025 /* 4957 /*
5026 * remove subsystem's css from the cgroup_dummy_top and free it - 4958 * remove subsystem's css from the cgroup_dummy_top and free it -
5027 * need to free before marking as null because ss->css_free needs 4959 * need to free before marking as null because ss->css_free needs
5028 * the cgrp->subsys pointer to find their state. note that this 4960 * the cgrp->subsys pointer to find their state.
5029 * also takes care of freeing the css_id.
5030 */ 4961 */
5031 ss->css_free(cgroup_css(cgroup_dummy_top, ss)); 4962 ss->css_free(cgroup_css(cgroup_dummy_top, ss));
5032 RCU_INIT_POINTER(cgroup_dummy_top->subsys[ss->subsys_id], NULL); 4963 RCU_INIT_POINTER(cgroup_dummy_top->subsys[ss->subsys_id], NULL);
@@ -5097,8 +5028,6 @@ int __init cgroup_init(void)
5097 for_each_builtin_subsys(ss, i) { 5028 for_each_builtin_subsys(ss, i) {
5098 if (!ss->early_init) 5029 if (!ss->early_init)
5099 cgroup_init_subsys(ss); 5030 cgroup_init_subsys(ss);
5100 if (ss->use_id)
5101 cgroup_init_idr(ss, init_css_set.subsys[ss->subsys_id]);
5102 } 5031 }
5103 5032
5104 /* allocate id for the dummy hierarchy */ 5033 /* allocate id for the dummy hierarchy */
@@ -5518,181 +5447,6 @@ static int __init cgroup_disable(char *str)
5518} 5447}
5519__setup("cgroup_disable=", cgroup_disable); 5448__setup("cgroup_disable=", cgroup_disable);
5520 5449
5521/*
5522 * Functons for CSS ID.
5523 */
5524
5525/* to get ID other than 0, this should be called when !cgroup_is_dead() */
5526unsigned short css_id(struct cgroup_subsys_state *css)
5527{
5528 struct css_id *cssid;
5529
5530 /*
5531 * This css_id() can return correct value when somone has refcnt
5532 * on this or this is under rcu_read_lock(). Once css->id is allocated,
5533 * it's unchanged until freed.
5534 */
5535 cssid = rcu_dereference_raw(css->id);
5536
5537 if (cssid)
5538 return cssid->id;
5539 return 0;
5540}
5541EXPORT_SYMBOL_GPL(css_id);
5542
5543/**
5544 * css_is_ancestor - test "root" css is an ancestor of "child"
5545 * @child: the css to be tested.
5546 * @root: the css supporsed to be an ancestor of the child.
5547 *
5548 * Returns true if "root" is an ancestor of "child" in its hierarchy. Because
5549 * this function reads css->id, the caller must hold rcu_read_lock().
5550 * But, considering usual usage, the csses should be valid objects after test.
5551 * Assuming that the caller will do some action to the child if this returns
5552 * returns true, the caller must take "child";s reference count.
5553 * If "child" is valid object and this returns true, "root" is valid, too.
5554 */
5555
5556bool css_is_ancestor(struct cgroup_subsys_state *child,
5557 const struct cgroup_subsys_state *root)
5558{
5559 struct css_id *child_id;
5560 struct css_id *root_id;
5561
5562 child_id = rcu_dereference(child->id);
5563 if (!child_id)
5564 return false;
5565 root_id = rcu_dereference(root->id);
5566 if (!root_id)
5567 return false;
5568 if (child_id->depth < root_id->depth)
5569 return false;
5570 if (child_id->stack[root_id->depth] != root_id->id)
5571 return false;
5572 return true;
5573}
5574
5575void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css)
5576{
5577 struct css_id *id = rcu_dereference_protected(css->id, true);
5578
5579 /* When this is called before css_id initialization, id can be NULL */
5580 if (!id)
5581 return;
5582
5583 BUG_ON(!ss->use_id);
5584
5585 rcu_assign_pointer(id->css, NULL);
5586 rcu_assign_pointer(css->id, NULL);
5587 spin_lock(&ss->id_lock);
5588 idr_remove(&ss->idr, id->id);
5589 spin_unlock(&ss->id_lock);
5590 kfree_rcu(id, rcu_head);
5591}
5592EXPORT_SYMBOL_GPL(free_css_id);
5593
5594/*
5595 * This is called by init or create(). Then, calls to this function are
5596 * always serialized (By cgroup_mutex() at create()).
5597 */
5598
5599static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth)
5600{
5601 struct css_id *newid;
5602 int ret, size;
5603
5604 BUG_ON(!ss->use_id);
5605
5606 size = sizeof(*newid) + sizeof(unsigned short) * (depth + 1);
5607 newid = kzalloc(size, GFP_KERNEL);
5608 if (!newid)
5609 return ERR_PTR(-ENOMEM);
5610
5611 idr_preload(GFP_KERNEL);
5612 spin_lock(&ss->id_lock);
5613 /* Don't use 0. allocates an ID of 1-65535 */
5614 ret = idr_alloc(&ss->idr, newid, 1, CSS_ID_MAX + 1, GFP_NOWAIT);
5615 spin_unlock(&ss->id_lock);
5616 idr_preload_end();
5617
5618 /* Returns error when there are no free spaces for new ID.*/
5619 if (ret < 0)
5620 goto err_out;
5621
5622 newid->id = ret;
5623 newid->depth = depth;
5624 return newid;
5625err_out:
5626 kfree(newid);
5627 return ERR_PTR(ret);
5628
5629}
5630
5631static int __init_or_module cgroup_init_idr(struct cgroup_subsys *ss,
5632 struct cgroup_subsys_state *rootcss)
5633{
5634 struct css_id *newid;
5635
5636 spin_lock_init(&ss->id_lock);
5637 idr_init(&ss->idr);
5638
5639 newid = get_new_cssid(ss, 0);
5640 if (IS_ERR(newid))
5641 return PTR_ERR(newid);
5642
5643 newid->stack[0] = newid->id;
5644 RCU_INIT_POINTER(newid->css, rootcss);
5645 RCU_INIT_POINTER(rootcss->id, newid);
5646 return 0;
5647}
5648
5649static int alloc_css_id(struct cgroup_subsys_state *child_css)
5650{
5651 struct cgroup_subsys_state *parent_css = css_parent(child_css);
5652 struct css_id *child_id, *parent_id;
5653 int i, depth;
5654
5655 parent_id = rcu_dereference_protected(parent_css->id, true);
5656 depth = parent_id->depth + 1;
5657
5658 child_id = get_new_cssid(child_css->ss, depth);
5659 if (IS_ERR(child_id))
5660 return PTR_ERR(child_id);
5661
5662 for (i = 0; i < depth; i++)
5663 child_id->stack[i] = parent_id->stack[i];
5664 child_id->stack[depth] = child_id->id;
5665 /*
5666 * child_id->css pointer will be set after this cgroup is available
5667 * see cgroup_populate_dir()
5668 */
5669 rcu_assign_pointer(child_css->id, child_id);
5670
5671 return 0;
5672}
5673
5674/**
5675 * css_lookup - lookup css by id
5676 * @ss: cgroup subsys to be looked into.
5677 * @id: the id
5678 *
5679 * Returns pointer to cgroup_subsys_state if there is valid one with id.
5680 * NULL if not. Should be called under rcu_read_lock()
5681 */
5682struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id)
5683{
5684 struct css_id *cssid = NULL;
5685
5686 BUG_ON(!ss->use_id);
5687 cssid = idr_find(&ss->idr, id);
5688
5689 if (unlikely(!cssid))
5690 return NULL;
5691
5692 return rcu_dereference(cssid->css);
5693}
5694EXPORT_SYMBOL_GPL(css_lookup);
5695
5696/** 5450/**
5697 * css_from_dir - get corresponding css from the dentry of a cgroup dir 5451 * css_from_dir - get corresponding css from the dentry of a cgroup dir
5698 * @dentry: directory dentry of interest 5452 * @dentry: directory dentry of interest
diff --git a/kernel/elfcore.c b/kernel/elfcore.c
index ff915efef66d..e556751d15d9 100644
--- a/kernel/elfcore.c
+++ b/kernel/elfcore.c
@@ -1,23 +1,19 @@
1#include <linux/elf.h> 1#include <linux/elf.h>
2#include <linux/fs.h> 2#include <linux/fs.h>
3#include <linux/mm.h> 3#include <linux/mm.h>
4 4#include <linux/binfmts.h>
5#include <asm/elf.h>
6
7 5
8Elf_Half __weak elf_core_extra_phdrs(void) 6Elf_Half __weak elf_core_extra_phdrs(void)
9{ 7{
10 return 0; 8 return 0;
11} 9}
12 10
13int __weak elf_core_write_extra_phdrs(struct file *file, loff_t offset, size_t *size, 11int __weak elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset)
14 unsigned long limit)
15{ 12{
16 return 1; 13 return 1;
17} 14}
18 15
19int __weak elf_core_write_extra_data(struct file *file, size_t *size, 16int __weak elf_core_write_extra_data(struct coredump_params *cprm)
20 unsigned long limit)
21{ 17{
22 return 1; 18 return 1;
23} 19}
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 42086551a24a..06c62de9c711 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -132,6 +132,12 @@ out:
132 return ERR_PTR(err); 132 return ERR_PTR(err);
133} 133}
134 134
135static void delayed_free_pidns(struct rcu_head *p)
136{
137 kmem_cache_free(pid_ns_cachep,
138 container_of(p, struct pid_namespace, rcu));
139}
140
135static void destroy_pid_namespace(struct pid_namespace *ns) 141static void destroy_pid_namespace(struct pid_namespace *ns)
136{ 142{
137 int i; 143 int i;
@@ -140,7 +146,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns)
140 for (i = 0; i < PIDMAP_ENTRIES; i++) 146 for (i = 0; i < PIDMAP_ENTRIES; i++)
141 kfree(ns->pidmap[i].page); 147 kfree(ns->pidmap[i].page);
142 put_user_ns(ns->user_ns); 148 put_user_ns(ns->user_ns);
143 kmem_cache_free(pid_ns_cachep, ns); 149 call_rcu(&ns->rcu, delayed_free_pidns);
144} 150}
145 151
146struct pid_namespace *copy_pid_ns(unsigned long flags, 152struct pid_namespace *copy_pid_ns(unsigned long flags,
diff --git a/kernel/signal.c b/kernel/signal.c
index ded28b91fa53..940b30ee9a30 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2723,7 +2723,7 @@ COMPAT_SYSCALL_DEFINE2(rt_sigpending, compat_sigset_t __user *, uset,
2723 2723
2724#ifndef HAVE_ARCH_COPY_SIGINFO_TO_USER 2724#ifndef HAVE_ARCH_COPY_SIGINFO_TO_USER
2725 2725
2726int copy_siginfo_to_user(siginfo_t __user *to, siginfo_t *from) 2726int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from)
2727{ 2727{
2728 int err; 2728 int err;
2729 2729