mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-24 21:54:34 -04:00
cgroups: read-write lock CLONE_THREAD forking per threadgroup
Adds functionality to read/write lock CLONE_THREAD fork()ing per-threadgroup Add an rwsem that lives in a threadgroup's signal_struct that's taken for reading in the fork path, under CONFIG_CGROUPS. If another part of the kernel later wants to use such a locking mechanism, the CONFIG_CGROUPS ifdefs should be changed to a higher-up flag that CGROUPS and the other system would both depend on. This is a pre-patch for cgroup-procs-write.patch. Signed-off-by: Ben Blum <bblum@andrew.cmu.edu> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Cc: Matt Helsley <matthltc@us.ibm.com> Reviewed-by: Paul Menage <menage@google.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: David Rientjes <rientjes@google.com> Cc: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
dcb3a08e69
commit
4714d1d32d
3 changed files with 55 additions and 0 deletions
|
|
@ -22,6 +22,14 @@
|
|||
extern struct files_struct init_files;
|
||||
extern struct fs_struct init_fs;
|
||||
|
||||
#ifdef CONFIG_CGROUPS
|
||||
#define INIT_THREADGROUP_FORK_LOCK(sig) \
|
||||
.threadgroup_fork_lock = \
|
||||
__RWSEM_INITIALIZER(sig.threadgroup_fork_lock),
|
||||
#else
|
||||
#define INIT_THREADGROUP_FORK_LOCK(sig)
|
||||
#endif
|
||||
|
||||
#define INIT_SIGNALS(sig) { \
|
||||
.nr_threads = 1, \
|
||||
.wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\
|
||||
|
|
@ -38,6 +46,7 @@ extern struct fs_struct init_fs;
|
|||
}, \
|
||||
.cred_guard_mutex = \
|
||||
__MUTEX_INITIALIZER(sig.cred_guard_mutex), \
|
||||
INIT_THREADGROUP_FORK_LOCK(sig) \
|
||||
}
|
||||
|
||||
extern struct nsproxy init_nsproxy;
|
||||
|
|
|
|||
|
|
@ -513,6 +513,7 @@ struct thread_group_cputimer {
|
|||
spinlock_t lock;
|
||||
};
|
||||
|
||||
#include <linux/rwsem.h>
|
||||
struct autogroup;
|
||||
|
||||
/*
|
||||
|
|
@ -632,6 +633,16 @@ struct signal_struct {
|
|||
unsigned audit_tty;
|
||||
struct tty_audit_buf *tty_audit_buf;
|
||||
#endif
|
||||
#ifdef CONFIG_CGROUPS
|
||||
/*
|
||||
* The threadgroup_fork_lock prevents threads from forking with
|
||||
* CLONE_THREAD while held for writing. Use this for fork-sensitive
|
||||
* threadgroup-wide operations. It's taken for reading in fork.c in
|
||||
* copy_process().
|
||||
* Currently only needed write-side by cgroups.
|
||||
*/
|
||||
struct rw_semaphore threadgroup_fork_lock;
|
||||
#endif
|
||||
|
||||
int oom_adj; /* OOM kill score adjustment (bit shift) */
|
||||
int oom_score_adj; /* OOM kill score adjustment */
|
||||
|
|
@ -2323,6 +2334,31 @@ static inline void unlock_task_sighand(struct task_struct *tsk,
|
|||
spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
|
||||
}
|
||||
|
||||
/* See the declaration of threadgroup_fork_lock in signal_struct. */
|
||||
#ifdef CONFIG_CGROUPS
|
||||
static inline void threadgroup_fork_read_lock(struct task_struct *tsk)
|
||||
{
|
||||
down_read(&tsk->signal->threadgroup_fork_lock);
|
||||
}
|
||||
static inline void threadgroup_fork_read_unlock(struct task_struct *tsk)
|
||||
{
|
||||
up_read(&tsk->signal->threadgroup_fork_lock);
|
||||
}
|
||||
static inline void threadgroup_fork_write_lock(struct task_struct *tsk)
|
||||
{
|
||||
down_write(&tsk->signal->threadgroup_fork_lock);
|
||||
}
|
||||
static inline void threadgroup_fork_write_unlock(struct task_struct *tsk)
|
||||
{
|
||||
up_write(&tsk->signal->threadgroup_fork_lock);
|
||||
}
|
||||
#else
|
||||
static inline void threadgroup_fork_read_lock(struct task_struct *tsk) {}
|
||||
static inline void threadgroup_fork_read_unlock(struct task_struct *tsk) {}
|
||||
static inline void threadgroup_fork_write_lock(struct task_struct *tsk) {}
|
||||
static inline void threadgroup_fork_write_unlock(struct task_struct *tsk) {}
|
||||
#endif
|
||||
|
||||
#ifndef __HAVE_THREAD_FUNCTIONS
|
||||
|
||||
#define task_thread_info(task) ((struct thread_info *)(task)->stack)
|
||||
|
|
|
|||
Loading…
Reference in a new issue