Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm: test for 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 be triggered by stray bios that have the
REQ_ATOMIC set.

Signed-off-by: John Garry <john.g.garry@oracle.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: John Garry <john.g.garry@oracle.com>

+7 -2
+7 -2
drivers/md/dm.c
··· 1321 1321 BUG_ON(dm_tio_flagged(tio, DM_TIO_IS_DUPLICATE_BIO)); 1322 1322 BUG_ON(bio_sectors > *tio->len_ptr); 1323 1323 BUG_ON(n_sectors > bio_sectors); 1324 + BUG_ON(bio->bi_opf & REQ_ATOMIC); 1324 1325 1325 1326 if (static_branch_unlikely(&zoned_enabled) && 1326 1327 unlikely(bdev_is_zoned(bio->bi_bdev))) { ··· 1736 1735 ci->submit_as_polled = !!(ci->bio->bi_opf & REQ_POLLED); 1737 1736 1738 1737 len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count); 1739 - if (ci->bio->bi_opf & REQ_ATOMIC && len != ci->sector_count) 1740 - return BLK_STS_IOERR; 1738 + if (ci->bio->bi_opf & REQ_ATOMIC) { 1739 + if (unlikely(!dm_target_supports_atomic_writes(ti->type))) 1740 + return BLK_STS_IOERR; 1741 + if (unlikely(len != ci->sector_count)) 1742 + return BLK_STS_IOERR; 1743 + } 1741 1744 1742 1745 setup_split_accounting(ci, len); 1743 1746