[PATCH] libata: configure max sectors properly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Xiang Chen <chenxiang66@xxxxxxxxxxxxx>

Max sectors of limitations for scsi host can be set through
scsi_host_template->max_sectors in scsi driver. But we find that max
sectors may exceed scsi_host_template->max_sectors for SATA disk even
if we set it. We find that it may be overwrote in some scsi drivers
(which calls the callback slave_configure and also calls function
ata_scsi_dev_config in it). The invoking relationship is as follows:

scsi_probe_and_add_lun
    ...
    scsi_alloc_sdev
	scsi_mq_alloc_queue
	    ...
	    __scsi_init_queue
		blk_queue_max_hw_sectors(q, shost->max_sectors) //max_sectors coming from sht->max_sectors
	    scsi_change_queue_depth
	    scsi_sysfs_device_initialize
	    shost->hostt->slave_alloc()
		xxx_salve_configure
		    ...
		    ata_scsi_dev_config
			blk_queue_max_hw_sectors(q, dev->max_sectors) //max_sectors is overwrote by dev->max_sectors

To avoid the issue, set q->limits.max_sectors with the minimum value between
dev->max_sectors and q->limits.max_sectors.

Signed-off-by: Xiang Chen <chenxiang66@xxxxxxxxxxxxx>
---
 drivers/ata/libata-scsi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 48b8934..fb7b243 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1026,12 +1026,15 @@ EXPORT_SYMBOL_GPL(ata_scsi_dma_need_drain);
 int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev)
 {
 	struct request_queue *q = sdev->request_queue;
+	unsigned int max_sectors;
 
 	if (!ata_id_has_unload(dev->id))
 		dev->flags |= ATA_DFLAG_NO_UNLOAD;
 
 	/* configure max sectors */
-	blk_queue_max_hw_sectors(q, dev->max_sectors);
+	max_sectors = min_t(unsigned int, dev->max_sectors,
+			q->limits.max_sectors);
+	blk_queue_max_hw_sectors(q, max_sectors);
 
 	if (dev->class == ATA_DEV_ATAPI) {
 		sdev->sector_size = ATA_SECT_SIZE;
-- 
2.8.1




[Index of Archives]     [Linux Filesystems]     [Linux SCSI]     [Linux RAID]     [Git]     [Kernel Newbies]     [Linux Newbie]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Samba]     [Device Mapper]

  Powered by Linux