Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752495AbdI0Q2O (ORCPT ); Wed, 27 Sep 2017 12:28:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53076 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752414AbdI0Q2L (ORCPT ); Wed, 27 Sep 2017 12:28:11 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 788D25FD7A Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=oleg@redhat.com Date: Wed, 27 Sep 2017 18:28:08 +0200 From: Oleg Nesterov To: Gargi Sharma Cc: linux-kernel@vger.kernel.org, riel@surriel.com, julia.lawall@lip6.fr, akpm@linux-foundation.org, mingo@kernel.org, pasha.tatashin@oracle.com, ktkhai@virtuozzo.com, Eric Biederman Subject: Re: [PATCH v2 2/2] pid: Remove pidhash Message-ID: <20170927162808.GA5680@redhat.com> References: <20170927154543.GA3788@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170927154543.GA3788@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 27 Sep 2017 16:28:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1548 Lines: 47 If I was not clear... in short, after this patch the very first idr_alloc_cyclic() is already wrong. Because, once again, the new not-fully-initialized pid can be found by find_pid_ns(). perhaps you should chane the previous patch to do idr_alloc_cyclic(ptr = NULL) and use idr_replace() in this patch after the PIDNS_HASH_ADDING check. And I just noticed you didn't cc Eric Biederman , please do next time. On 09/27, Oleg Nesterov wrote: > > On 09/27, Gargi Sharma wrote: > > > > -#define find_next_offset(map, off) \ > > - find_next_zero_bit((map)->page, BITS_PER_PAGE, off) > > - > > this should go into the previous patch, but this is minor... > > > @@ -208,12 +200,10 @@ struct pid *alloc_pid(struct pid_namespace *ns) > > > > upid = pid->numbers + ns->level; > > spin_lock_irq(&pidmap_lock); > > - if (!(ns->nr_hashed & PIDNS_HASH_ADDING)) > > + if (!(ns->pid_allocated & PIDNS_ADDING)) > > goto out_unlock; > > for ( ; upid >= pid->numbers; --upid) { > > - hlist_add_head_rcu(&upid->pid_chain, > > - &pid_hash[pid_hashfn(upid->nr, upid->ns)]); > > - upid->ns->nr_hashed++; > > + upid->ns->pid_allocated++; > > No, this is wrong. > > It is too late to check PIDNS_HASH_ADDING/PIDNS_ADDING and increment pid_allocated, > once we call idr_alloc_cyclic() this pid is already "hashed" in that it can be found > by find_pid_ns() with this patch applied. > > And of course, it is too late to do atomic_set(&pid->count, 1) and initialize > pid->tasks[type] lists by the same reason. > > Oleg.