From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.150 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796256546; b=ctC44z7LcNQfaw2NS5+49fooPeza+sucxluI29usb+fdpN+n+1oSFE1HC3l0T7NIpLHm KCl9tPS7jgUUtXLPI+StGmB80SjhNxhWP5XHnLG+lksglewyIzUvScJNHCXUP+5Rcwwv9 ZZlbldsN/i9M5ETSTJ7yrzqouRNIK3hv6IiOtyuGizmOr8Iyd7/CLmslaLYCuGSpx4DRQ PabGnwxd1fgkwhHexmLjfj7sgKvLE/JcHOQYajHHgNd4RWJKWTQHmOyTyAPmdYcQsr4tt shTP4Sgmx8Xrj1MhgGSYXU+eUbhfBtcFodXvTh9Fnz32u0piz+umt99iVEpr7s0FpnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796256546; 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:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:Reply-To:MIME-Version:Content-Transfer-Encoding; bh=mFMV39VRwkiLdGkh8Z9M/GDjIKfRnh7Qv4KyXLBfZHU=; b=aWg0XO3vlaahf9JsVnUdFWI6BY5UTvcUdA8SL8MocYWhIH9/u+CGuzmGlScOukcE9Cx2 UUPTgxv6xCeQQJEsnL1njK4/rkwWPO2z87QGmzcqsMk7c6P0XKb2GPy14SfLLGBDytIuf bFH/nO7pn3+UIm3FugBbJ3Nt9/c9zQud780p/RnqvogoG4/FJ9PBu7x+/G7dTTHJ3Ssg/ hi/8F0kiNc5vXdRu8C2BSc60Dv7XtP9EJljZKWZ57RqnPRyJHcV2og1GfQAq0eY6v81/j DegIS+sQ85091J7IUDiuBWwNOuGYIFmYn9U/RzEJztjA0Bi7Tz9eFVpVYynBANAjQxg== 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=Xq3ANA0m; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=s8UrLfi1; arc=none smtp.remote-ip=202.12.124.150 Received: from fout-b7-smtp.messagingengine.com (fout-b7-smtp.messagingengine.com [202.12.124.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AC0D606A32C for ; Thu, 3 Dec 2026 00:09:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0AC0D606A32C 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=Xq3ANA0m; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=s8UrLfi1 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.stl.internal (Postfix) with ESMTP id 4E8A91D00210 for ; Wed, 2 Dec 2026 19:09:05 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Wed, 02 Dec 2026 19:09:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= 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=1796256545; x=1796342945; bh=mFMV39VRwkiLdGkh8Z9M/GDjIKfRnh7Qv4KyXLBfZHU=; b= Xq3ANA0mZ+vunA7TnVbH9N/YO53H9ZGbdov7+sUplOkDyhq28AcrhJAL5X152EkN VtRE/aFmjy0MXKo5Xxifriu8CCj6kmbyYpmXjQLWJgu8DmSvwkwofLxS2r0vVYXg od8J+g4ILY6jX8QhBhbJZHnzidQ9GbnlYEScHoYwJMCL3r2cxbel15IU6ce2ptr0 U/nGea+vGuIlywGDs76x3eWnAZ/plZlwSvtgSm5au18UCRi/VTFnn3j5uw1zVb7J jqtVvRreHiALDND4l0Tp+QanTiIsLAByJescmV1e+Q73A2CYW9qXz4wtjeMzYVqG Y9eqSkoh+LM5/6R/g6CcxA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1796256545; x=1796342945; bh=m FMV39VRwkiLdGkh8Z9M/GDjIKfRnh7Qv4KyXLBfZHU=; b=s8UrLfi1lx1oPoEyT bkHHjM21BPkg8lwY6WAJ6S/THVj5wXuoq2VJ2/13W6ohQajhr2Xv0FlLk4f9xH7i sXj+WisQkHtu9eYNr65lSP1zIaZ3VhN1rDOCzMh5LFED9E9fra16MqnEn/8Oh73t X3bvFFn1EYV8OpxuE/XCB5JsAWAFpjvAEG2CwF17uQmB4+b0Q7GfzHdzKHb2tbVQ OYtVyj+y2W5A9iOoteAhjvZaOJSgLznY6AB+m39CtFfpTSDU2PMm/sOiE57CZ9Jl EhCcs9S8jqOcF4liNaUo8ZNWiffyyYfriBh+TYEEFX+3FVeGKgAyLWmw3UciMLii Bp1eA== 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=1796256545; d=ownmail.net; mf=PG5laWxiQG93bm1haWwubmV0Pg==; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:y9/5KQ5D65y7udlJLiRqEsGyLhi2SOFeD8Jm7g+7dbf/pJd WPEAbrAdHtxeaYDa4M77WaC95Axd5cyJA0uYHPemK/4aHh9QMD8xsfSBLYojIbhW Y5Uyi9KX0jbe/HxWr4LkrX3Grd2YRxmcm7e/boM+OoNOXQ44Jm0j6ahG1LbkjDup 0IDp1brkV0cjnVENOH7b6iPhnpz4F3rcJbcLsaUSwHA3omrVqWYHHMcHahvpCUed M5W38RhFw1OPz9sBSc1mdgD+QBxccHgORVBNZP2TD2S3L5ZjZ0IZavE5OL1OTL5M uu8XSkL1GzE6Trs3PHNOWCPPFGFWmoBpB+ceVeg==; 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=11; hn=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:V5AJdIRufbLmVC9NL+rZ7SjcSzgCJrs1fDdAE2Q4C/o=:165bQMEJQuFHGDFGu1QlP81KOcZq/BumSIi1x2TSMXg=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEk7W2urxng3XGtsqgBSAihcmhsvNGvgXw20nbGEMVLbua2VpqSQVrQQ/bg3x9oHI 2U248MaPJhG1HzmtvnLR7bUOngaQ85sTLwQMHyZTX2+3WJ49HqLEx3VpN0ufoRwVheXDP9 1D+etNYMr6+5PlweDNJSWG483gtmONAADgd5K0nT21v2vfFhL8m4RTj+eg7dQ3ozUH7HQg MgdWvFgOGeSEuZmAnXMq9gn/Vv+Xdk6tiYB/+BCyjeg3w53kPBpMn3UVSHc5luDO87vMyU TngMqapyON7sXN+NdQktZie+TxW/kvzHrC5wvPlLBxT34IdTsnDVjZEExUIc0lXeC+WClG K+RkQD2a8HcEYVChxEu6U6oLzYBG3+6dgjvcy19QcwDsG+D50oSytJtvsA7NqrBf61rhxh WRWtPe86WrFAn5tvtYrEeZqCId4hOoE/3NHDfrkTFTxIXeT3sb4J2crFjNwm8Gt9EKCuP4 y5Gz861oHXwH091qosgsb44XxEOSlgwVrWQuGBPXAf1uJ7chcRdzGfqZgoRo8PwtsIRA1c xeCXx7EWGEoQYY0JsiBYpK/4jrCa0lcCC4LOoCbnDWZBpuna/f0njQmWV3EMr9k+f9xbk4 BJUa9EVF7F4hxBSQLeRO3KuL5jQEb41m4po31diFMzxBm1wCLRFkG4bGe8+A X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 2 Dec 2026 19:09:02 -0500 (EST) From: NeilBrown To: linux-kernel@vger.kernel.org Subject: [PATCH 1/9] VFS: introduce d_is_negative_acquire() Date: Thu, 3 Dec 2026 11:07:56 +1100 Message-ID: <20261203000848.2986775-2-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20261203000848.2986775-1-neilb@ownmail.net> References: <20261203000848.2986775-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 As discussed in Commit: 2fa6b1e01a9b ("fs/namei.c: fix missing barriers when checking positivity") d_is_negative() is only safe when the dentry is locked against change, either by d_lock or parent's i_rwsem. When not locked an acquire barrier is needed. A recent change introduced a new use of d_is_negative() is a non-locked situation. To make it easier to get this sort of thing right, introduce d_is_negative_acquire(), document when it should be used and when d_is_negative() should be avoided, and use d_is_negative_acquire() where appropriate. Fixes: 98b6cf102b35 ("namei: test for a negative dentry the way traverse_mounts() does") Signed-off-by: NeilBrown --- fs/namei.c | 8 ++++---- fs/overlayfs/namei.c | 2 +- include/linux/dcache.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c79eecffe4ac..5bf77dca0c53 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3329,7 +3329,7 @@ struct dentry *lookup_one_positive_killable(const struct mnt_idmap *idmap, ret = lookup_dcache(name, base, 0); if (!ret) ret = lookup_slow_killable(name, base, 0); - if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { + if (!IS_ERR(ret) && d_is_negative_acquire(ret)) { dput(ret); ret = ERR_PTR(-ENOENT); } @@ -3364,7 +3364,7 @@ struct dentry *lookup_one_positive_unlocked(const struct mnt_idmap *idmap, { struct dentry *ret = lookup_one_unlocked(idmap, name, base); - if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { + if (!IS_ERR(ret) && d_is_negative_acquire(ret)) { dput(ret); ret = ERR_PTR(-ENOENT); } @@ -3424,7 +3424,7 @@ struct dentry *lookup_noperm_positive_unlocked(struct qstr *name, struct dentry *ret; ret = lookup_noperm_unlocked(name, base); - if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { ++ if (!IS_ERR(ret) && d_is_negative_acquire(ret)) { dput(ret); ret = ERR_PTR(-ENOENT); } @@ -4830,7 +4830,7 @@ static struct dentry *lookup_fast_for_open(struct nameidata *nd, int open_flag) return dentry; if (open_flag & O_CREAT) { - if (d_is_negative(dentry)) { + if (d_is_negative_acquire(dentry)) { if (!(nd->flags & LOOKUP_RCU)) dput(dentry); dentry = NULL; diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index ddf60254888a..8fa8c168dd50 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -216,7 +216,7 @@ static struct dentry *ovl_lookup_positive_unlocked(struct ovl_lookup_data *d, struct dentry *ret = lookup_one_unlocked(mnt_idmap(d->layer->mnt), &QSTR_LEN(name, len), base); - if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { + if (!IS_ERR(ret) && d_is_negative_acquire(ret)) { if (drop_negative && ret->d_lockref.count == 1) { spin_lock(&ret->d_lock); /* Recheck condition under lock */ diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 1d03b3c6e081..7c03a862f675 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -498,6 +498,16 @@ static inline bool d_is_file(const struct dentry *dentry) return d_is_reg(dentry) || d_is_special(dentry); } +/** + * d_is_negative - test if a dentry is negative + * @dentry: the dentry to test + * + * This should only be used if the dentry is locked against + * change, either by ->d_lock or by parent's ->i_rwsem. + * Outside this context use d_really_is_negative() if the sole + * purpose is to determine if it is safe to dereference the inode, + * or use d_is_negative_acquire() if the context is more general. + */ static inline bool d_is_negative(const struct dentry *dentry) { // TODO: check d_is_whiteout(dentry) also. @@ -509,6 +519,30 @@ static inline bool d_flags_negative(unsigned flags) return (flags & DCACHE_ENTRY_TYPE) == DCACHE_MISS_TYPE; } +/** + * d_is_negative_acquire - test if a dentry is negative, with barrier + * @dentry: the dentry to test + * + * This should be used if the dentry is NOT locked against + * change, either by ->d_lock or by parent's ->i_rwsem. + * In a locked context it is preferred to use d_is_negative(). + */ +static inline bool d_is_negative_acquire(const struct dentry *dentry) +{ + /* acquire matches release in __d_set_inode_and_type() */ + return d_flags_negative(smp_load_acquire(&dentry->d_flags)); +} + +/** + * d_is_positive - test if a dentry is positive + * @dentry: the dentry to test + * + * This should only be used if the dentry is locked against + * change, either by ->d_lock or by parent's ->i_rwsem. + * Outside this context use d_really_is_positive() if the sole + * purpose is to determine if it is safe to dereference the inode, + * or use !d_is_negative_acquire() if the context is more general. + */ static inline bool d_is_positive(const struct dentry *dentry) { return !d_is_negative(dentry); base-commit: 84fb6f8a1ba91eee3ffe6aa519686fce851a0e42 -- 2.50.0.107.gf914562f5916.dirty