From patchwork Sat Oct 7 20:35:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13412478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B10C9E95A71 for ; Sat, 7 Oct 2023 20:36:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 302C18D0014; Sat, 7 Oct 2023 16:36:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B2638D0013; Sat, 7 Oct 2023 16:36:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 153D78D0014; Sat, 7 Oct 2023 16:36:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id F02C98D0013 for ; Sat, 7 Oct 2023 16:36:06 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CBCE2140170 for ; Sat, 7 Oct 2023 20:36:06 +0000 (UTC) X-FDA: 81319822332.20.3434F7B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id 2DFCA16000A for ; Sat, 7 Oct 2023 20:36:04 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lQcmH1QC; dmarc=none; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696710965; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=M8hQeLdTKHD1dkcSFiFXLuX/qDihXIc+aJqbr2IAWzY=; b=cuV8MLpT9uFidewr6H4mQOtyOKfrIzAnWCYMVafG7Lw7PATibNy1qmL2DbOktf18xfbH0t gANsjvonxhXGTOr4KXhV3jbo6SIYelzUjQ1GXvHzgsedr6yMZvcmKBM50OOAIsSQSThAIv GzXnmZNqwxnKoNtMJ3RruagPLUSvSO0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lQcmH1QC; dmarc=none; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696710965; a=rsa-sha256; cv=none; b=SpNeRxpmJWRPJwCkB6AnLo3wy1lHO9bWC7KizhHY3REiMqqntIQk1rbS966aiVwTrwvBeY Qj3Py90BYwJ4k1q950ujTLZia1/CQiI0BlhwqnZpd0DVWlXZlP17Ly1mKSgc2jvY2l71kj eV3zGSAEvxdZXmYoRYB3gO9kcajO5DU= 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 X-Rspam-User: X-Stat-Signature: y4nzd755ge77h1q1sig7i783rkm61k4d X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2DFCA16000A X-HE-Tag: 1696710964-582276 X-HE-Meta: U2FsdGVkX1/RlP4qZx3hRCx+5/3EnpSYxoLolRmKPYh1t1kHiMnBhK6n/1Hl8JhAylFR3Jlh2OmGm6LsX6qnuPQ1ApmtFrNpDPVxJHok7Ih00Ra/3I1u21oXCVN1kpBOfDW8FlA6oHPcxf8fiAx3KE3hFeHDZBqnIUy9+mz9Ce3RdMrokmfoku21avxw9jRPQiNMxuYrvHJWayGd9yl6mR5XibENRFC+C5NS2rOFiUUhrtCSSwddMJwMunIRpUe4TsxdKF3QmkVGR0Rf8WuJr5dxdG72vlErwzYCBtqbsAq6NdkkdlIllRCLV3neg/plnZAZNHMsUDNxVPzbPYu3MthUUkZz6fDoXAlyb85xleSZIIyEUrC4iUHk0xfaNQpEFserd+LFCy4I6E4EXzKmFnyiSbSM0+jLYvdWuyLOBIPlzqhR4zWNlt2g6HXTldzrUb5VAjpXVIOfY+4AbNbez2zcXInNmMUCdmyJ4ysXRyH1ISkR29N4AtZo3QFl2ti8AI4DY/n1cnHgLIgwM0UgZiwLs/LLStLui89XOdS8f4f7mYL38O1LouanLM1BnQKnvt7TGKEdm/kLvZamhvLVLlF2SxZ5TTgL3+xr/RuGWn29ShvklMqSG4xxI884mnJ6zCejdcS+qgrqy89ifPidWKgEPRmMVIzO85btn9cmhfmL+3EWTPulhEIyp2J2sElJ1dKkzdNkbShjkdRNHTOnh3ndY2ivBZdQVycsJQ1lYNXBUhPtIgTXrzmTHD2TB5Oky6A2ls1ymnRKFKxNVePu/xVsY+sHvNk06knmDmJY7SS9typXqJ3ulA5vzvwR2FBDMF2oP8uTes/1l32XP3ovBSDHxvsoCPSN+9nEWI/g3eTPdbYXMTiQkRD+vdqK3+OahuBMjj9N12AcjhEfmc3rF7FXjPOYsWpEFhbcMx0t6itcPyH6Gzds/u3sxKkEgvpcx0si1zw3ocGU8TSKSJO TRrKiP5O M+RWhBLVteF3ldE91BOo89oGzCzUrevDGOQMa7RuGPKLrMvVpp3tvU+xkqurotDMaGsEuaN+DCJe03j4T7AjZZQJUNF/gNbRhHgrodoeJkRASm4w0VjJj4A7TG46z8MVlVRZ4McakrHgiR7Gk7uXb6V2eIglGATZmUHAC72WtDTZmJx2p/Wt7VO2zQqrqriHlqBOSDbVaviZgpZAhE/6eGzvTJZry9S737WIl X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);