From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.146 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795988067; b=4Iu+Pp7fywhhRGXmfEihVT7Z7m/VDOvJcXziK3uI8SnJwAkwqsKxt5/JrPcaBy+JYJfj uaJqtUjtFoWVAa7KYMdWGE3YugCUy6+me3qRwXk0rgo34dbD5IuEsTFM25w0DD7GNasyE tpVG/dQtZahjWBLL2lasLANrzdt/EDsdwB0adVXoiqKyvHlZHqzXqHETLmfU4gHwg1+KE 9Ucf6EABoxoobsW7Pz+cRdWQLCo8lBNYugzKo1tMdTgsAMKc9OagGYjC7K2FDCcEwvgcu w//sD85b/veZ4Lr7DoArnDi/GzsiZiIv6rMRgBiR9Ky7iWfPajLQDmkEIlzg4L/oFcg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795988067; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:Reply-To:MIME-Version:Content-Transfer-Encoding; bh=KNrcdHCfm14DJrbhG1komA79M+E2ZYc6lhc4nAj7Du8=; b=Mm0eZtis4LETG404TLP+nEid19bqu1UikbcLGvjjLarMnoAkaTCzCReoXnEtzhMcaDJE PgU7iLdvyHpn1YbAxqnWqX5bdSgxVMdlFsy10nl181JGLbTRoIaFAUIPvcdP3Vd6Vuh/F JJg7fZKQixxanLvSOCa+bWtPoigRYEm+1C/LRAaezCAms9EXNL7HpZiFYxsM7VV7ESask bQFq6/RjYPRByTLIH37FQWGW35EW01SI4hJlT0NXXjsQ8lxD4F+xfuMcx5DCiDsqWyw01 fVwzg9XkFoFwUHVusqHaGn6SwAbn15qDKV+OSvoDZLwGlq7957KAeuLugw429AGua0w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=ownmail.net; spf=pass smtp.mailfrom=ownmail.net; dkim=pass header.d=ownmail.net header.i=@ownmail.net header.a=rsa-sha256 header.s=fm3 header.b=kSkKwMVP; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=zdfO03tg; arc=none smtp.remote-ip=103.168.172.146 Received: from fout-a3-smtp.messagingengine.com (fout-a3-smtp.messagingengine.com [103.168.172.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37D06606A327 for ; Sun, 29 Nov 2026 21:34:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 37D06606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ownmail.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ownmail.net header.i=@ownmail.net header.a=rsa-sha256 header.s=fm3 header.b=kSkKwMVP; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=zdfO03tg Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 7A857EC0A05 for ; Sun, 29 Nov 2026 16:34:26 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Sun, 29 Nov 2026 16:34:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to; s=fm3; t=1795988066; x=1796074466; bh=KNrcdHCfm14DJrbhG1komA79M+E2ZYc6lhc4nAj7Du8=; b= kSkKwMVPbddojJHKqKVTWm5wf52takjH/t4I/7sXubNuaOP/VA2WXGUQxB/y66wy lUZk4zvqzJc4pETJQtEhp4S/GZLPqE6tja3ALT2iyy9XFzVoLA6dkh7MHIHvdeIw AtQpXxY7rkx5cTig9yQex3EL2YipLc19B0MeepBvKyhJPNg3Mq60VioDQlXTHW4Y zJHdQJkhHsl2vd8fLXV7+tof8MnmCMtnj2XWiQxwx4z+rweQIux3Y2IAoowyJIUK 7BndfIlLv3w9uLONAUf++UoZS2HIgDUQ7M9z0nkZy8gXFugdqGZuZtrr+s+Y8BfJ ocLTTHi0Sh/pc2KmBQc4yg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1795988066; x=1796074466; bh=K NrcdHCfm14DJrbhG1komA79M+E2ZYc6lhc4nAj7Du8=; b=zdfO03tgBrtIY2W1/ f+hylnXNpKGlw2ynl1M+4Dio1rRwOMjXCG4FtauQXSVXtIKlt5GjY2XwZUZOWLqW nMJHVBrbvCMK+ueftF2P0RwO+567XrZXHcXVhrY2rD8Bi+fbWrzcSb80cExqKMkO R8WNBzjhQSVcyqwdhEdX+zmGZFEy1EFnkSmRsylZpRN52LDGc5wWGfeVKGKAUVUI r5aylKaQOjgqPuqKwm90Iu0Qdhn33QaCktR92VSgBaPp7Qp4zWqcTJA52wJz89Q7 lgaS07oLP/ncZ/zXOqWMZTxakdTZACbDNhp31t4Xrbb3FmNQa5wkQ5AcNUj8c1xW pNA0A== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=ownmail.net a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1795988066; d=ownmail.net; mf=PG5laWxiQG93bm1haWwubmV0Pg==; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:MLE4+r2sQvE9nokHiUz5AdC7aDDQ+7JO6Fu0ZvEUYC1F07Q 06dArTpnVoJ+SlpGPQEyLuv+8c13IqNOS911ui+tMAdXsmmlVkf895XMMbAK4f2/ 6Ijcobbm3bX6YNEohWVRIxpTuMoGyMd2DKZMdMaC6d9lXZ/SyUD6vB5RUwIGfTXJ 085byMY+DxH/Y1UvrTmisW6mpP/5y0OJBAI73/CWj95uo1KGNg4+hBvBw4AY02TN x2hI1/4HZrwaFdxJcOaIg0UbzURNbRLqZnHnIFMolzOfLfE5J02mWk1XoiPBK5DO S0son/frcIog89H0efYn4LqfwytZHMf+BydAc1A==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-transfer-encoding,date,feedback-id,from, in-reply-to,message-id,mime-version,references,reply-to,subject, to; Message-Instance: m=1; h=sha256:oZ9f+scYcs4dcauq+w4Q1FA8mszthNXkW9GDOZl/acA=:bFBfI8GnacQux3O2LkePojOx10ZxSgp3Dhp6BtNWGrU=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGhmM94DfFDAMGW5xTa5DrMlhKr/ITi6fZ+vS6QfwNqtAl8XLhO25uQWYKhqXs3uR 2IZmIDwMlTmPhMex4OKip8GD7MB/Y9TjJjkbe3lH/wQ5xmr0TPniuyOaHFsfD47s7oPd8R AP0nYNFljugaz2eqOAkbHsjvFvB9S5MdU7tmBsgaV0Ps7+EL4SSbWRnTKMvPK2NWl+FEnA KCArVxzRIlgBn++dAKHQOFLvWxzi5okhr6U71O1ckANpd5h8yd8x5FymcvSvtgX7zMKsMt MKSw92k+Ls2TIhffLspEPAZ2NtebaxlbWMWITu2zgAJR2Ovt6eSL7VBpKwyG4E2LWdNuXo 35LWNvK6CYnSSZU2AmfUSjU3EZUIGT7BEKAdq82gXxApwmqi7AYVW4pQPUaHYzoHd7B+OO kRQFNhb7zfTjSZobQGJ/ljyxOUkGwRudQpF8sOaSZm4MQSrnigHtMKfP3j/XagtEiqNQTD UrC83q/n7ySFfTMWFFKsUUD3wYEE+vtJ4Eb0mkT4rODRWln2LtEJ9HrVWm+GS0XvO50Pdc itBWcMs8UsuTHFB6nX27uXuJGpYmjqGOv07Q+WX7k/Z3dQqnE/Xu9GM82yOFFEr/d3EBwj 0AtxkwcMnnoyZFoq+QdtbOJrDdjFiuro9bYcEpCcgBAl22G02m5SLEC9UCUg X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Nov 2026 16:34:21 -0500 (EST) From: NeilBrown To: Alexander Viro , Christian Brauner Cc: David Howells , Marc Dionne , Jan Harkes , coda@cs.cmu.edu, Jan Kara , Richard Weinberger , Anton Ivanov , Johannes Berg , Jeff Layton , Amir Goldstein , linux-kernel@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-fsdevel@vger.kernel.org, linux-um@lists.infradead.org, linux-afs@lists.infradead.org Subject: [PATCH v4 7/8] procfs: drop parent lock for d_alloc_parallel() in iterate_shared() Date: Mon, 30 Nov 2026 08:21:43 +1100 Message-ID: <20261129213259.2837044-8-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20261129213259.2837044-1-neilb@ownmail.net> References: <20261129213259.2837044-1-neilb@ownmail.net> Reply-To: NeilBrown X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: NeilBrown When procfs finds a name during iterate_shared() that isn't in the dcache it *must* add it so that it can have a stable inode number to report (inodes are only accessible via the dcache in procfs). It uses d_alloc_parallel(). A planned change to locking will make it unsafe to call d_alloc_parallel() while holding the directory lock. Other filesystems which prime the dcache in iterate_shared() use d_alloc_trylock() which is safe but can fail if it races with ->lookup. As procfs cannot handle failure we need something different. procfs doesn't *need* the parent to be locked. There are no shared data structures accessed that don't have their own locking. So it is safe to drop and re-take the parent lock. So unlock the parent and use lookup_noperm_unlocked() to find child dentry, whether in dcache or via a call to ->lookup. By doing this, procfs effectively delegates locking decisions to lookup_noperm_unlocked(), which will be changed when the planned locking changes happen. A consequence of this is that when a child isn't in the dcache, more work is done. ->lookup has to parse the name and find the details - details which proc_fill_cache or proc_sys_fill_cache already have. This should be a modest cost, and after the locking changes are made we could restore the current behaviour if needed. Other code that drops and retakes the lock in iterate_shared() needs to be careful to check S_DEAD which could be set while the lock is dropped. This is not needed in procfs as the flag is never set. Note that in the case of an error from lookup_noperm_unlocked(), proc_fill_cache() will return the name with inaccurate ino/type details while proc_sys_fill_cache will above the readdir. This is a pre-existing difference of long standing which I have chosen to leave as-is. I doubt it is of any consequence. Signed-off-by: NeilBrown --- fs/proc/base.c | 29 +++++++++-------------------- fs/proc/proc_sysctl.c | 42 ++++++++++++++---------------------------- 2 files changed, 23 insertions(+), 48 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 7685660c3624..14bcfaea0ac9 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2106,31 +2106,20 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx, unsigned type = DT_UNKNOWN; ino_t ino = 1; - child = try_lookup_noperm(&qname, dir); + inode_unlock_shared(dir->d_inode); + + child = lookup_noperm_unlocked(&qname, dir); + if (IS_ERR(child)) goto end_instantiate; - - if (!child) { - child = d_alloc_parallel(dir, &qname); - if (IS_ERR(child)) - goto end_instantiate; - if (d_in_lookup(child)) { - struct dentry *res; - res = instantiate(child, task, ptr); - d_lookup_done(child); - if (unlikely(res)) { - dput(child); - child = res; - if (IS_ERR(child)) - goto end_instantiate; - } - } + if (d_really_is_positive(child)) { + inode = d_inode(child); + ino = inode->i_ino; + type = inode->i_mode >> 12; } - inode = d_inode(child); - ino = inode->i_ino; - type = inode->i_mode >> 12; dput(child); end_instantiate: + inode_lock_shared(dir->d_inode); return dir_emit(ctx, name, len, ino, type); } diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index eeebf813668e..37b96ec31fbe 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -687,38 +687,24 @@ static bool proc_sys_fill_cache(struct file *file, struct inode *inode; struct qstr qname; ino_t ino = 0; + bool ret = false; unsigned type = DT_UNKNOWN; - qname.name = table->procname; - qname.len = strlen(table->procname); - qname.hash = full_name_hash(dir, qname.name, qname.len); - - child = d_lookup(dir, &qname); - if (!child) { - child = d_alloc_parallel(dir, &qname); - if (IS_ERR(child)) - return false; - if (d_in_lookup(child)) { - struct dentry *res; - inode = proc_sys_make_inode(dir->d_sb, head, table); - res = d_splice_alias_ops(inode, child, - &proc_sys_dentry_operations); - d_lookup_done(child); - if (unlikely(res)) { - dput(child); - - if (IS_ERR(res)) - return false; - - child = res; - } - } + qname = QSTR(table->procname); + inode_unlock_shared(dir->d_inode); + child = lookup_noperm_unlocked(&qname, dir); + if (IS_ERR(child)) + goto out; + if (d_really_is_positive(child)) { + inode = d_inode(child); + ino = inode->i_ino; + type = inode->i_mode >> 12; } - inode = d_inode(child); - ino = inode->i_ino; - type = inode->i_mode >> 12; dput(child); - return dir_emit(ctx, qname.name, qname.len, ino, type); + ret = dir_emit(ctx, qname.name, qname.len, ino, type); +out: + inode_lock_shared(dir->d_inode); + return ret; } static bool proc_sys_link_fill_cache(struct file *file, -- 2.50.0.107.gf914562f5916.dirty