The "min_t(unsigned int" macro truncates both arguments to unsigned int. So, if we are running discard on a very big device with 2^32 or more sectors, the truncation may produce zero, resulting in infinite loop. This patch fixes the infinite loop in the lvm test lvcreate-large-raid.sh BTW. the patch 744889b7cbb56a64f957e65ade7cb65fe3f35714 that was committed between v4.19-rc8 and v4.19 also breaks discard by truncating sector_t to unsigned int (but it won't result in an infinite loop, it will result in an error instead). Should it be pulled out from the 4.19 long term branch? Or should we backport all the subsequent patches on the top of it? Signed-off-by: Mikulas Patocka <mpatocka@xxxxxxxxxx> Reported-by: Zdenek Kabelac <zkabelac@xxxxxxxxxx> Fixes: ba5d73851e71 ("block: cleanup __blkdev_issue_discard()") Fixes: 744889b7cbb5 ("block: don't deal with discard limit in blkdev_issue_discard()") Cc: stable@xxxxxxxxxxxxxxx # v4.19 --- block/blk-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Index: linux-2.6/block/blk-lib.c =================================================================== --- linux-2.6.orig/block/blk-lib.c 2018-11-14 18:25:28.000000000 +0100 +++ linux-2.6/block/blk-lib.c 2018-11-14 18:33:04.000000000 +0100 @@ -55,7 +55,7 @@ int __blkdev_issue_discard(struct block_ return -EINVAL; while (nr_sects) { - unsigned int req_sects = min_t(unsigned int, nr_sects, + unsigned int req_sects = min_t(sector_t, nr_sects, bio_allowed_max_sectors(q)); bio = blk_next_bio(bio, 0, gfp_mask); -- dm-devel mailing list dm-devel@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/dm-devel