From: Bhupesh <bhupesh@igalia.com>
To: linux-ext4@vger.kernel.org
Cc: bhupesh@igalia.com, tytso@mit.edu, kernel-dev@igalia.com,
linux-kernel@vger.kernel.org, revest@google.com,
adilger.kernel@dilger.ca, cascardo@igalia.com
Subject: [PATCH v2 2/2] fs/ext4/xattr: Check for 'xattr_sem' inside 'ext4_xattr_delete_inode'
Date: Tue, 28 Jan 2025 13:57:51 +0530 [thread overview]
Message-ID: <20250128082751.124948-3-bhupesh@igalia.com> (raw)
In-Reply-To: <20250128082751.124948-1-bhupesh@igalia.com>
Once we are inside the 'ext4_xattr_delete_inode' function and trying
to delete the inode, the 'xattr_sem' should be unlocked.
We need trylock here to avoid false-positive warning from lockdep
about reclaim circular dependency.
This makes the 'ext4_xattr_delete_inode' implementation mimic the
existing 'ext2_xattr_delete_inode' implementation and thus avoid
similar lockdep issues while deleting inodes.
Signed-off-by: Bhupesh <bhupesh@igalia.com>
---
fs/ext4/xattr.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 6ff94cdf1515..b98267c09b00 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -2935,7 +2935,20 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
struct ext4_iloc iloc = { .bh = NULL };
struct ext4_xattr_entry *entry;
struct inode *ea_inode;
- int error;
+ int error = 0;
+
+ /*
+ * We are the only ones holding inode reference. The xattr_sem should
+ * better be unlocked! We could as well just not acquire xattr_sem at
+ * all but this makes the code more futureproof. OTOH we need trylock
+ * here to avoid false-positive warning from lockdep about reclaim
+ * circular dependency.
+ */
+ if (WARN_ON_ONCE(!down_write_trylock(&EXT4_I(inode)->xattr_sem)))
+ return error;
+
+ if (!EXT4_I(inode)->i_file_acl)
+ goto cleanup;
error = ext4_journal_ensure_credits(handle, extra_credits,
ext4_free_metadata_revoke_credits(inode->i_sb, 1));
@@ -3024,6 +3037,7 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
cleanup:
brelse(iloc.bh);
brelse(bh);
+ up_write(&EXT4_I(inode)->xattr_sem);
return error;
}
--
2.38.1
next prev parent reply other threads:[~2025-01-28 8:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-28 8:27 [PATCH v2 0/2] fs/ext4/xattr: Fix issues seen while deleting xattr inode(s) Bhupesh
2025-01-28 8:27 ` [PATCH v2 1/2] fs/ext4/xattr: Ignore xattrs past end Bhupesh
2025-01-28 8:27 ` Bhupesh [this message]
2025-03-17 15:17 ` [PATCH v2 2/2] fs/ext4/xattr: Check for 'xattr_sem' inside 'ext4_xattr_delete_inode' Theodore Ts'o
2025-03-18 11:06 ` Bhupesh Sharma
2025-03-18 3:41 ` [PATCH v2 0/2] fs/ext4/xattr: Fix issues seen while deleting xattr inode(s) Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250128082751.124948-3-bhupesh@igalia.com \
--to=bhupesh@igalia.com \
--cc=adilger.kernel@dilger.ca \
--cc=cascardo@igalia.com \
--cc=kernel-dev@igalia.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=revest@google.com \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®