linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix the wrong rcu_str_deref() usage
@ 2024-10-02 21:29 Qu Wenruo
  2024-10-03 10:10 ` Filipe Manana
  2024-10-04 10:03 ` Johannes Thumshirn
  0 siblings, 2 replies; 4+ messages in thread
From: Qu Wenruo @ 2024-10-02 21:29 UTC (permalink / raw)
  To: linux-btrfs

For rcu_str_deref(), it should be called with rcu read lock hold.
But inside the function is_same_device(), the rcu string is accessed
without holding the rcu read lock, causing rcu warnings.

Fix it by holding the rcu read lock during the path resolution of the
existing device.

This will be folded into the offending patch "btrfs: avoid unnecessary
device path update for the same device"

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/volumes.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 35c4d151b5b0..3867d3c18be5 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -807,8 +807,10 @@ static bool is_same_device(struct btrfs_device *device, const char *new_path)
 	if (!device->name)
 		goto out;
 
+	rcu_read_lock();
 	old_path = rcu_str_deref(device->name);
 	ret = kern_path(old_path, LOOKUP_FOLLOW, &old);
+	rcu_read_unlock();
 	if (ret)
 		goto out;
 	ret = kern_path(new_path, LOOKUP_FOLLOW, &new);
-- 
2.46.2


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

end of thread, other threads:[~2024-10-04 10:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-02 21:29 [PATCH] btrfs: fix the wrong rcu_str_deref() usage Qu Wenruo
2024-10-03 10:10 ` Filipe Manana
2024-10-04 10:03 ` Johannes Thumshirn
2024-10-04 10:08   ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).