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

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.

Cc: <stable@vger.kernel.org>
Reported-by: Don Brace <don.brace@microsemi.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Tested-by: Don Brace <don.brace@microsemi.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

+14 -5
+14 -5
drivers/scsi/sd.c
··· 3107 3107 sd_read_security(sdkp, buffer); 3108 3108 } 3109 3109 3110 - sdkp->first_scan = 0; 3111 - 3112 3110 /* 3113 3111 * We now have all cache related info, determine how we deal 3114 3112 * with flush requests. ··· 3121 3123 q->limits.max_dev_sectors = logical_to_sectors(sdp, dev_max); 3122 3124 3123 3125 /* 3124 - * Use the device's preferred I/O size for reads and writes 3126 + * Determine the device's preferred I/O size for reads and writes 3125 3127 * unless the reported value is unreasonably small, large, or 3126 3128 * garbage. 3127 3129 */ ··· 3135 3137 rw_max = min_not_zero(logical_to_sectors(sdp, dev_max), 3136 3138 (sector_t)BLK_DEF_MAX_SECTORS); 3137 3139 3138 - /* Combine with controller limits */ 3139 - q->limits.max_sectors = min(rw_max, queue_max_hw_sectors(q)); 3140 + /* Do not exceed controller limit */ 3141 + rw_max = min(rw_max, queue_max_hw_sectors(q)); 3142 + 3143 + /* 3144 + * Only update max_sectors if previously unset or if the current value 3145 + * exceeds the capabilities of the hardware. 3146 + */ 3147 + if (sdkp->first_scan || 3148 + q->limits.max_sectors > q->limits.max_dev_sectors || 3149 + q->limits.max_sectors > q->limits.max_hw_sectors) 3150 + q->limits.max_sectors = rw_max; 3151 + 3152 + sdkp->first_scan = 0; 3140 3153 3141 3154 set_capacity(disk, logical_to_sectors(sdp, sdkp->capacity)); 3142 3155 sd_config_write_same(sdkp);