Fixes for dentry lockdep tracking on stacking filesystems
Subsystems (2)
cover Fixes for dentry lockdep tracking on stacking filesystems
The recent addition of lockdep tracking for in-lookup dentries didn't take into account the needs of stacking filesystems. For this we need different lock keys for different filesystems in the stack.
Thanks,
NeilBrown
[PATCH 1/3] VFS: per-fs-type lockdep key for dentry in-lookup locking [PATCH 2/3] VFS: rename lookup_map to dep_map
[PATCH 3/3] ovl: provide private lockdep class for dentry->dep_map
PATCH 1/3 VFS: per-fs-type lockdep key for dentry in-lookup locking
From: NeilBrown <[email protected]>
Stacked file-systems might call d_alloc_parallel() in another file-system while holding an in-lookup dentry is this filesystem. In order for lockdep not to report that, we give each file-system-type a different lockdep key for in-lookup locking.
This matches what is already done for lockdep tracking of i_rwsem.
--- fs/dcache.c | 4 ++-- include/linux/fs.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
fs/dcache.c +2 -2
@@ -1901,7 +1901,6 @@ EXPORT_SYMBOL(d_invalidate);static struct dentry *__d_alloc (struct super_block *sb,const struct qstr *name) { -static struct lock_class_key __lookup_key;struct dentry *dentry;char *dname;int err;
@@ -1959,7 +1958,8 @@ static struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) dentry->waiters =NULL ;INIT_HLIST_NODE (&dentry->d_sib); -lockdep_init_map (&dentry->lookup_map,"DCACHE_PAR_LOOKUP" , &__lookup_key,0 ); +lockdep_init_map (&dentry->lookup_map,"DCACHE_PAR_LOOKUP" , + &sb->s_type->d_lookup_key,0 );if (dentry->d_op && dentry->d_op->d_init) { err = dentry->d_op->d_init (dentry);
include/linux/fs.h +2 -0
@@ -2313,6 +2313,8 @@ struct file_system_type {struct lock_class_key i_mutex_key;struct lock_class_key invalidate_lock_key;struct lock_class_key i_mutex_dir_key; + +struct lock_class_key d_lookup_key; };#define MODULE_ALIAS_FS (NAME ) MODULE_ALIAS("fs-" NAME)
base-commit: 3879f51857325da9bf3cfb073280257cd16ae067
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 2/3 VFS: rename lookup_map to dep_map
In reply to NeilBrownFrom: NeilBrown <[email protected]>
lockdep has a number of macros which assume the lockdep_map is in a field called "dep_map". If dentry.lookup_map is renamed to dep_map these macros can be used.
In this patch we can now use might_lock(). In future lockdep_set_class() will be used.
--- fs/dcache.c | 15 +++++++-------- include/linux/dcache.h | 6 +++--- 2 files changed, 10 insertions(+), 11 deletions(-)
fs/dcache.c +7 -8
@@ -1958,7 +1958,7 @@ static struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) dentry->waiters =NULL ;INIT_HLIST_NODE (&dentry->d_sib); -lockdep_init_map (&dentry->lookup_map,"DCACHE_PAR_LOOKUP" , +lockdep_init_map (&dentry->dep_map,"DCACHE_PAR_LOOKUP" , &sb->s_type->d_lookup_key,0 );if (dentry->d_op && dentry->d_op->d_init) {
@@ -2040,7 +2040,7 @@ struct dentry *d_duplicate(struct dentry *dentry)return ERR_PTR (-ENOMEM ); new->d_flags |=DCACHE_PAR_LOOKUP ; -lock_map_acquire_try (&new->lookup_map); +lock_map_acquire_try (&new->dep_map);spin_lock (&parent->d_lock); new->d_parent =dget_dlock (parent);hlist_add_head (&new->d_sib, &parent->d_children);
@@ -2806,12 +2806,11 @@ static void d_wait_lookup(struct dentry *dentry) {if (likely (d_in_lookup (dentry))) {/* -* Tell lockdep we will wait for the lookup lock, after -* dropping ->d_lock, but won't actually take it. +* Tell lockdep we may wait for the lookup lock, after +* dropping ->d_lock. */ spin_release (&dentry->d_lock.dep_map, _THIS_IP_); -lock_map_acquire (&dentry->lookup_map); -lock_map_release (&dentry->lookup_map); +might_lock (dentry);spin_acquire (&dentry->d_lock.dep_map,0 ,1 , _THIS_IP_); dentry->d_flags |=DCACHE_LOOKUP_WAITERS ;
@@ -2936,7 +2935,7 @@ struct dentry *__d_alloc_parallel(struct dentry *parent, }hlist_bl_add_head (&new->d_in_lookup_hash, b);hlist_bl_unlock (b); -lock_map_acquire_try (&new->lookup_map); +lock_map_acquire_try (&new->dep_map);return new; mismatch:spin_unlock (&dentry->d_lock);
@@ -3035,7 +3034,7 @@ static void __d_lookup_unhash(struct dentry *dentry) b =in_lookup_hash (dentry->d_parent, dentry->d_name.hash);hlist_bl_lock (b); dentry->d_flags &= ~DCACHE_PAR_LOOKUP ; -lock_map_release (&dentry->lookup_map); +lock_map_release (&dentry->dep_map);__hlist_bl_del (&dentry->d_in_lookup_hash);hlist_bl_unlock (b); dentry->waiters =NULL ;
include/linux/dcache.h +3 -3
@@ -117,7 +117,7 @@ struct dentry {*/ /* lockdep tracking of DCACHE_PAR_LOOKUP locks */ -struct lockdep_map lookup_map; +struct lockdep_map dep_map;struct list_head d_lru;/* LRU list */ struct hlist_node d_sib;/* child of parent list */ struct hlist_head d_children;/* our children */
@@ -571,7 +571,7 @@ unsigned long vfs_pressure_ratio(unsigned long val);static inline void d_lookup_release (struct dentry *dentry) {if (d_in_lookup (dentry)) -lock_map_release (&dentry->lookup_map); +lock_map_release (&dentry->dep_map); }/**
@@ -585,7 +585,7 @@ static inline void d_lookup_release(struct dentry *dentry)static inline void d_lookup_acquire (struct dentry *dentry) {if (d_in_lookup (dentry)) -lock_map_acquire_try (&dentry->lookup_map); +lock_map_acquire_try (&dentry->dep_map); }/**
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 3/3 ovl: provide private lockdep class for dentry->dep_map
In reply to NeilBrownFrom: NeilBrown <[email protected]>
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.
--- fs/overlayfs/inode.c | 1 - fs/overlayfs/overlayfs.h | 2 ++ fs/overlayfs/super.c | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-)
fs/overlayfs/inode.c +0 -1
@@ -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_DEPTHstatic inline void ovl_lockdep_annotate_inode_mutex_key (struct inode *inode) {
fs/overlayfs/overlayfs.h +2 -0
@@ -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 ),
fs/overlayfs/super.c +19 -0
@@ -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
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Re: [PATCH 3/3] ovl: provide private lockdep class for dentry->dep_map
Quoted 8 lines · NeilBrown
From: NeilBrown <[email protected]>
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_typed_lookup_keyis not enough.
Quoted 7 lines
So provide a .d_init() function to update the map as it already done for
i_rwsemand ovl_inode.lock.Reported-and-tested-by "Borah, Chaitanya Kumar" <[email protected]>Fixes 59492f9991dc ("VFS: add lockdep monitoring of DCACHE_PAR_LOOKUP lock.")Signed-off-by NeilBrown <[email protected]>
Quoted 75 lines
--- fs/overlayfs/inode.c | 1 - fs/overlayfs/overlayfs.h | 2 ++ fs/overlayfs/super.c | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-)fs/overlayfs/inode.c +0
-1@@ -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_DEPTHstatic inline void ovl_lockdep_annotate_inode_mutex_key (struct inode *inode) {fs/overlayfs/overlayfs.h +2
-0@@ -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 ),fs/overlayfs/super.c +19
-1@@ -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
Re: [PATCH 3/3] ovl: provide private lockdep class for dentry->dep_map
In reply to NeilBrownHello Neil,
Quoted 10 lines · NeilBrown
From: NeilBrown <[email protected]>
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_typed_lookup_keyis not enough.So provide a .d_init() function to update the map as it already done for
i_rwsemand ovl_inode.lock.
Thank you for the patch. Any idea when this lands in linux-next?
==
Chaitanya
Quoted 76 lines
Reported-and-tested-by "Borah, Chaitanya Kumar" <[email protected]>Fixes 59492f9991dc ("VFS: add lockdep monitoring of DCACHE_PAR_LOOKUP lock.")Signed-off-by NeilBrown <[email protected]>--- fs/overlayfs/inode.c | 1 - fs/overlayfs/overlayfs.h | 2 ++ fs/overlayfs/super.c | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-)fs/overlayfs/inode.c +0
-1@@ -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_DEPTHstatic inline void ovl_lockdep_annotate_inode_mutex_key (struct inode *inode) {fs/overlayfs/overlayfs.h +2
-0@@ -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 ),fs/overlayfs/super.c +19
-0@@ -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
Amir Goldstein
maintainerQuoted 5 lines · NeilBrown
The recent addition of lockdep tracking for in-lookup dentries didn't take into account the needs of stacking filesystems. For this we need different lock keys for different filesystems in the stack.
Quoted 7 lines
Thanks,
NeilBrown[PATCH 1/3] VFS: per-fs-type lockdep key for dentry in-lookup locking [PATCH 2/3] VFS: rename
lookup_maptodep_map
[PATCH 3/3] ovl: provide private lockdep class fordentry->dep_map
Christian,
These are fixed to the series you have staged on vfs-7.4.lookup
Best append them to this branch per PR?
I have added my RVB for the ovl patch.
Thanks,
Amir.
Quoted 8 lines · NeilBrown
The recent addition of lockdep tracking for in-lookup dentries didn't take into account the needs of stacking filesystems. For this we need different lock keys for different filesystems in the stack.
Thanks,
NeilBrown[...]
Applied to the vfs-7.4.lookup branch of the vfs/vfs.git tree. Patches in the vfs-7.4.lookup branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.4.lookup
[1/3] VFS: per-fs-type lockdep key for dentry in-lookup locking
https://git.kernel.org/vfs/vfs/c/9f611778a273 [2/3] VFS: rename lookup_map to dep_map https://git.kernel.org/vfs/vfs/c/11f6be214ba3 [3/3] ovl: provide private lockdep class for dentry->dep_map https://git.kernel.org/vfs/vfs/c/a5478f5c226b