Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Tejun Heo
Hello, On Thu, Mar 16, 2017 at 05:31:59PM +0100, Oleg Nesterov wrote: > Or we can add another "unsigned no_cgroups:1" bit into task_struct, > not sure. To synchronize around initialization, a PF flag would be easier as we can use wait_on_bit(). > Anyway, I do not understand the

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Tejun Heo
Hello, On Thu, Mar 16, 2017 at 05:31:59PM +0100, Oleg Nesterov wrote: > Or we can add another "unsigned no_cgroups:1" bit into task_struct, > not sure. To synchronize around initialization, a PF flag would be easier as we can use wait_on_bit(). > Anyway, I do not understand the

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Tejun Heo
Hello, On Thu, Mar 16, 2017 at 05:17:57PM +0100, Oleg Nesterov wrote: > But this also means that __cgroup_procs_write() will always fail if > this task is a kernel thread which was not created by kthread_create(). > > Currently you can use kernel_thread() (although you shouldn't) and it > can be

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Tejun Heo
Hello, On Thu, Mar 16, 2017 at 05:17:57PM +0100, Oleg Nesterov wrote: > But this also means that __cgroup_procs_write() will always fail if > this task is a kernel thread which was not created by kthread_create(). > > Currently you can use kernel_thread() (although you shouldn't) and it > can be

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Oleg Nesterov
On 03/16, Tejun Heo wrote: > > > --- x/kernel/kthread.c > > +++ x/kernel/kthread.c > > @@ -226,6 +226,7 @@ > > ret = -EINTR; > > if (!test_bit(KTHREAD_SHOULD_STOP, >flags)) { > > __kthread_parkme(self); > > + current->flags &= ~PF_IDONTLIKECGROUPS; > > ret

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Oleg Nesterov
On 03/16, Tejun Heo wrote: > > > --- x/kernel/kthread.c > > +++ x/kernel/kthread.c > > @@ -226,6 +226,7 @@ > > ret = -EINTR; > > if (!test_bit(KTHREAD_SHOULD_STOP, >flags)) { > > __kthread_parkme(self); > > + current->flags &= ~PF_IDONTLIKECGROUPS; > > ret

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Oleg Nesterov
On 03/16, Tejun Heo wrote: > > Hello, > > On Thu, Mar 16, 2017 at 04:02:34PM +0100, Oleg Nesterov wrote: > > > +bool kthread_initialized(struct task_struct *k) > > > +{ > > > + struct kthread *kthread = to_kthread(k); > > > + > > > + return kthread && test_bit(KTHREAD_INITIALIZED, >flags); > > >

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Oleg Nesterov
On 03/16, Tejun Heo wrote: > > Hello, > > On Thu, Mar 16, 2017 at 04:02:34PM +0100, Oleg Nesterov wrote: > > > +bool kthread_initialized(struct task_struct *k) > > > +{ > > > + struct kthread *kthread = to_kthread(k); > > > + > > > + return kthread && test_bit(KTHREAD_INITIALIZED, >flags); > > >

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Tejun Heo
Hello, On Thu, Mar 16, 2017 at 04:39:26PM +0100, Oleg Nesterov wrote: > Either way, I am wondering if we can do something really trivial like > the patch below. This way we can also remove the "tsk == kthreadd_task" > check, and we do not need the barriers. > > Oleg. > > --- x/kernel/kthread.c

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Tejun Heo
Hello, On Thu, Mar 16, 2017 at 04:39:26PM +0100, Oleg Nesterov wrote: > Either way, I am wondering if we can do something really trivial like > the patch below. This way we can also remove the "tsk == kthreadd_task" > check, and we do not need the barriers. > > Oleg. > > --- x/kernel/kthread.c

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Tejun Heo
Hello, On Thu, Mar 16, 2017 at 04:02:34PM +0100, Oleg Nesterov wrote: > > +bool kthread_initialized(struct task_struct *k) > > +{ > > + struct kthread *kthread = to_kthread(k); > > + > > + return kthread && test_bit(KTHREAD_INITIALIZED, >flags); > > +} > > Not sure I understand... > > With

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Tejun Heo
Hello, On Thu, Mar 16, 2017 at 04:02:34PM +0100, Oleg Nesterov wrote: > > +bool kthread_initialized(struct task_struct *k) > > +{ > > + struct kthread *kthread = to_kthread(k); > > + > > + return kthread && test_bit(KTHREAD_INITIALIZED, >flags); > > +} > > Not sure I understand... > > With

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Oleg Nesterov
On 03/16, Oleg Nesterov wrote: > > On 03/15, Tejun Heo wrote: > > > > --- a/kernel/cgroup/cgroup.c > > +++ b/kernel/cgroup/cgroup.c > > @@ -2425,11 +2425,13 @@ ssize_t __cgroup_procs_write(struct kern > > tsk = tsk->group_leader; > > > > /* > > -* Workqueue threads may acquire

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Oleg Nesterov
On 03/16, Oleg Nesterov wrote: > > On 03/15, Tejun Heo wrote: > > > > --- a/kernel/cgroup/cgroup.c > > +++ b/kernel/cgroup/cgroup.c > > @@ -2425,11 +2425,13 @@ ssize_t __cgroup_procs_write(struct kern > > tsk = tsk->group_leader; > > > > /* > > -* Workqueue threads may acquire

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Oleg Nesterov
On 03/15, Tejun Heo wrote: > > --- a/kernel/cgroup/cgroup.c > +++ b/kernel/cgroup/cgroup.c > @@ -2425,11 +2425,13 @@ ssize_t __cgroup_procs_write(struct kern > tsk = tsk->group_leader; > > /* > - * Workqueue threads may acquire PF_NO_SETAFFINITY and become > - *

Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-16 Thread Oleg Nesterov
On 03/15, Tejun Heo wrote: > > --- a/kernel/cgroup/cgroup.c > +++ b/kernel/cgroup/cgroup.c > @@ -2425,11 +2425,13 @@ ssize_t __cgroup_procs_write(struct kern > tsk = tsk->group_leader; > > /* > - * Workqueue threads may acquire PF_NO_SETAFFINITY and become > - *

[PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-15 Thread Tejun Heo
Creation of a kthread goes through a couple interlocked stages between the kthread itself and its creator. Once the new kthread starts running, it initializes itself and wakes up the creator. The creator then can further configure the kthread and then let it start doing its job by waking it up.

[PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups

2017-03-15 Thread Tejun Heo
Creation of a kthread goes through a couple interlocked stages between the kthread itself and its creator. Once the new kthread starts running, it initializes itself and wakes up the creator. The creator then can further configure the kthread and then let it start doing its job by waking it up.