Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp843097rdh; Thu, 23 Nov 2023 22:06:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IF581vT3uS4VRQ64RlwhTIswcNEu3VX6xKCojYxNVfO+rFuwJtHw6rscOYzgUg28LAWoLhU X-Received: by 2002:aa7:88ce:0:b0:6cb:d24b:878c with SMTP id k14-20020aa788ce000000b006cbd24b878cmr1761290pff.12.1700805960095; Thu, 23 Nov 2023 22:06:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700805960; cv=none; d=google.com; s=arc-20160816; b=zyq5mrVC9rcfEZ+b8OhYIFeujbbB5hGVZyqJXrEgOUC1ylBb3SZ56Dh0LsfUkbx7At 0HoPGgz9aIUuQjAt+m3an8O5xxhGm3Ku46BcdxjnLl4OtYKjWjbgqyvDZ9pQaH/onC2a POdkOX/pnUK69sgEnbkK+cJ0aSI8JjurQV7+agkCwLoHLVNoqs7b0568gwbEkSgYRMol FDRcUwfxKyQUu0NwkNaWjGmZl7gs9Sjxqc67N1g8ZdXQ9YddhR3d8QqzrOUqXca7Z59g 2he36cpgo63cE8nlhIflo/flcVJECGgO8K3fyKReT+09oI55hAPfQ+RDWvyuuJcoaKS5 +VyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dygXiWQj01+v+M8EqnLDmRAM15rjFqh51JbrrIY5KXg=; fh=vDsv/0Rb6aybIi/Xas2DR+uQpFXMLtn4no3J1t38V0s=; b=IyIanXVLJxF50Ou8rRd+s1U61QUWc2Pe4GFiPBwe8XrhksX3/Hl6ybkWLTbBm/caT0 COXQBNJjQPT4yyJV0uWNo6lIguNU6RXQzWtKu+NRvR6NHKwUiSJzDhvHRznH9BoPKb6a Xa5WGSZwkyCmsmwwz/Z19MJT0ang3RaNOXkWBCHbn6xms1CnuiXYxfsqjIKaxv0CXJzo dfieWgepZ2Ssh5XggatmTdMMWy8gREriHSmnR2//zmvqjND4bgRFaJZmq2vknTZJv0g5 w9kIW+4qpO1SE4BS5PUZo9xfzOaZgHRTK0L1eub3W3jaVDmp+ed/PTN92W749g0UEgQw pDnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=GEO3n6mU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id a5-20020a056a000c8500b006bd9c159a98si2977224pfv.186.2023.11.23.22.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 22:06:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=GEO3n6mU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4EB6680A733B; Thu, 23 Nov 2023 22:05:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232503AbjKXGFE (ORCPT + 99 others); Fri, 24 Nov 2023 01:05:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231337AbjKXGET (ORCPT ); Fri, 24 Nov 2023 01:04:19 -0500 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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 23 Nov 2023 22:05:54 -0800 (PST) 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 { -- 2.39.2