1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/drivers/md/persistent-data
Ming-Hung Tsai 0bb1968da2 dm array: fix cursor index when skipping across block boundaries
dm_array_cursor_skip() seeks to the target position by loading array
blocks iteratively until the specified number of entries to skip is
reached. When seeking across block boundaries, it uses
dm_array_cursor_next() to step into the next block.
dm_array_cursor_skip() must first move the cursor index to the end
of the current block; otherwise, the cursor position could incorrectly
remain in the same block, causing the actual number of skipped entries
to be much smaller than expected.

This bug affects cache resizing in v2 metadata and could lead to data
loss if the fast device is shrunk during the first-time resume. For
example:

1. create a cache metadata consists of 32768 blocks, with a dirty block
   assigned to the second bitmap block. cache_restore v1.0 is required.

cat <<EOF >> cmeta.xml
<superblock uuid="" block_size="64" nr_cache_blocks="32768" \
policy="smq" hint_width="4">
  <mappings>
    <mapping cache_block="32767" origin_block="0" dirty="true"/>
  </mappings>
</superblock>
EOF
dmsetup create cmeta --table "0 8192 linear /dev/sdc 0"
cache_restore -i cmeta.xml -o /dev/mapper/cmeta --metadata-version=2

2. bring up the cache while attempt to discard all the blocks belonging
   to the second bitmap block (block# 32576 to 32767). The last command
   is expected to fail, but it actually succeeds.

dmsetup create cdata --table "0 2084864 linear /dev/sdc 8192"
dmsetup create corig --table "0 65536 linear /dev/sdc 2105344"
dmsetup create cache --table "0 65536 cache /dev/mapper/cmeta \
/dev/mapper/cdata /dev/mapper/corig 64 2 metadata2 writeback smq \
2 migration_threshold 0"

In addition to the reproducer described above, this fix can be
verified using the "array_cursor/skip" tests in dm-unit:
  dm-unit run /pdata/array_cursor/skip/ --kernel-dir <KERNEL_DIR>

Signed-off-by: Ming-Hung Tsai <mtsai@redhat.com>
Fixes: 9b696229aa ("dm persistent data: add cursor skip functions to the cursor APIs")
Reviewed-by: Joe Thornber <thornber@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
2024-12-13 08:39:18 -05:00
..
dm-array.c dm array: fix cursor index when skipping across block boundaries 2024-12-13 08:39:18 -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: Constify struct dm_block_validator 2024-07-19 12:08:15 +02:00
dm-block-manager.h dm: Constify struct dm_block_validator 2024-07-19 12:08:15 +02:00
dm-btree-internal.h dm: Constify struct dm_block_validator 2024-07-19 12:08:15 +02:00
dm-btree-remove.c dm: add missing empty lines 2023-02-14 14:23:06 -05:00
dm-btree-spine.c dm: Constify struct dm_block_validator 2024-07-19 12:08:15 +02: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: Fix typo in error message 2024-11-20 11:38:04 +01: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 persistent data: fix memory allocation failure 2024-08-13 21:14:21 +02: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: Constify struct dm_block_validator 2024-07-19 12:08:15 +02:00
dm-transaction-manager.h dm: Constify struct dm_block_validator 2024-07-19 12:08:15 +02: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