All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: don't set lock_owner when locking tree pages for reading
@ 2022-06-09  2:39 Zygo Blaxell
  2022-06-09  5:03 ` Nikolay Borisov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Zygo Blaxell @ 2022-06-09  2:39 UTC (permalink / raw)
  To: linux-btrfs

In 196d59ab9ccc "btrfs: switch extent buffer tree lock to rw_semaphore"
the functions for tree read locking were rewritten, and in the process
the read lock functions started setting eb->lock_owner = current->pid.
Previously lock_owner was only set in tree write lock functions.

Read locks are shared, so they don't have exclusive ownership of the
underlying object, so setting lock_owner to any single value for a
read lock makes no sense.  It's mostly harmless because write locks
and read locks are mutually exclusive, and none of the existing code
in btrfs (btrfs_init_new_buffer and print_eb_refs_lock) cares what
nonsense is written in lock_owner when no writer is holding the lock.

KCSAN does care, and will complain about the data race incessantly.
Remove the assignments in the read lock functions because they're
useless noise.

Fixes: 196d59ab9ccc ("btrfs: switch extent buffer tree lock to rw_semaphore")
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
---
 fs/btrfs/locking.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c
index 313d9d685adb..33461b4f9c8b 100644
--- a/fs/btrfs/locking.c
+++ b/fs/btrfs/locking.c
@@ -45,7 +45,6 @@ void __btrfs_tree_read_lock(struct extent_buffer *eb, enum btrfs_lock_nesting ne
 		start_ns = ktime_get_ns();
 
 	down_read_nested(&eb->lock, nest);
-	eb->lock_owner = current->pid;
 	trace_btrfs_tree_read_lock(eb, start_ns);
 }
 
@@ -62,7 +61,6 @@ void btrfs_tree_read_lock(struct extent_buffer *eb)
 int btrfs_try_tree_read_lock(struct extent_buffer *eb)
 {
 	if (down_read_trylock(&eb->lock)) {
-		eb->lock_owner = current->pid;
 		trace_btrfs_try_tree_read_lock(eb);
 		return 1;
 	}
@@ -90,7 +88,6 @@ int btrfs_try_tree_write_lock(struct extent_buffer *eb)
 void btrfs_tree_read_unlock(struct extent_buffer *eb)
 {
 	trace_btrfs_tree_read_unlock(eb);
-	eb->lock_owner = 0;
 	up_read(&eb->lock);
 }
 
-- 
2.30.2


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

* Re: [PATCH] btrfs: don't set lock_owner when locking tree pages for reading
  2022-06-09  2:39 [PATCH] btrfs: don't set lock_owner when locking tree pages for reading Zygo Blaxell
@ 2022-06-09  5:03 ` Nikolay Borisov
  2022-06-09  9:42 ` Filipe Manana
  2022-06-13 18:48 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Nikolay Borisov @ 2022-06-09  5:03 UTC (permalink / raw)
  To: Zygo Blaxell, linux-btrfs



On 9.06.22 г. 5:39 ч., Zygo Blaxell wrote:
> In 196d59ab9ccc "btrfs: switch extent buffer tree lock to rw_semaphore"
> the functions for tree read locking were rewritten, and in the process
> the read lock functions started setting eb->lock_owner = current->pid.
> Previously lock_owner was only set in tree write lock functions.
> 
> Read locks are shared, so they don't have exclusive ownership of the
> underlying object, so setting lock_owner to any single value for a
> read lock makes no sense.  It's mostly harmless because write locks
> and read locks are mutually exclusive, and none of the existing code
> in btrfs (btrfs_init_new_buffer and print_eb_refs_lock) cares what
> nonsense is written in lock_owner when no writer is holding the lock.
> 
> KCSAN does care, and will complain about the data race incessantly.
> Remove the assignments in the read lock functions because they're
> useless noise.
> 
> Fixes: 196d59ab9ccc ("btrfs: switch extent buffer tree lock to rw_semaphore")
> Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

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

* Re: [PATCH] btrfs: don't set lock_owner when locking tree pages for reading
  2022-06-09  2:39 [PATCH] btrfs: don't set lock_owner when locking tree pages for reading Zygo Blaxell
  2022-06-09  5:03 ` Nikolay Borisov
