From: Martin K. Petersen Date: Thu, 28 Sep 2017 01:38:59 +0000 (-0400) Subject: scsi: sd: Do not override max_sectors_kb sysfs setting X-Git-Tag: v4.1.12-124.31.3~158 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d8344b28f8c6537e8b801f5fc603fde23c0355de;p=users%2Fjedix%2Flinux-maple.git scsi: sd: Do not override max_sectors_kb sysfs setting A user may lower the max_sectors_kb setting in sysfs to accommodate certain workloads. Previously we would always set the max I/O size to either the block layer default or the optional preferred I/O size reported by the device. Keep the current heuristics for the initial setting of max_sectors_kb. For subsequent invocations, only update the current queue limit if it exceeds the capabilities of the hardware. Orabug: 29596510 Cc: Reported-by: Don Brace Reviewed-by: Martin Wilck Tested-by: Don Brace Signed-off-by: Martin K. Petersen (cherry picked from commit 77082ca503bed061f7fbda7cfd7c93beda967a41) Signed-off-by: John Sobecki Tested-by: Dustin Samko Reviewed-by: Ritika Srivastava Signed-off-by: Brian Maly --- diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 9cd46eca3482..37b5accbad25 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2766,8 +2766,6 @@ static int sd_revalidate_disk(struct gendisk *disk) sd_read_write_same(sdkp, buffer); } - sdkp->first_scan = 0; - /* * We now have all cache related info, determine how we deal * with flush requests. @@ -2782,7 +2780,7 @@ static int sd_revalidate_disk(struct gendisk *disk) q->limits.max_dev_sectors = logical_to_sectors(sdp, dev_max); /* - * Use the device's preferred I/O size for reads and writes + * Determine the device's preferred I/O size for reads and writes * unless the reported value is unreasonably small, large, or * garbage. */ @@ -2795,8 +2793,19 @@ static int sd_revalidate_disk(struct gendisk *disk) } else rw_max = BLK_DEF_MAX_SECTORS; - /* Combine with controller limits */ - q->limits.max_sectors = min(rw_max, queue_max_hw_sectors(q)); + /* Do not exceed controller limit */ + rw_max = min(rw_max, queue_max_hw_sectors(q)); + + /* + * Only update max_sectors if previously unset or if the current value + * exceeds the capabilities of the hardware. + */ + if (sdkp->first_scan || + q->limits.max_sectors > q->limits.max_dev_sectors || + q->limits.max_sectors > q->limits.max_hw_sectors) + q->limits.max_sectors = rw_max; + + sdkp->first_scan = 0; set_capacity(disk, logical_to_sectors(sdp, sdkp->capacity)); sd_config_write_same(sdkp);