From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0C3CC0218A for ; Sat, 1 Feb 2025 17:42:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83D156B007B; Sat, 1 Feb 2025 12:42:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7ECE36B0082; Sat, 1 Feb 2025 12:42:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B5606B0083; Sat, 1 Feb 2025 12:42:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4CF926B007B for ; Sat, 1 Feb 2025 12:42:42 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9661047AF1 for ; Sat, 1 Feb 2025 17:42:41 +0000 (UTC) X-FDA: 83072095722.14.531923E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 82F4940003 for ; Sat, 1 Feb 2025 17:42:39 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gCjPs72U; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of oleg@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=oleg@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738431759; a=rsa-sha256; cv=none; b=YgzfNJ0FqtUXwQLdkQzJFlntQJFcZu0cfy5WbLmn15WupYnMq8cl4aVcDcyWDMkaH28JcV qnk69X+nZZD9xPHalUKn2jeHFUJ9RM6BSGK7RPrchaLUpep/WbVNkdJIfnLJh8EQrT9OTw ABnB4PvEneq8tU54SPS0cHoDvXBZyTI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gCjPs72U; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of oleg@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=oleg@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738431759; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=U+Cvxdil9FSRRnY1aPniEAAVDp4QhwhxZqsCBBkWUiE=; b=jI3rNX95mSjx+mPXj39qPhVbIyMCn5HCKZNFlagWW0n+mxgoZb3A9q5iXWnFHMMNMoQXOz SaqDDD8F8mpptAMedWvTvylJ15Mci158GuoHvvweMVIrSg4sQlnWLKTdo106ltFDvA2msh 3W5iDxFOZ6pjPYf/0wOGzeUtG4Ykwc4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738431758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=U+Cvxdil9FSRRnY1aPniEAAVDp4QhwhxZqsCBBkWUiE=; b=gCjPs72Uhe3TlKxY6Q3T35Hdgr4Ea/9iqLVw6dWolFWA1NX8Eb8eiWBMfR2pq9HgotpNAU rtdSl3gC4FOS0wHgYXjN64DUbtEOdGPnGaGeug7Xfa6U7YiIOp2yoQwL91Ycl3Atm10Kpg jcI1LwdAPiMueUnKaTA5rSRyTtOYXjQ= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-392-71nFFKxZOyahblyBDUFmsA-1; Sat, 01 Feb 2025 12:42:35 -0500 X-MC-Unique: 71nFFKxZOyahblyBDUFmsA-1 X-Mimecast-MFC-AGG-ID: 71nFFKxZOyahblyBDUFmsA Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DDFC619560A1; Sat, 1 Feb 2025 17:42:33 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.16]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 346FB19560A3; Sat, 1 Feb 2025 17:42:30 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sat, 1 Feb 2025 18:42:07 +0100 (CET) Date: Sat, 1 Feb 2025 18:42:04 +0100 From: Oleg Nesterov To: Mateusz Guzik Cc: ebiederm@xmission.com, brauner@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 6/6] pid: drop irq disablement around pidmap_lock Message-ID: <20250201174203.GA26042@redhat.com> References: <20250201163106.28912-1-mjguzik@gmail.com> <20250201163106.28912-7-mjguzik@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250201163106.28912-7-mjguzik@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-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kVxMcNPK8KBmT9u09qxfIRcYX 1DZv4N91 gkv3WN7e1R7rm4sk2Ky10LoZ+QOJAOxOPLKnHE94paun9eRLuRAMFVp7qR1xH/ZfTpZfNiWTY8T+nAMc/4dBzSYVENISJdPvBQ8b5x5kQ3dw+2c2p9DLRyZbScmo+mddew91BCPMNaRthnBoCOoGE4V393vApli+oeQ0DBkdMiVZcY+kscQAQea4hdCw0YgKKhNYlr5Wg92gIySrVpgRCJvLn9okwAmfKnb7II8NfVlkmLQYd68/OUl4gDQ6A2t6bI/aEIyMP3AXT4728GMsWKA9W18FDaxlo/3nIMhkm8MApON16/cUEadgkKbzzL2qQLk7Oe+8eFwYml5Vc4jaMSt7vWiUMXpnFBd/8oh1xRzFEaou1MXwfE1cxXHwjwtta1ZuE X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: I'll try to review on Monday, but I see nothing obviously wrong after a very quick glance. Although I am not sure 4/6 is really useful, but I won't argue. However, shouldn't this patch also remove the comment which explains the possible lock inversion? Above put_pid(), /* * Note: disable interrupts while the pidmap_lock is held as an * interrupt might come in and do read_lock(&tasklist_lock). * * If we don't disable interrupts there is a nasty deadlock between * detach_pid()->free_pid() and another cpu that does * spin_lock(&pidmap_lock) followed by an interrupt routine that does * read_lock(&tasklist_lock); * * After we clean up the tasklist_lock and know there are no * irq handlers that take it we can leave the interrupts enabled. * For now it is easier to be safe than to prove it can't happen. */ Oleg. On 02/01, Mateusz Guzik wrote: > > It no longer serves any purpose now that the tasklist_lock -> > pidmap_lock ordering got eliminated. > > Signed-off-by: Mateusz Guzik > --- > kernel/pid.c | 23 +++++++++++------------ > 1 file changed, 11 insertions(+), 12 deletions(-) > > diff --git a/kernel/pid.c b/kernel/pid.c > index 73625f28c166..900193de4232 100644 > --- a/kernel/pid.c > +++ b/kernel/pid.c > @@ -115,11 +115,10 @@ static void delayed_put_pid(struct rcu_head *rhp) > void free_pid(struct pid *pid) > { > int i; > - unsigned long flags; > > lockdep_assert_not_held(&tasklist_lock); > > - spin_lock_irqsave(&pidmap_lock, flags); > + spin_lock(&pidmap_lock); > for (i = 0; i <= pid->level; i++) { > struct upid *upid = pid->numbers + i; > struct pid_namespace *ns = upid->ns; > @@ -142,7 +141,7 @@ void free_pid(struct pid *pid) > idr_remove(&ns->idr, upid->nr); > } > pidfs_remove_pid(pid); > - spin_unlock_irqrestore(&pidmap_lock, flags); > + spin_unlock(&pidmap_lock); > > call_rcu(&pid->rcu, delayed_put_pid); > } > @@ -210,7 +209,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, > } > > idr_preload(GFP_KERNEL); > - spin_lock_irq(&pidmap_lock); > + spin_lock(&pidmap_lock); > > if (tid) { > nr = idr_alloc(&tmp->idr, NULL, tid, > @@ -237,7 +236,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, > nr = idr_alloc_cyclic(&tmp->idr, NULL, pid_min, > pid_max, GFP_ATOMIC); > } > - spin_unlock_irq(&pidmap_lock); > + spin_unlock(&pidmap_lock); > idr_preload_end(); > > if (nr < 0) { > @@ -271,7 +270,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, > > upid = pid->numbers + ns->level; > idr_preload(GFP_KERNEL); > - spin_lock_irq(&pidmap_lock); > + spin_lock(&pidmap_lock); > if (!(ns->pid_allocated & PIDNS_ADDING)) > goto out_unlock; > pidfs_add_pid(pid); > @@ -280,18 +279,18 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, > idr_replace(&upid->ns->idr, pid, upid->nr); > upid->ns->pid_allocated++; > } > - spin_unlock_irq(&pidmap_lock); > + spin_unlock(&pidmap_lock); > idr_preload_end(); > > return pid; > > out_unlock: > - spin_unlock_irq(&pidmap_lock); > + spin_unlock(&pidmap_lock); > idr_preload_end(); > put_pid_ns(ns); > > out_free: > - spin_lock_irq(&pidmap_lock); > + spin_lock(&pidmap_lock); > while (++i <= ns->level) { > upid = pid->numbers + i; > idr_remove(&upid->ns->idr, upid->nr); > @@ -301,7 +300,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, > if (ns->pid_allocated == PIDNS_ADDING) > idr_set_cursor(&ns->idr, 0); > > - spin_unlock_irq(&pidmap_lock); > + spin_unlock(&pidmap_lock); > > kmem_cache_free(ns->pid_cachep, pid); > return ERR_PTR(retval); > @@ -309,9 +308,9 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, > > void disable_pid_allocation(struct pid_namespace *ns) > { > - spin_lock_irq(&pidmap_lock); > + spin_lock(&pidmap_lock); > ns->pid_allocated &= ~PIDNS_ADDING; > - spin_unlock_irq(&pidmap_lock); > + spin_unlock(&pidmap_lock); > } > > struct pid *find_pid_ns(int nr, struct pid_namespace *ns) > -- > 2.43.0 >