btrfs: relocation: fix misplaced barrier in reloc_root_is_dead
PATCH 1/1 btrfs: relocation: fix misplaced barrier in reloc_root_is_dead
Fix a misplaced barrier in reloc_root_is_dead. The BTRFS_ROOT_DEAD_RELOC_TREE bit should be checked before accessing reloc_root.
The fix forces the order documented in the original commit:
"In the cross section C-D, either caller gets the DEAD bit set, avoiding access reloc_root no matter if it's safe or not. Or caller get the DEAD bit cleared, then access reloc_root, which is already NULL, nothing will be wrong."
static bool reloc_root_is_dead()
smp_rmb(); <--- misplaced
if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state))
return true;
return false;
}static bool have_reloc_root(struct btrfs_root *root)
{
if (reloc_root_is_dead(root))
return false;
<--- the barrier should happen here
if (!root->reloc_root)
return false;
return true;
}--- fs/btrfs/relocation.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/relocation.c +2 -3
@@ -289,15 +289,14 @@ static int update_backref_cache(struct btrfs_trans_handle *trans,static bool reloc_root_is_dead (struct btrfs_root *root) { +bool is_dead =test_bit (BTRFS_ROOT_DEAD_RELOC_TREE , &root->state);/* * Pair with set_bit/clear_bit in clean_dirty_subvols and * btrfs_update_reloc_root. We need to see the updated bit before * trying to access reloc_root */ smp_rmb (); -if (test_bit (BTRFS_ROOT_DEAD_RELOC_TREE , &root->state)) -return true; -return false; +return is_dead; }/*
Signature · 1 line
2.17.1
Quoted 10 lines · Baptiste Lepers
Fix a misplaced barrier in
reloc_root_is_dead. TheBTRFS_ROOT_DEAD_RELOC_TREEbit should be checked before accessingreloc_root.The fix forces the order documented in the original commit:
"In the cross section C-D, either caller gets the DEAD bit set, avoiding accessreloc_rootno matter if it's safe or not. Or caller get the DEAD bit cleared, then accessreloc_root, which is already NULL, nothing will be wrong."
Quoted 6 lines
static bool
reloc_root_is_dead()smp_rmb(); <--- misplaced if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state)) return true; return false; }
Exactly what I originally purposed to David, we didn't reach an agreement on where the barrier should be.
At least I'm completely fine with this patch.
Thanks,
Qu
Quoted 40 lines
static bool
have_reloc_root(struct btrfs_root *root){ if (reloc_root_is_dead(root)) return false; <--- the barrier should happen here if (!root->reloc_root) return false; return true; }Fixes 6282675e6708e ("btrfs: relocation: fix reloc_root lifespan and access")Signed-off-by Baptiste Lepers <[email protected]>--- fs/btrfs/relocation.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fs/btrfs/relocation.c +2
-3@@ -289,15 +289,14 @@ static int update_backref_cache(struct btrfs_trans_handle *trans,static bool reloc_root_is_dead (struct btrfs_root *root) { +bool is_dead =test_bit (BTRFS_ROOT_DEAD_RELOC_TREE , &root->state);/* * Pair with set_bit/clear_bit in clean_dirty_subvols and * btrfs_update_reloc_root. We need to see the updated bit before * trying to access reloc_root */ smp_rmb (); -if (test_bit (BTRFS_ROOT_DEAD_RELOC_TREE , &root->state)) -return true; -return false; +return is_dead; }/*