* [PATCH AUTOSEL 5.5 043/106] btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root
[not found] <20200415114226.13103-1-sashal@kernel.org>
@ 2020-04-15 11:41 ` Sasha Levin
2020-04-15 11:41 ` [PATCH AUTOSEL 5.5 044/106] btrfs: add RCU locks around block group initialization Sasha Levin
1 sibling, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2020-04-15 11:41 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Josef Bacik, Nikolay Borisov, David Sterba, Sasha Levin,
linux-btrfs
From: Josef Bacik <josef@toxicpanda.com>
[ Upstream commit 4cdfd93002cb84471ed85b4999cd38077a317873 ]
We want to use this for dropping all roots, and in some error cases we
may not have a root, so handle this to make the cleanup code easier.
Make btrfs_grab_fs_root the same so we can use it in cases where the
root may not exist (like the quota root).
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/btrfs/disk-io.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 76f123ebb2921..3c63b0965ad64 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -97,6 +97,8 @@ struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info);
*/
static inline struct btrfs_root *btrfs_grab_fs_root(struct btrfs_root *root)
{
+ if (!root)
+ return NULL;
if (refcount_inc_not_zero(&root->refs))
return root;
return NULL;
@@ -104,6 +106,8 @@ static inline struct btrfs_root *btrfs_grab_fs_root(struct btrfs_root *root)
static inline void btrfs_put_fs_root(struct btrfs_root *root)
{
+ if (!root)
+ return;
if (refcount_dec_and_test(&root->refs))
kfree(root);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH AUTOSEL 5.5 044/106] btrfs: add RCU locks around block group initialization
[not found] <20200415114226.13103-1-sashal@kernel.org>
2020-04-15 11:41 ` [PATCH AUTOSEL 5.5 043/106] btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root Sasha Levin
@ 2020-04-15 11:41 ` Sasha Levin
1 sibling, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2020-04-15 11:41 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Madhuparna Bhowmik, Guenter Roeck, David Sterba, Sasha Levin,
linux-btrfs
From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
[ Upstream commit 29566c9c773456467933ee22bbca1c2b72a3506c ]
The space_info list is normally RCU protected and should be traversed
with rcu_read_lock held. There's a warning
[29.104756] WARNING: suspicious RCU usage
[29.105046] 5.6.0-rc4-next-20200305 #1 Not tainted
[29.105231] -----------------------------
[29.105401] fs/btrfs/block-group.c:2011 RCU-list traversed in non-reader section!!
pointing out that the locking is missing in btrfs_read_block_groups.
However this is not necessary as the list traversal happens at mount
time when there's no other thread potentially accessing the list.
To fix the warning and for consistency let's add the RCU lock/unlock,
the code won't be affected much as it's doing some lightweight
operations.
Reported-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/btrfs/block-group.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index acf0b7d879bc0..5886b218641cf 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1824,6 +1824,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
btrfs_release_path(path);
}
+ rcu_read_lock();
list_for_each_entry_rcu(space_info, &info->space_info, list) {
if (!(btrfs_get_alloc_profile(info, space_info->flags) &
(BTRFS_BLOCK_GROUP_RAID10 |
@@ -1844,6 +1845,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
list)
inc_block_group_ro(cache, 1);
}
+ rcu_read_unlock();
btrfs_init_global_block_rsv(info);
ret = check_chunk_block_group_mappings(info);
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-04-15 12:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20200415114226.13103-1-sashal@kernel.org>
2020-04-15 11:41 ` [PATCH AUTOSEL 5.5 043/106] btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root Sasha Levin
2020-04-15 11:41 ` [PATCH AUTOSEL 5.5 044/106] btrfs: add RCU locks around block group initialization Sasha Levin
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).