[PATCH 3/3] ovl: provide private lockdep class for dentry->dep_map
From: NeilBrown
Date: Fri Oct 02 2026 - 18:48:11 EST
From: NeilBrown <neil@xxxxxxxxxx>
Now that d_alloc_parallel() locking is tracked by lockdep, ovl needs to
take care that it doesn't trigger on deliberate recursion into
subordinate filesystems. As ovl can stack over itself, the use
of the per-file_system_type d_lookup_key is not enough.
So provide a .d_init() function to update the map as it already done for
i_rwsem and ovl_inode.lock.
Reported-and-tested-by: "Borah, Chaitanya Kumar" <chaitanya.kumar.borah@xxxxxxxxx>
Link: https://lore.kernel.org/all/e3772a51-eabc-4c31-b73d-f3187bf1b3b2@xxxxxxxxx/
Fixes: 59492f9991dc ("VFS: add lockdep monitoring of DCACHE_PAR_LOOKUP lock.")
Signed-off-by: NeilBrown <neil@xxxxxxxxxx>
---
fs/overlayfs/inode.c | 1 -
fs/overlayfs/overlayfs.h | 2 ++
fs/overlayfs/super.c | 19 +++++++++++++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index 401cb8c75520..bf40198c8b8a 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -816,7 +816,6 @@ static const struct address_space_operations ovl_aops = {
* - OVL_I(inode)->lock (ovl_inode_lock[1])
* - upper_mnt->mnt_sb->s_writers (ovl_want_write[0])
*/
-#define OVL_MAX_NESTING FILESYSTEM_MAX_STACK_DEPTH
static inline void ovl_lockdep_annotate_inode_mutex_key(struct inode *inode)
{
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index e0d8c6152e9f..64cbe4c4bd3e 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -16,6 +16,8 @@
#undef pr_fmt
#define pr_fmt(fmt) "overlayfs: " fmt
+#define OVL_MAX_NESTING FILESYSTEM_MAX_STACK_DEPTH
+
enum ovl_path_type {
__OVL_PATH_UPPER = (1 << 0),
__OVL_PATH_MERGE = (1 << 1),
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index e487597337e8..08147799e47c 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -163,10 +163,28 @@ static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
return ovl_dentry_revalidate_common(dentry, flags, true);
}
+#ifdef CONFIG_LOCKDEP
+static int ovl_dentry_init(struct dentry *dentry)
+{
+ static struct lock_class_key ovl_d_lock_key[OVL_MAX_NESTING];
+ int depth = dentry->d_sb->s_stack_depth - 1;
+
+ if (WARN_ON_ONCE(depth < 0 || depth >= OVL_MAX_NESTING))
+ depth = 0;
+
+ lockdep_set_class(dentry, &ovl_d_lock_key[depth]);
+
+ return 0;
+}
+#else
+#define ovl_dentry_init NULL
+#endif
+
static const struct dentry_operations ovl_dentry_operations = {
.d_real = ovl_d_real,
.d_revalidate = ovl_dentry_revalidate,
.d_weak_revalidate = ovl_dentry_weak_revalidate,
+ .d_init = ovl_dentry_init,
};
#if IS_ENABLED(CONFIG_UNICODE)
@@ -176,6 +194,7 @@ static const struct dentry_operations ovl_dentry_ci_operations = {
.d_weak_revalidate = ovl_dentry_weak_revalidate,
.d_hash = generic_ci_d_hash,
.d_compare = generic_ci_d_compare,
+ .d_init = ovl_dentry_init,
};
#endif
--
2.50.0.107.gf914562f5916.dirty