From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932289AbdJJOP2 (ORCPT ); Tue, 10 Oct 2017 10:15:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51140 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932117AbdJJOP1 (ORCPT ); Tue, 10 Oct 2017 10:15:27 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9FC207E427 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=oleg@redhat.com Date: Tue, 10 Oct 2017 16:15:23 +0200 From: Oleg Nesterov To: Gargi Sharma Cc: Andrew Morton , linux-kernel@vger.kernel.org, Rik van Riel , Julia Lawall , mingo@kernel.org, pasha.tatashin@oracle.com, ktkhai@virtuozzo.com, "Eric W. Biederman" , Christoph Hellwig Subject: Re: [PATCH v4 1/2] pid: Replace pid bitmap implementation with IDR API Message-ID: <20171010141523.GA16542@redhat.com> References: <1507583624-22146-1-git-send-email-gs051095@gmail.com> <1507583624-22146-2-git-send-email-gs051095@gmail.com> <20171009161737.ea8c62441cc12dfd909ee0b2@linux-foundation.org> <20171010115034.GA28545@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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.27]); Tue, 10 Oct 2017 14:15:27 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/10, Gargi Sharma wrote: > > On Tue, Oct 10, 2017 at 12:50 PM, Oleg Nesterov wrote: > > On 10/09, Andrew Morton wrote: > >> > >> Especially here. I don't think pidmap_lock is held. Is that IDR > >> iteration safe? > > > > Yes, this doesn't look right, we need rcu_read_lock() or pidmap_lock. > > > > And, we also need rcu_read_lock() for another reason, to protect "struct pid". > > Ah, I missed this. From what I understood idr_for_each_entry_continue > should be safe Without rcu? Why? > because calls idr_get_next which in turn calls > radix_tree_iter_find to find the next populated entry in the idr. and then it does rcu_dereference_raw(*slot). Without rcu or pidmap this slot can got away if we race with free_pid(). > If > the pid that you are looking up the task for is deleted, task will get > a NULL from pid_task and no signal to kill will be sent. pid->tasks is protected by tasklist_lock, but the pid itself can go away without rcu lock. So I think you need to take rcu_read_lock() right after tasklist_lock. > > Gargi, I suggested to use idr_for_each_entry_continue(), but now I am wondering > > if we should use idr_for_each() instead. IIUC this would be a bit faster? Not > > that I think this is really important... > > I can run benchmarks with idr_for_each to see how much speed up is > achieved and then we can go with whatever we think is better. How does > that sounds? Up to you ;) I am fine either way. Oleg.