• Filipe Manana's avatar
    btrfs: avoid races when tracking progress for extent map shrinking · 44849405
    Filipe Manana authored
    We store the progress (root and inode numbers) of the extent map shrinker
    in fs_info without any synchronization but we can have multiple tasks
    calling into the shrinker during memory allocations when there's enough
    memory pressure for example.
    
    This can result in a task A reading fs_info->extent_map_shrinker_last_ino
    after another task B updates it, and task A reading
    fs_info->extent_map_shrinker_last_root before task B updates it, making
    task A see an odd state that isn't necessarily harmful but may make it
    skip certain inode ranges or do more work than necessary by going over
    the same inodes again. These unprotected accesses would also trigger
    warnings from tools like KCSAN.
    
    So add a lock to protect access to these progress fields.
    Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    44849405
disk-io.c 139 KB