From patchwork Fri Nov 24 06:04:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13466998 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="GEO3n6mU" Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A37001BE; Thu, 23 Nov 2023 22:04:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=dygXiWQj01+v+M8EqnLDmRAM15rjFqh51JbrrIY5KXg=; b=GEO3n6mUIzHm/NcIO+KXB6pvDF YjpRn42VkFVF2oPiXcmD95jtOpAnBkD/76OIfMA+JcOc3JTiVQfnd9AE819o1KMxoiaGq+m/jrIEz xl+LohwoqM6vHCxrJL5qAyZQTGntOwiZtnhU2BcUpdBB01BvckPlSu2v0Hc5kwk3i4Y9uurjqY+Nn YEc+6fjdoil80r2X5hKMDq4IuSKhh9VQSIaPjjv7fESvwQUS0nknbz4rH9SB3AgmZPz/KWKFNpoCO QT/F+jl2Olw/poIVBarWzLKbmKtpMnAG23aaiGedmvjJ/ciepTyUFywSkyGYjIGLJ4bg5c0WAiRAR BGQRivFA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r6PIe-002PuT-0U; Fri, 24 Nov 2023 06:04:24 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Christian Brauner , linux-kernel@vger.kernel.org Subject: [PATCH v3 11/21] __dentry_kill(): get consistent rules for victim's refcount Date: Fri, 24 Nov 2023 06:04:12 +0000 Message-Id: <20231124060422.576198-11-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231124060422.576198-1-viro@zeniv.linux.org.uk> References: <20231124060200.GR38156@ZenIV> <20231124060422.576198-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Sender: Al Viro Currently we call it with refcount equal to 1 when called from dentry_kill(); all other callers have it equal to 0. Make it always be called with zero refcount; on this step we just decrement it before the calls in dentry_kill(). That is safe, since all places that care about the value of refcount either do that under ->d_lock or hold a reference to dentry in question. Either is sufficient to prevent observing a dentry immediately prior to __dentry_kill() getting called from dentry_kill(). Reviewed-by: Christian Brauner Signed-off-by: Al Viro --- fs/dcache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/dcache.c b/fs/dcache.c index 2e74f3f2ce2e..b527db8e5901 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -729,6 +729,7 @@ static struct dentry *dentry_kill(struct dentry *dentry) goto slow_positive; } } + dentry->d_lockref.count--; __dentry_kill(dentry); return parent; @@ -741,6 +742,7 @@ static struct dentry *dentry_kill(struct dentry *dentry) if (unlikely(dentry->d_lockref.count != 1)) { dentry->d_lockref.count--; } else if (likely(!retain_dentry(dentry))) { + dentry->d_lockref.count--; __dentry_kill(dentry); return parent; } else {