linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libata: configure max sectors properly
@ 2021-05-26  1:34 chenxiang
  2021-05-26  2:48 ` Martin K. Petersen
  2021-05-31 14:19 ` [libata] 2c76f9f255: stress-ng.copy-file.ops_per_sec -25.9% regression kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: chenxiang @ 2021-05-26  1:34 UTC (permalink / raw)
  To: axboe, tj, martin.petersen
  Cc: linux-ide, linux-scsi, linuxarm, linuxarm, Xiang Chen

From: Xiang Chen <chenxiang66@hisilicon.com>

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@hisilicon.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-31 14:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-26  1:34 [PATCH] libata: configure max sectors properly chenxiang
2021-05-26  2:48 ` Martin K. Petersen
2021-05-31 14:19 ` [libata] 2c76f9f255: stress-ng.copy-file.ops_per_sec -25.9% regression kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).