scsi: core: take the DMA max mapping size into account
authorChristoph Hellwig <hch@lst.de>
Mon, 17 Jun 2019 12:19:54 +0000 (14:19 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 17 Jul 2019 03:01:49 +0000 (23:01 -0400)
We need to limit the device's max_sectors to what the DMA mapping
implementation can support.  If not, we risk running out of swiotlb
buffers easily.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/scsi_lib.c

index 404e5e2..699623f 100644 (file)
@@ -1784,6 +1784,8 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q)
                blk_queue_max_integrity_segments(q, shost->sg_prot_tablesize);
        }
 
+       shost->max_sectors = min_t(unsigned int, shost->max_sectors,
+                       dma_max_mapping_size(dev) << SECTOR_SHIFT);
        blk_queue_max_hw_sectors(q, shost->max_sectors);
        if (shost->unchecked_isa_dma)
                blk_queue_bounce_limit(q, BLK_BOUNCE_ISA);