From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755205AbdCPQT5 (ORCPT ); Thu, 16 Mar 2017 12:19:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35526 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750970AbdCPQTz (ORCPT ); Thu, 16 Mar 2017 12:19:55 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DC56E3DBEF Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=oleg@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DC56E3DBEF Date: Thu, 16 Mar 2017 17:17:57 +0100 From: Oleg Nesterov To: Tejun Heo Cc: Linus Torvalds , Andrew Morton , Peter Zijlstra , Thomas Gleixner , Chris Mason , linux-kernel@vger.kernel.org, kernel-team@fb.com, Li Zefan , Johannes Weiner , cgroups@vger.kernel.org Subject: Re: [PATCH 2/2] kthread, cgroup: close race window where new kthreads can be migrated to non-root cgroups Message-ID: <20170316161756.GA27613@redhat.com> References: <20170315231827.GA13656@htj.duckdns.org> <20170315231920.GB13656@htj.duckdns.org> <20170316150233.GB24478@redhat.com> <20170316160544.GC15810@htj.duckdns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170316160544.GC15810@htj.duckdns.org> User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 16 Mar 2017 16:19:56 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, &kthread->flags); > > > +} > > > > Not sure I understand... > > > > With this patch you can no longer migrate a kernel thread created by > > kernel_thread() ? Note that to_kthread() is NULL unless it was created > > by kthread_create(). > > Yeah, what it does is preventing migration of kthreads until the > kthread owner wakes it up for the first time. The problem is that > kthread_bind() seals up future cgroup migrations from userland but > doesn't move back the kthread to the root cgroup, so the userland has > a window where it can mangle with cgroup membership inbetween and > break things. This is clear, > The NULL test is there because the test may be performed before the > kthread itself sets up its struct kthread. This too. 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 migrated, this won't work after your patch. Oleg.