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

dm: fix bio splitting and its bio completion order for regular IO

dm_queue_split() is removed because __split_and_process_bio() _must_
handle splitting bios to ensure proper bio submission and completion
ordering as a bio is split.

Otherwise, multiple recursive calls to ->submit_bio will cause multiple
split bios to be allocated from the same ->bio_split mempool at the same
time. This would result in deadlock in low memory conditions because no
progress could be made (only one bio is available in ->bio_split
mempool).

This fix has been verified to still fix the loss of performance, due
to excess splitting, that commit 120c9257f5f1 provided.

Fixes: 120c9257f5f1 ("Revert "dm: always call blk_queue_split() in dm_process_bio()"")
Cc: stable@vger.kernel.org # 5.0+, requires custom backport due to 5.9 changes
Reported-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

+2 -21
+2 -21
drivers/md/dm.c
··· 1724 1724 return ret; 1725 1725 } 1726 1726 1727 - static void dm_queue_split(struct mapped_device *md, struct dm_target *ti, struct bio **bio) 1728 - { 1729 - unsigned len, sector_count; 1730 - 1731 - sector_count = bio_sectors(*bio); 1732 - len = min_t(sector_t, max_io_len((*bio)->bi_iter.bi_sector, ti), sector_count); 1733 - 1734 - if (sector_count > len) { 1735 - struct bio *split = bio_split(*bio, len, GFP_NOIO, &md->queue->bio_split); 1736 - 1737 - bio_chain(split, *bio); 1738 - trace_block_split(md->queue, split, (*bio)->bi_iter.bi_sector); 1739 - submit_bio_noacct(*bio); 1740 - *bio = split; 1741 - } 1742 - } 1743 - 1744 1727 static blk_qc_t dm_process_bio(struct mapped_device *md, 1745 1728 struct dm_table *map, struct bio *bio) 1746 1729 { ··· 1751 1768 if (current->bio_list) { 1752 1769 if (is_abnormal_io(bio)) 1753 1770 blk_queue_split(&bio); 1754 - else 1755 - dm_queue_split(md, ti, &bio); 1771 + /* regular IO is split by __split_and_process_bio */ 1756 1772 } 1757 1773 1758 1774 if (dm_get_md_type(md) == DM_TYPE_NVME_BIO_BASED) 1759 1775 return __process_bio(md, map, bio, ti); 1760 - else 1761 - return __split_and_process_bio(md, map, bio); 1776 + return __split_and_process_bio(md, map, bio); 1762 1777 } 1763 1778 1764 1779 static blk_qc_t dm_submit_bio(struct bio *bio)