Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1133189rdb; Sat, 7 Oct 2023 13:36:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHES6Wdfz+duCaGC0fbRJMxsv9QzcKUJuCfln0z2qJcyJThbZSab+cyVMM70npf28UArdkh X-Received: by 2002:a17:902:ed54:b0:1c6:845:27c5 with SMTP id y20-20020a170902ed5400b001c6084527c5mr12181821plb.61.1696710990221; Sat, 07 Oct 2023 13:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696710990; cv=none; d=google.com; s=arc-20160816; b=sBjAi6ahUqYTBZozV0c1Uh0Y+kU186KB0rYGW4zqFTiPFDLrhLfsYVwLFXnTdtFkrq NXQxpDoHHXKHuo6u+cT+DaMQdXYBxPLzEGmhVg4KpktJa1iCr44UArWW3z0mVIdndwUD tXZYVSRI3iLOBsQ4dtXPFHXubXuOvAFaryYQbADISin64iBZjtjCXwhFpbXSXXFC9y07 VASIoMhjc8hmKUYml482EkEdMrWeqqSMK9rsZ29oCHxrwFH/3euX4/zp/aojbo/Kp2yb SVorK7yuy/rVf5b0mUUlLWCQFlkpPLE/si6e6Pzi0M/xz7YTc3Lq0GV9R5x/Vy2GP29i sI6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=M8hQeLdTKHD1dkcSFiFXLuX/qDihXIc+aJqbr2IAWzY=; fh=xOXdQT4SsuXIFM5Yjo81cCn92/LeCLHKO8ZW4BZqIMk=; b=S+U0uwmiwU+F8elr7yNdG3nZ8EpSAA6zCnAPpvYknW/qTEgchJS2xzs3zs/CUy6XUD bHfEocnGh7GTS5aTzfUU8JBcxgefhHOQZZABkXo8auL2D4hlQPSDrO7pjWuoiosLnGOQ mYVCLFFrESrYiui/u3UNECd8qoUA/OcF8At/QffM4fDEdYjPIzrkQfPdyhdzSqyjSYg2 OCiVXbkVASzj+5DZgUMMKEC1Xx5OkvCUm+QJwsFzT+d7qj4f1kP3DCtpqRY+IGAZIQfz FHSrfa3Ol9GE11FbnaZeiex8ac2cmuWHo77ZxEDA+zCfRTf7w1IgbdrVp/LWQFv7r7Rz U4ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=lQcmH1QC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id u1-20020a17090341c100b001bda1941a8esi6861545ple.582.2023.10.07.13.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 13:36:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=lQcmH1QC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id EF569804DD9E; Sat, 7 Oct 2023 13:36:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344211AbjJGUgO (ORCPT + 99 others); Sat, 7 Oct 2023 16:36:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344180AbjJGUgG (ORCPT ); Sat, 7 Oct 2023 16:36:06 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A9F695; Sat, 7 Oct 2023 13:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=M8hQeLdTKHD1dkcSFiFXLuX/qDihXIc+aJqbr2IAWzY=; b=lQcmH1QCtfWiamaUkdggT/KxOo OK0QlZrv3IuBk3rgCNbSb2qFSC5vOBeAFcN8mrzvdhDtou8RV6BMahNOsV1MSS3hJGeedDAplZ/cV YyZccOspWO/IbpA8IroZfVlWGHQo5O+RCZo0GoNt5Yux+UC2DMSWlPddd+fjtxxMg5V5rPKo917iV WjmPfeKI9oYkPHpC3LSi9i3iUyWzvGuW88sPcLpQLhA1QXCCqoAa2MqrVH0X0URx34oIh7eWvoHi7 JFUsXkX6bwQdA1WfweORl4aGPqfBoGr6P0DIIn4hQWkVuXzWWIWuUVR7MIui0t5jKGZAvoGc/z6VP kst7qR8w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qpE1Y-005mLI-Ux; Sat, 07 Oct 2023 20:35:44 +0000 From: "Matthew Wilcox (Oracle)" To: Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chandan Babu R , "Darrick J . Wong" , linux-xfs@vger.kernel.org, Mateusz Guzik Subject: [PATCH v2 5/5] fs: Add inode_assert_locked() and inode_assert_locked_excl() Date: Sat, 7 Oct 2023 21:35:43 +0100 Message-Id: <20231007203543.1377452-6-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20231007203543.1377452-1-willy@infradead.org> References: <20231007203543.1377452-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Sat, 07 Oct 2023 13:36:29 -0700 (PDT) Use the new rwsem_assert_held functions to implement these new assertions. Convert the inode_is_locked() callers in the VFS to use them. Signed-off-by: Matthew Wilcox (Oracle) --- fs/attr.c | 2 +- fs/namei.c | 6 +++--- include/linux/fs.h | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index a8ae5f6d9b16..5e32b0a4f8c2 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -387,7 +387,7 @@ int notify_change(struct mnt_idmap *idmap, struct dentry *dentry, struct timespec64 now; unsigned int ia_valid = attr->ia_valid; - WARN_ON_ONCE(!inode_is_locked(inode)); + inode_assert_locked_excl(inode); error = may_setattr(idmap, inode, ia_valid); if (error) diff --git a/fs/namei.c b/fs/namei.c index 567ee547492b..6b595ad4318d 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2708,7 +2708,7 @@ struct dentry *try_lookup_one_len(const char *name, struct dentry *base, int len struct qstr this; int err; - WARN_ON_ONCE(!inode_is_locked(base->d_inode)); + inode_assert_locked(base->d_inode); err = lookup_one_common(&nop_mnt_idmap, name, base, len, &this); if (err) @@ -2735,7 +2735,7 @@ struct dentry *lookup_one_len(const char *name, struct dentry *base, int len) struct qstr this; int err; - WARN_ON_ONCE(!inode_is_locked(base->d_inode)); + inode_assert_locked(base->d_inode); err = lookup_one_common(&nop_mnt_idmap, name, base, len, &this); if (err) @@ -2765,7 +2765,7 @@ struct dentry *lookup_one(struct mnt_idmap *idmap, const char *name, struct qstr this; int err; - WARN_ON_ONCE(!inode_is_locked(base->d_inode)); + inode_assert_locked(base->d_inode); err = lookup_one_common(idmap, name, base, len, &this); if (err) diff --git a/include/linux/fs.h b/include/linux/fs.h index b528f063e8ff..e01e041c102b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -832,6 +832,16 @@ static inline int inode_is_locked(struct inode *inode) return rwsem_is_locked(&inode->i_rwsem); } +static inline void inode_assert_locked(const struct inode *inode) +{ + rwsem_assert_held(&inode->i_rwsem); +} + +static inline void inode_assert_locked_excl(const struct inode *inode) +{ + rwsem_assert_held_write(&inode->i_rwsem); +} + static inline void inode_lock_nested(struct inode *inode, unsigned subclass) { down_write_nested(&inode->i_rwsem, subclass); -- 2.40.1