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

sd: Limit transfer length

Until now the per-command transfer length has exclusively been gated by
the max_sectors parameter in the scsi_host template. Given that the size
of this parameter has been bumped to an unsigned int we have to be
careful not to exceed the target device's capabilities.

If the if the device specifies a Maximum Transfer Length in the Block
Limits VPD we'll use that value. Otherwise we'll use 0xffffffff for
devices that have use_16_for_rw set and 0xffff for the rest. We then
combine the chosen disk limit with max_sectors in the host template. The
smaller of the two will be used to set the max_hw_sectors queue limit.

Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Ewan D. Milne <emilne@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>

authored by

Martin K. Petersen and committed by
Christoph Hellwig
bcdb247c 8d964478

+18 -1
+15 -1
drivers/scsi/sd.c
··· 2236 2236 } 2237 2237 } 2238 2238 2239 - sdp->use_16_for_rw = (sdkp->capacity > 0xffffffff); 2239 + if (sdkp->capacity > 0xffffffff) { 2240 + sdp->use_16_for_rw = 1; 2241 + sdkp->max_xfer_blocks = SD_MAX_XFER_BLOCKS; 2242 + } else 2243 + sdkp->max_xfer_blocks = SD_DEF_XFER_BLOCKS; 2240 2244 2241 2245 /* Rescale capacity to 512-byte units */ 2242 2246 if (sector_size == 4096) ··· 2555 2551 { 2556 2552 unsigned int sector_sz = sdkp->device->sector_size; 2557 2553 const int vpd_len = 64; 2554 + u32 max_xfer_length; 2558 2555 unsigned char *buffer = kmalloc(vpd_len, GFP_KERNEL); 2559 2556 2560 2557 if (!buffer || 2561 2558 /* Block Limits VPD */ 2562 2559 scsi_get_vpd_page(sdkp->device, 0xb0, buffer, vpd_len)) 2563 2560 goto out; 2561 + 2562 + max_xfer_length = get_unaligned_be32(&buffer[8]); 2563 + if (max_xfer_length) 2564 + sdkp->max_xfer_blocks = max_xfer_length; 2564 2565 2565 2566 blk_queue_io_min(sdkp->disk->queue, 2566 2567 get_unaligned_be16(&buffer[6]) * sector_sz); ··· 2721 2712 struct scsi_disk *sdkp = scsi_disk(disk); 2722 2713 struct scsi_device *sdp = sdkp->device; 2723 2714 unsigned char *buffer; 2715 + unsigned int max_xfer; 2724 2716 2725 2717 SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, 2726 2718 "sd_revalidate_disk\n")); ··· 2769 2759 */ 2770 2760 sd_set_flush_flag(sdkp); 2771 2761 2762 + max_xfer = min_not_zero(queue_max_hw_sectors(sdkp->disk->queue), 2763 + sdkp->max_xfer_blocks); 2764 + max_xfer <<= ilog2(sdp->sector_size) - 9; 2765 + blk_queue_max_hw_sectors(sdkp->disk->queue, max_xfer); 2772 2766 set_capacity(disk, sdkp->capacity); 2773 2767 sd_config_write_same(sdkp); 2774 2768 kfree(buffer);
+3
drivers/scsi/sd.h
··· 44 44 }; 45 45 46 46 enum { 47 + SD_DEF_XFER_BLOCKS = 0xffff, 48 + SD_MAX_XFER_BLOCKS = 0xffffffff, 47 49 SD_MAX_WS10_BLOCKS = 0xffff, 48 50 SD_MAX_WS16_BLOCKS = 0x7fffff, 49 51 }; ··· 66 64 struct gendisk *disk; 67 65 atomic_t openers; 68 66 sector_t capacity; /* size in 512-byte sectors */ 67 + u32 max_xfer_blocks; 69 68 u32 max_ws_blocks; 70 69 u32 max_unmap_blocks; 71 70 u32 unmap_granularity;