Skip to contentSkip to conversation

dm: fix failure when empty flush's bi_sector points beyond the device end

PATCH In review Mikulas Patocka 2 participants 2 messages Nov 20, 2025 Device mapper

lore
Share & tools
lore

Mikulas Patocka

author maintainer
#0 lore raw

PATCH 1/1 dm: fix failure when empty flush's bi_sector points beyond the device end

An empty flush bio can have arbitrary bi_sector. The commit 2b1c6d7a890a introduced a regression that device mapper would fail an empty flush bio with -EIO if the sector pointed beyond the end of the device.

The commit introduced an optimization, that optimization would pass flushes to __split_and_process_bio and __split_and_process_bio is not prepared to handle empty bios. Fix this bug by passing only non-empty flushes to __split_and_process_bio - non-empty flushes must have valid bi_sector. Empty bios will go through __send_empty_flush, as they did before the optimization.

This problem can be reproduced by running the lvm2 test:
make check_local T=lvconvert-thin.sh LVM_TEST_PREFER_BRD=0

Fixes 2b1c6d7a890a ("dm: optimize REQ_PREFLUSH with data when using the linear target")
---
 drivers/md/dm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm.c +1 -1
Index: linux-2.6/drivers/md/dm.c
===================================================================
@@ -2005,7 +2005,7 @@ static void dm_split_and_process_bio(str
 		 * linear target or multiple linear targets pointing to the same
 		 * device), we can send the flush with data directly to it.
 		 */
-		if (map->flush_bypasses_map) {
+		if (bio->bi_iter.bi_size && map->flush_bypasses_map) {
 			struct list_head *devices = dm_table_get_devices(map);
 			if (devices->next == devices->prev)
 				goto send_preflush_with_data;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Mikulas Patocka

An empty flush bio can have arbitrary bi_sector. The commit 2b1c6d7a890a introduced a regression that device mapper would fail an empty flush bio with -EIO if the sector pointed beyond the end of the device.

The commit introduced an optimization, that optimization would pass flushes to __split_and_process_bio and __split_and_process_bio is not prepared to handle empty bios. Fix this bug by passing only non-empty flushes to __split_and_process_bio - non-empty flushes must have valid bi_sector. Empty bios will go through __send_empty_flush, as they did before the optimization.

This problem can be reproduced by running the lvm2 test:
make check_local T=lvconvert-thin.sh LVM_TEST_PREFER_BRD=0

Fixes 2b1c6d7a890a ("dm: optimize REQ_PREFLUSH with data when using the linear target")
---
  drivers/md/dm.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6/drivers/md/dm.c
===================================================================

drivers/md/dm.c static void dm_split_and_process_bio(str · line 2011

Quoted 8 lines
drivers/md/dm.c +1 -1
@@ -2005,7 +2005,7 @@ static void dm_split_and_process_bio(str
  		 * linear target or multiple linear targets pointing to the same
  		 * device), we can send the flush with data directly to it.
  		 */
-		if (map->flush_bypasses_map) {
+		if (bio->bi_iter.bi_size && map->flush_bypasses_map) {
  			struct list_head *devices = dm_table_get_devices(map);
  			if (devices->next == devices->prev)
  				goto send_preflush_with_data;