All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: Fully initialize invalidate_lock, amend lock class later
@ 2021-09-01  8:44 Sebastian Andrzej Siewior
  2021-09-17 10:34 ` Sebastian Andrzej Siewior
  2021-09-17 11:39 ` Jan Kara
  0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2021-09-01  8:44 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Alexander Viro, Jan Kara, Peter Zijlstra, Thomas Gleixner

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")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 fs/inode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index cb41f02d8cedf..a49695f57e1ea 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -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 */
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: Fully initialize invalidate_lock, amend lock class later
  2021-09-01  8:44 [PATCH] mm: Fully initialize invalidate_lock, amend lock class later Sebastian Andrzej Siewior
@ 2021-09-17 10:34 ` Sebastian Andrzej Siewior
  2021-09-17 11:39 ` Jan Kara
  1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2021-09-17 10:34 UTC (permalink / raw)
  To: linux-fsdevel, Peter Zijlstra; +Cc: Alexander Viro, Jan Kara, Thomas Gleixner

On 2021-09-01 10:44:04 [+0200], To linux-fsdevel@vger.kernel.org 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.
> 
> 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")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

ping.

> ---
>  fs/inode.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index cb41f02d8cedf..a49695f57e1ea 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -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 */

Sebastian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: Fully initialize invalidate_lock, amend lock class later
  2021-09-01  8:44 [PATCH] mm: Fully initialize invalidate_lock, amend lock class later Sebastian Andrzej Siewior
  2021-09-17 10:34 ` Sebastian Andrzej Siewior
@ 2021-09-17 11:39 ` Jan Kara
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2021-09-17 11:39 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-fsdevel, Alexander Viro, Jan Kara, Peter Zijlstra, Thomas Gleixner

On Wed 01-09-21 10:44:03, Sebastian Andrzej Siewior 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.
> 
> 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")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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

								Honza

> ---
>  fs/inode.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index cb41f02d8cedf..a49695f57e1ea 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -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 */
> -- 
> 2.33.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-17 11:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01  8:44 [PATCH] mm: Fully initialize invalidate_lock, amend lock class later Sebastian Andrzej Siewior
2021-09-17 10:34 ` Sebastian Andrzej Siewior
2021-09-17 11:39 ` Jan Kara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.