Skip to contentSkip to conversation

dm: BUG on REQ_ATOMIC in dm_accept_partial_bio()

PATCH In review Mikulas Patocka 3 participants 3 messages Nov 5, 2025 – Nov 10, 2025 Device mapper

lore
Share & tools
lore

Mikulas Patocka

author maintainer
#0 lore raw

PATCH 1/2 dm: BUG on REQ_ATOMIC in dm_accept_partial_bio()

Any bio with REQ_ATOMIC flag set should never be split or partially completed, so BUG_ON() on this scenario in dm_accept_partial_bio() (whose intent is to allow partial completions).

Also, we must reject atomic bio to targets that don't support them, otherwise this BUG could could be triggered by stray bios that have the REQ_ATOMIC set.

---
 drivers/md/dm.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/md/dm.c +7 -2
Index: linux-2.6/drivers/md/dm.c
===================================================================
@@ -1321,6 +1321,7 @@ void dm_accept_partial_bio(struct bio *b
 	BUG_ON(dm_tio_flagged(tio, DM_TIO_IS_DUPLICATE_BIO));
 	BUG_ON(bio_sectors > *tio->len_ptr);
 	BUG_ON(n_sectors > bio_sectors);
+	BUG_ON(bio->bi_opf & REQ_ATOMIC);
 
 	if (static_branch_unlikely(&zoned_enabled) &&
 	    unlikely(bdev_is_zoned(bio->bi_bdev))) {
@@ -1735,8 +1736,12 @@ static blk_status_t __split_and_process_
 	ci->submit_as_polled = !!(ci->bio->bi_opf & REQ_POLLED);
 
 	len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count);
-	if (ci->bio->bi_opf & REQ_ATOMIC && len != ci->sector_count)
-		return BLK_STS_IOERR;
+	if (ci->bio->bi_opf & REQ_ATOMIC) {
+		if (unlikely(!dm_target_supports_atomic_writes(ti->type)))
+			return BLK_STS_IOERR;
+		if (unlikely(len != ci->sector_count))
+			return BLK_STS_IOERR;
+	}
 
 	setup_split_accounting(ci, len);
 
#1 lore raw
Quoted 6 lines · Mikulas Patocka

Any bio with REQ_ATOMIC flag set should never be split or partially completed, so BUG_ON() on this scenario in dm_accept_partial_bio() (whose intent is to allow partial completions).

Also, we must reject atomic bio to targets that don't support them, otherwise this BUG could could be triggered by stray bios that have the

double could.

Yongpeng,

Quoted 37 lines

REQ_ATOMIC set.

---
  drivers/md/dm.c |    9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)

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

drivers/md/dm.c +7 -2
@@ -1321,6 +1321,7 @@ void dm_accept_partial_bio(struct bio *b
  	BUG_ON(dm_tio_flagged(tio, DM_TIO_IS_DUPLICATE_BIO));
  	BUG_ON(bio_sectors > *tio->len_ptr);
  	BUG_ON(n_sectors > bio_sectors);
+	BUG_ON(bio->bi_opf & REQ_ATOMIC);
 
  	if (static_branch_unlikely(&zoned_enabled) &&
  	    unlikely(bdev_is_zoned(bio->bi_bdev))) {
@@ -1735,8 +1736,12 @@ static blk_status_t __split_and_process_
  	ci->submit_as_polled = !!(ci->bio->bi_opf & REQ_POLLED);
 
  	len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count);
-	if (ci->bio->bi_opf & REQ_ATOMIC && len != ci->sector_count)
-		return BLK_STS_IOERR;
+	if (ci->bio->bi_opf & REQ_ATOMIC) {
+		if (unlikely(!dm_target_supports_atomic_writes(ti->type)))
+			return BLK_STS_IOERR;
+		if (unlikely(len != ci->sector_count))
+			return BLK_STS_IOERR;
+	}
 
  	setup_split_accounting(ci, len);
 
Tested-by on v1 1/2
#2 lore raw
In reply to Mikulas Patocka
Quoted 10 lines · Mikulas Patocka

Any bio with REQ_ATOMIC flag set should never be split or partially completed, so BUG_ON() on this scenario in dm_accept_partial_bio() (whose intent is to allow partial completions).

Also, we must reject atomic bio to targets that don't support them, otherwise this BUG could could be triggered by stray bios that have the REQ_ATOMIC set.

Thanks!