Skip to contentSkip to conversation

mm: Fully initialize invalidate_lock, amend lock class later

PATCH In review Sebastian Andrzej Siewior 2 participants 3 messages Sep 1, 2021 – Sep 17, 2021 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: Fully initialize invalidate_lock, amend lock class later

The function __init_rwsem() is not part of the official API, it just a helper function used by init_rwsem().
Changing the lock's class and name should be done by using lockdep_set_class_and_name() after the has been fully initialized. The overhead of the additional class struct and setting it twice is negligible and it works across all locks.

Fully initialize the lock with init_rwsem() and then set the custom class and name for the lock.

Fixes 730633f0b7f95 ("mm: Protect operations adding pages to page cache with invalidate_lock")
---
 fs/inode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/inode.c +4 -2
index cb41f02d8cedf..a49695f57e1ea 100644
@@ -190,8 +190,10 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
 	mapping_set_gfp_mask(mapping, GFP_HIGHUSER_MOVABLE);
 	mapping->private_data = NULL;
 	mapping->writeback_index = 0;
-	__init_rwsem(&mapping->invalidate_lock, "mapping.invalidate_lock",
-		     &sb->s_type->invalidate_lock_key);
+	init_rwsem(&mapping->invalidate_lock);
+	lockdep_set_class_and_name(&mapping->invalidate_lock,
+				   &sb->s_type->invalidate_lock_key,
+				   "mapping.invalidate_lock");
 	inode->i_private = NULL;
 	inode->i_mapping = mapping;
 	INIT_HLIST_HEAD(&inode->i_dentry);	/* buggered by rcu freeing */
Signature · 1 line
2.33.0
#1 lore raw
Quoted 7 lines · On 2021-09-01 10:44:04 [+0200], To [email protected] wrote:

The function __init_rwsem() is not part of the official API, it just a helper function used by init_rwsem().
Changing the lock's class and name should be done by using lockdep_set_class_and_name() after the has been fully initialized. The overhead of the additional class struct and setting it twice is negligible and it works across all locks.

Quoted 5 lines

Fully initialize the lock with init_rwsem() and then set the custom class and name for the lock.

Fixes 730633f0b7f95 ("mm: Protect operations adding pages to page cache with invalidate_lock")

ping.

Quoted 11 lines
---
 fs/inode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/inode.c +0 -0
index cb41f02d8cedf..a49695f57e1ea 100644
@@ -190,8 +190,10 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
 	mapping_set_gfp_mask(mapping, GFP_HIGHUSER_MOVABLE);
 	mapping->private_data = NULL;

fs/inode.c int inode_init_always(struct super_block *sb, struct inode *inode) · line 199

Quoted 10 lines
fs/inode.c +4 -2
 	mapping->writeback_index = 0;
-	__init_rwsem(&mapping->invalidate_lock, "mapping.invalidate_lock",
-		     &sb->s_type->invalidate_lock_key);
+	init_rwsem(&mapping->invalidate_lock);
+	lockdep_set_class_and_name(&mapping->invalidate_lock,
+				   &sb->s_type->invalidate_lock_key,
+				   "mapping.invalidate_lock");
 	inode->i_private = NULL;
 	inode->i_mapping = mapping;
 	INIT_HLIST_HEAD(&inode->i_dentry);	/* buggered by rcu freeing */

Sebastian

reviewer
#2 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 7 lines · Sebastian Andrzej Siewior

The function __init_rwsem() is not part of the official API, it just a helper function used by init_rwsem().
Changing the lock's class and name should be done by using lockdep_set_class_and_name() after the has been fully initialized. The overhead of the additional class struct and setting it twice is negligible and it works across all locks.

Quoted 5 lines

Fully initialize the lock with init_rwsem() and then set the custom class and name for the lock.

Fixes 730633f0b7f95 ("mm: Protect operations adding pages to page cache with invalidate_lock")

Fine by me, thanks for the fix. I'll queue it to my tree and push it to Linus.

Honza

Quoted 24 lines
---
 fs/inode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/inode.c +4 -2
index cb41f02d8cedf..a49695f57e1ea 100644
@@ -190,8 +190,10 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
 	mapping_set_gfp_mask(mapping, GFP_HIGHUSER_MOVABLE);
 	mapping->private_data = NULL;
 	mapping->writeback_index = 0;
-	__init_rwsem(&mapping->invalidate_lock, "mapping.invalidate_lock",
-		     &sb->s_type->invalidate_lock_key);
+	init_rwsem(&mapping->invalidate_lock);
+	lockdep_set_class_and_name(&mapping->invalidate_lock,
+				   &sb->s_type->invalidate_lock_key,
+				   "mapping.invalidate_lock");
 	inode->i_private = NULL;
 	inode->i_mapping = mapping;
 	INIT_HLIST_HEAD(&inode->i_dentry);	/* buggered by rcu freeing */
Signature · 1 line
2.33.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR