From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751800AbdJBPVj (ORCPT ); Mon, 2 Oct 2017 11:21:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48648 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751268AbdJBPVi (ORCPT ); Mon, 2 Oct 2017 11:21:38 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C9249C0587E9 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=oleg@redhat.com Date: Mon, 2 Oct 2017 17:21:35 +0200 From: Oleg Nesterov To: Rik van Riel Cc: Gargi Sharma , linux-kernel@vger.kernel.org, julia.lawall@lip6.fr, akpm@linux-foundation.org, mingo@kernel.org, pasha.tatashin@oracle.com, ktkhai@virtuozzo.com Subject: Re: [PATCH v2 2/2] pid: Remove pidhash Message-ID: <20171002152135.GB9481@redhat.com> References: <20170927154543.GA3788@redhat.com> <1506951313.21121.119.camel@surriel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1506951313.21121.119.camel@surriel.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.32]); Mon, 02 Oct 2017 15:21:38 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Rik, On 10/02, Rik van Riel wrote: > > Gargi and I are looking at that code, and trying to figure out > exactly what needs to be done to make all of this correct. see another email I sent to Gargi a minute ago, > 2) With pid_ns_prepare_proc out of the way, we can put all the code > from below where the call to pid_ns_prepare_proc is now (except > error handing) into the main loop of pid allocation, so we can > do all that stuff under the pidmap_lock: > > for (i = ns->level; i >= 0; i--) { > ... > idr_alloc_cyclic(...) > get_pid_ns(ns); > atomic_set(&pid->count, 1); > for (...) > INIT_HLIST_HEAD(...) > ns->nr_allocated++; > ... > } I do not see how this can fix the problem with not-fully-initialized pid returned by find_pid_ns(). As for PIDNS_ADDING/PIDNS_HASH_ADDING, _perhaps_ we can cleanup this logic a bit and do the check earlier, but imo this needs another/separate change. I'd suggest to keep the current logic and the order of initialization and just do for (i = ns->level; i >= 0; i--) { ... // do not expose the new pid to find_pid_ns() until it // is fully initialized nr = idr_alloc_cyclic(&tmp->idr, /*pid*/ NULL, ...); ... } ... spin_lock_irq(&pidmap_lock); if (!(ns->nr_hashed & PIDNS_HASH_ADDING)) goto out_unlock; for ( ; upid >= pid->numbers; --upid) { - hlist_add_head_rcu(&upid->pid_chain, - &pid_hash[pid_hashfn(upid->nr, upid->ns)]); + // finally make it visible to find_pid_ns() + idr_replace(upid->ns-idr, pid, upid->nr); upid->ns->nr_hashed++; } spin_unlock_irq(&pidmap_lock); Or I missed something? Oleg.