From patchwork Thu Nov 9 06:20:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13450656 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DE31E574 for ; Thu, 9 Nov 2023 06:21:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="Xr6xK9r5" 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 E4E7D26BC for ; Wed, 8 Nov 2023 22:20:59 -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=fqgEuHsebdDpFMPtEzF/nzVbQVktYGU1hkEJxaEkZjE=; b=Xr6xK9r5kYOj73ojc91FN+5yZG mirO/VPTyTgtXSwxxlDhaOKi8ekNzq3J9akpgNCa0TBF3V3v+TTXWHUzMRsrsOxZXjJQImoML8Ut6 VByJJ6e2y6/PkUJg3DjKUjoRFrarkV+BrjLmySK3b2+EmWQsRST9Ifx1sAg09uXIttzkK8MBBNc+c 6X+tdvq38iEedN0B3OO+cAe07z+nakrGw7jwv/KEyIzYUqwcztLTkJlm5p0Pa+L5H5u7yvV/52GBD GhhX2cou0tEeHnRZ0TBZZIaQASZyIxL1pzA2OtLhrbufTEJ6SD975JGsu6p0pPRwy6s0NQwncSCF4 5gMkOtqg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r0yPS-00DLk8-0h; Thu, 09 Nov 2023 06:20:58 +0000 From: Al Viro To: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, Christian Brauner Subject: [PATCH 13/22] __dentry_kill(): get consistent rules for victim's refcount Date: Thu, 9 Nov 2023 06:20:47 +0000 Message-Id: <20231109062056.3181775-13-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231109062056.3181775-1-viro@zeniv.linux.org.uk> References: <20231109061932.GA3181489@ZenIV> <20231109062056.3181775-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(). Signed-off-by: Al Viro Reviewed-by: Christian Brauner --- fs/dcache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/dcache.c b/fs/dcache.c index 1f61a5d03d5b..d9466cab4884 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 {