linux/drivers/md/persistent-data
Li Lingfeng d483001206 dm thin metadata: Fix ABBA deadlock by resetting dm_bufio_client
As described in commit 8111964f1b ("dm thin: Fix ABBA deadlock between
shrink_slab and dm_pool_abort_metadata"), ABBA deadlocks will be
triggered because shrinker_rwsem currently needs to held by
dm_pool_abort_metadata() as a side-effect of thin-pool metadata
operation failure.

The following three problem scenarios have been noticed:

1) Described by commit 8111964f1b ("dm thin: Fix ABBA deadlock between
   shrink_slab and dm_pool_abort_metadata")

2) shrinker_rwsem and throttle->lock
          P1(drop cache)                        P2(kworker)
drop_caches_sysctl_handler
 drop_slab
  shrink_slab
   down_read(&shrinker_rwsem)  - LOCK A
   do_shrink_slab
    super_cache_scan
     prune_icache_sb
      dispose_list
       evict
        ext4_evict_inode
         ext4_clear_inode
          ext4_discard_preallocations
           ext4_mb_load_buddy_gfp
            ext4_mb_init_cache
             ext4_wait_block_bitmap
              __ext4_error
               ext4_handle_error
                ext4_commit_super
                 ...
                 dm_submit_bio
                                     do_worker
                                      throttle_work_update
                                       down_write(&t->lock) -- LOCK B
                                      process_deferred_bios
                                       commit
                                        metadata_operation_failed
                                         dm_pool_abort_metadata
                                          dm_block_manager_create
                                           dm_bufio_client_create
                                            register_shrinker
                                             down_write(&shrinker_rwsem)
                                             -- LOCK A
                 thin_map
                  thin_bio_map
                   thin_defer_bio_with_throttle
                    throttle_lock
                     down_read(&t->lock)  - LOCK B

3) shrinker_rwsem and wait_on_buffer
          P1(drop cache)                            P2(kworker)
drop_caches_sysctl_handler
 drop_slab
  shrink_slab
   down_read(&shrinker_rwsem)  - LOCK A
   do_shrink_slab
   ...
    ext4_wait_block_bitmap
     __ext4_error
      ext4_handle_error
       jbd2_journal_abort
        jbd2_journal_update_sb_errno
         jbd2_write_superblock
          submit_bh
           // LOCK B
           // RELEASE B
                             do_worker
                              throttle_work_update
                               down_write(&t->lock) - LOCK B
                              process_deferred_bios
                               process_bio
                               commit
                                metadata_operation_failed
                                 dm_pool_abort_metadata
                                  dm_block_manager_create
                                   dm_bufio_client_create
                                    register_shrinker
                                     register_shrinker_prepared
                                      down_write(&shrinker_rwsem)  - LOCK A
                               bio_endio
      wait_on_buffer
       __wait_on_buffer

Fix these by resetting dm_bufio_client without holding shrinker_rwsem.

Fixes: 8111964f1b ("dm thin: Fix ABBA deadlock between shrink_slab and dm_pool_abort_metadata")
Cc: stable@vger.kernel.org
Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
2023-06-16 18:24:13 -04:00
..
dm-array.c dm: add missing blank line after declarations/fix those 2023-02-14 14:23:07 -05:00
dm-array.h dm: change "unsigned" to "unsigned int" 2023-02-14 14:23:06 -05:00
dm-bitset.c dm: add missing empty lines 2023-02-14 14:23:06 -05:00
dm-bitset.h dm: add missing SPDX-License-Indentifiers 2023-02-14 14:23:06 -05:00
dm-block-manager.c dm thin metadata: Fix ABBA deadlock by resetting dm_bufio_client 2023-06-16 18:24:13 -04:00
dm-block-manager.h dm thin metadata: Fix ABBA deadlock by resetting dm_bufio_client 2023-06-16 18:24:13 -04:00
dm-btree-internal.h dm: favour __packed versus "__attribute__ ((packed))" 2023-02-14 14:23:07 -05:00
dm-btree-remove.c dm: add missing empty lines 2023-02-14 14:23:06 -05:00
dm-btree-spine.c dm: prefer '"%s...", __func__' 2023-02-14 14:23:07 -05:00
dm-btree.c dm: add missing blank line after declarations/fix those 2023-02-14 14:23:07 -05:00
dm-btree.h dm: add missing blank line after declarations/fix those 2023-02-14 14:23:07 -05:00
dm-persistent-data-internal.h dm: change "unsigned" to "unsigned int" 2023-02-14 14:23:06 -05:00
dm-space-map-common.c dm: avoid useless 'else' after 'break' or return' 2023-02-14 14:23:07 -05:00
dm-space-map-common.h dm: favour __packed versus "__attribute__ ((packed))" 2023-02-14 14:23:07 -05:00
dm-space-map-disk.c dm: remove unnecessary braces from single statement blocks 2023-02-14 14:23:06 -05:00
dm-space-map-disk.h dm: add missing SPDX-License-Indentifiers 2023-02-14 14:23:06 -05:00
dm-space-map-metadata.c dm: add missing empty lines 2023-02-14 14:23:06 -05:00
dm-space-map-metadata.h dm: add missing SPDX-License-Indentifiers 2023-02-14 14:23:06 -05:00
dm-space-map.h dm thin metadata: Fix ABBA deadlock by resetting dm_bufio_client 2023-06-16 18:24:13 -04:00
dm-transaction-manager.c dm thin metadata: Fix ABBA deadlock by resetting dm_bufio_client 2023-06-16 18:24:13 -04:00
dm-transaction-manager.h dm: change "unsigned" to "unsigned int" 2023-02-14 14:23:06 -05:00
Kconfig treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00