Message ID | 20231124060422.576198-2-viro@zeniv.linux.org.uk |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp930563vqx; Thu, 23 Nov 2023 22:04:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnKXrRb3C444awvIYR5Fsb5lgSgtZ1bAw17HRnV/2kf2gytac+LWSHwLmlHRShtbJQV1TM X-Received: by 2002:a05:6a00:2d28:b0:6cb:daec:8b75 with SMTP id fa40-20020a056a002d2800b006cbdaec8b75mr1758088pfb.22.1700805894622; Thu, 23 Nov 2023 22:04:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700805894; cv=none; d=google.com; s=arc-20160816; b=ta2tg3zvzr/baOCR9Rt11SGgquhufKbo5wLyy6EYMHaez+g6X5Amx8B8FfGKsDKBka oXc7GVNB8fc0/FHeTu0KuzKWAMtuTphPIUklLnfUHxPApIDKGlJNc7VzEv6FB+ekl0GL OzkINCAYa+D3F/CRFfVXo0xe4qY17qnZppqHVLcdVbfhP1cLQJcurx/BocgQzTqnMy+q 7XapWMq4HJ1aYVm9TfBGrEqEoipdEZMhnypazVILvQUd8X53vbZIgQPizRNiE2NRHGDn R7IRgdalmo60MyjaxO+1zYOPB9IZOrNCeJ/ZI7x9T+nm3R7EEWlYHwB0AinNU/R0lKJ2 AfVw== 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=t2zwzPnF/uf/2oUVGi0n4GR0yi2cLzOWPO2ZTLid9cY=; fh=vDsv/0Rb6aybIi/Xas2DR+uQpFXMLtn4no3J1t38V0s=; b=vlvF37MV1EYl59nNs5UsxMxmozzswCZOxonB35MnCRHTPfhkUZ3dCk3kKteI2Oy5yE xm3qfbCQg8NWW5GqAVZk8VGv5pL8mUNblLliO/sqIpp+MNkRlCIdBvsP60iMBfKnvRzj LbeReh7EX4eM6rQCFOsXY1uHeG21mkQUM65EeShsdKfwLt5ZebTUewGzh53P1s+q4mRl EEc4+bGn8ShwZnHOk5cin8ZEUf7w0A6NkJ7A506gKVV45nHqTxqHc3RoPlrX6oOto2nN vHqC/AMOTK48NC/niF0uuQCBjFMKJmsxyE6Xv64yDbG+bgyI1DfvELo2Wc4vOWYrHADp mJcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="bzl/4PNt"; 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id b21-20020a056a000cd500b006cbb1347e6dsi2908615pfv.57.2023.11.23.22.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 22:04:54 -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="bzl/4PNt"; 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 084F880A7325; Thu, 23 Nov 2023 22:04:48 -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 S232071AbjKXGEf (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Fri, 24 Nov 2023 01:04:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjKXGER (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 24 Nov 2023 01:04:17 -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 03554D71; Thu, 23 Nov 2023 22:04:24 -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=t2zwzPnF/uf/2oUVGi0n4GR0yi2cLzOWPO2ZTLid9cY=; b=bzl/4PNtx7A7UmHIJuWGbYesMX 3YBns84+Z3wUeS19etV4FUGGskdaoSPZZ35wqX46z7gSRPDYGO09ETLKALzHsMUpqgLREz9q0zQAe 08WzGcqFC7Bi49RK/90zKSBklXfKYhGySNc+hKFExGVBZsrUs7s7izI6Vx+kZsSWNygX4FXQjNjNV vZZRweGyBQIBWerpNK4ZPB/B9VGGWObgYRhBcuhAax6GJ0tWuYJl+0TEWJ6uCI6d8b4JKlHvG7Czz +oj0fsYCrvfQ/CbVELuI3K5rNQoGe8TU4fdy36JTMIo7YLRuP7p//WL91yRdqbr+nP0QBvbH5ClMg Au1GWXRw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r6PIc-002Ptf-25; Fri, 24 Nov 2023 06:04:22 +0000 From: Al Viro <viro@zeniv.linux.org.uk> To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds <torvalds@linux-foundation.org>, Christian Brauner <brauner@kernel.org>, linux-kernel@vger.kernel.org Subject: [PATCH v3 02/21] coda_flag_children(): cope with dentries turning negative Date: Fri, 24 Nov 2023 06:04:03 +0000 Message-Id: <20231124060422.576198-2-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 <viro@ftp.linux.org.uk> 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: <linux-kernel.vger.kernel.org> 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:04:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783424241562776768 X-GMAIL-MSGID: 1783424241562776768 |
Series |
[v3,01/21] switch nfsd_client_rmdir() to use of simple_recursive_removal()
|
|
Commit Message
Al Viro
Nov. 24, 2023, 6:04 a.m. UTC
->d_lock on parent does not stabilize ->d_inode of child. We don't do much with that inode in there, but we need at least to avoid struct inode getting freed under us... Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> --- fs/coda/cache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Comments
On Thu, 23 Nov 2023 at 22:04, Al Viro <viro@zeniv.linux.org.uk> wrote: > > ->d_lock on parent does not stabilize ->d_inode of child. > We don't do much with that inode in there, but we need > at least to avoid struct inode getting freed under us... Gaah. We've gone back and forth on this. Being non-preemptible is already equivalent to rcu read locking. From Documentation/RCU/rcu_dereference.rst: With the new consolidated RCU flavors, an RCU read-side critical section is entered using rcu_read_lock(), anything that disables bottom halves, anything that disables interrupts, or anything that disables preemption. so I actually think the coda code is already mostly fine, because that parent spin_lock may not stabilize d_child per se, but it *does* imply a RCU read lock. So I think you should drop the rcu_read_lock/rcu_read_unlock from that patch. But that struct inode *inode = d_inode_rcu(de); conversion is required to get a stable inode pointer. So half of this patch is unnecessary. Adding Paul to the cc just to verify that the docs are up-to-date and that we're still good here. Because we've gone back-and-forth on the "spinlocks are an implied RCU read-side critical section" a couple of times. Linus
On Fri, Nov 24, 2023 at 01:22:19PM -0800, Linus Torvalds wrote: > On Thu, 23 Nov 2023 at 22:04, Al Viro <viro@zeniv.linux.org.uk> wrote: > > > > ->d_lock on parent does not stabilize ->d_inode of child. > > We don't do much with that inode in there, but we need > > at least to avoid struct inode getting freed under us... > > Gaah. We've gone back and forth on this. Being non-preemptible is > already equivalent to rcu read locking. > > >From Documentation/RCU/rcu_dereference.rst: > > With the new consolidated > RCU flavors, an RCU read-side critical section is entered > using rcu_read_lock(), anything that disables bottom halves, > anything that disables interrupts, or anything that disables > preemption. > > so I actually think the coda code is already mostly fine, because that > parent spin_lock may not stabilize d_child per se, but it *does* imply > a RCU read lock. > > So I think you should drop the rcu_read_lock/rcu_read_unlock from that patch. > > But that > > struct inode *inode = d_inode_rcu(de); > > conversion is required to get a stable inode pointer. > > So half of this patch is unnecessary. > > Adding Paul to the cc just to verify that the docs are up-to-date and > that we're still good here. > > Because we've gone back-and-forth on the "spinlocks are an implied RCU > read-side critical section" a couple of times. Yes, spinlocks are implied RCU read-side critical sections. Even in -rt, where non-raw spinlocks are preemptible, courtesy of this: static __always_inline void __rt_spin_lock(spinlock_t *lock) { rtlock_might_resched(); rtlock_lock(&lock->lock); rcu_read_lock(); migrate_disable(); } So given -rt's preemptible spinlocks still being RCU readers, I need to explicitly call this out in the documentation. How about as shown below for a start? Thanx, Paul ------------------------------------------------------------------------ diff --git a/Documentation/RCU/rcu_dereference.rst b/Documentation/RCU/rcu_dereference.rst index 659d5913784d..2524dcdadde2 100644 --- a/Documentation/RCU/rcu_dereference.rst +++ b/Documentation/RCU/rcu_dereference.rst @@ -408,7 +408,10 @@ member of the rcu_dereference() to use in various situations: RCU flavors, an RCU read-side critical section is entered using rcu_read_lock(), anything that disables bottom halves, anything that disables interrupts, or anything that disables - preemption. + preemption. Please note that spinlock critical sections + are also implied RCU read-side critical sections, even when + they are preemptible, as they are in kernels built with + CONFIG_PREEMPT_RT=y. 2. If the access might be within an RCU read-side critical section on the one hand, or protected by (say) my_lock on the other,
diff --git a/fs/coda/cache.c b/fs/coda/cache.c index 3b8c4513118f..bfbc03c6b632 100644 --- a/fs/coda/cache.c +++ b/fs/coda/cache.c @@ -92,13 +92,16 @@ static void coda_flag_children(struct dentry *parent, int flag) { struct dentry *de; + rcu_read_lock(); spin_lock(&parent->d_lock); list_for_each_entry(de, &parent->d_subdirs, d_child) { + struct inode *inode = d_inode_rcu(de); /* don't know what to do with negative dentries */ - if (d_inode(de) ) - coda_flag_inode(d_inode(de), flag); + if (inode) + coda_flag_inode(inode, flag); } spin_unlock(&parent->d_lock); + rcu_read_unlock(); return; }