@ 2022-06-09  9:42 ` Filipe Manana
  2022-06-13 18:48 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Filipe Manana @ 2022-06-09  9:42 UTC (permalink / raw)
  To: Zygo Blaxell; +Cc: linux-btrfs

On Wed, Jun 08, 2022 at 10:39:36PM -0400, Zygo Blaxell wrote:
> In 196d59ab9ccc "btrfs: switch extent buffer tree lock to rw_semaphore"
> the functions for tree read locking were rewritten, and in the process
> the read lock functions started setting eb->lock_owner = current->pid.
> Previously lock_owner was only set in tree write lock functions.
> 
> Read locks are shared, so they don't have exclusive ownership of the
> underlying object, so setting lock_owner to any single value for a
> read lock makes no sense.  It's mostly harmless because write locks
> and read locks are mutually exclusive, and none of the existing code
> in btrfs (btrfs_init_new_buffer and print_eb_refs_lock) cares what
> nonsense is written in lock_owner when no writer is holding the lock.
> 
> KCSAN does care, and will complain about the data race incessantly.
> Remove the assignments in the read lock functions because they're
> useless noise.
> 
> Fixes: 196d59ab9ccc ("btrfs: switch extent buffer tree lock to rw_semaphore")
> Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>


Looks good to me.
Btw, the subject is misleading, the part "when locking tree pages" gives
the idea that it's about page locks, but what we are locking is an extent
buffer, so it should read like "... when locking extent buffer for reading".
Thanks.

Reviewed-by: Filipe Manana <fdmanana@suse.com>

> ---
>  fs/btrfs/locking.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c
> index 313d9d685adb..33461b4f9c8b 100644
> --- a/fs/btrfs/locking.c
> +++ b/fs/btrfs/locking.c
> @@ -45,7 +45,6 @@ void __btrfs_tree_read_lock(struct extent_buffer *eb, enum btrfs_lock_nesting ne
>  		start_ns = ktime_get_ns();
>  
>  	down_read_nested(&eb->lock, nest);
> -	eb->lock_owner = current->pid;
>  	trace_btrfs_tree_read_lock(eb, start_ns);
>  }
>  
> @@ -62,7 +61,6 @@ void btrfs_tree_read_lock(struct extent_buffer *eb)
>  int btrfs_try_tree_read_lock(struct extent_buffer *eb)
>  {
>  	if (down_read_trylock(&eb->lock)) {
> -		eb->lock_owner = current->pid;
>  		trace_btrfs_try_tree_read_lock(eb);
>  		return 1;
>  	}
> @@ -90,7 +88,6 @@ int btrfs_try_tree_write_lock(struct extent_buffer *eb)
>  void btrfs_tree_read_unlock(struct extent_buffer *eb)
>  {
>  	trace_btrfs_tree_read_unlock(eb);
> -	eb->lock_owner = 0;
>  	up_read(&eb->lock);
>  }
>  
> -- 
> 2.30.2
> 

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

* Re: [PATCH] btrfs: don't set lock_owner when locking tree pages for reading
  2022-06-09  2:39 [PATCH] btrfs: don't set lock_owner when locking tree pages for reading Zygo Blaxell
  2022-06-09  5:03 ` Nikolay Borisov
  2022-06-09  9:42 ` Filipe Manana
@ 2022-06-13 18:48 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2022-06-13 18:48 UTC (permalink / raw)
  To: Zygo Blaxell; +Cc: linux-btrfs

On Wed, Jun 08, 2022 at 10:39:36PM -0400, Zygo Blaxell wrote:
> In 196d59ab9ccc "btrfs: switch extent buffer tree lock to rw_semaphore"
> the functions for tree read locking were rewritten, and in the process
> the read lock functions started setting eb->lock_owner = current->pid.
> Previously lock_owner was only set in tree write lock functions.
> 
> Read locks are shared, so they don't have exclusive ownership of the
> underlying object, so setting lock_owner to any single value for a
> read lock makes no sense.  It's mostly harmless because write locks
> and read locks are mutually exclusive, and none of the existing code
> in btrfs (btrfs_init_new_buffer and print_eb_refs_lock) cares what
> nonsense is written in lock_owner when no writer is holding the lock.
> 
> KCSAN does care, and will complain about the data race incessantly.
> Remove the assignments in the read lock functions because they're
> useless noise.
> 
> Fixes: 196d59ab9ccc ("btrfs: switch extent buffer tree lock to rw_semaphore")
> Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>

Added to misc-next, thanks.

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

end of thread, other threads:[~2022-06-13 20:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-09  2:39 [PATCH] btrfs: don't set lock_owner when locking tree pages for reading Zygo Blaxell
2022-06-09  5:03 ` Nikolay Borisov
2022-06-09  9:42 ` Filipe Manana
2022-06-13 18:48 ` David Sterba

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.