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

scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map()

In commit edb854a3680b ("scsi: core: Reallocate device's budget map on
queue depth change"), the sbitmap for the device budget map may be
reallocated after the slave device depth is configured.

When the sbitmap is reallocated we use the result from
scsi_device_max_queue_depth() for the sbitmap size, but don't resize to
match the actual device queue depth.

Fix by resizing the sbitmap after reallocating the budget sbitmap. We do
this instead of init'ing the sbitmap to the device queue depth as the user
may want to change the queue depth later via sysfs or other.

Link: https://lore.kernel.org/r/1647423870-143867-1-git-send-email-john.garry@huawei.com
Fixes: edb854a3680b ("scsi: core: Reallocate device's budget map on queue depth change")
Tested-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

John Garry and committed by
Martin K. Petersen
eaba83b5 63221571

+5
+5
drivers/scsi/scsi_scan.c
··· 223 223 int ret; 224 224 struct sbitmap sb_backup; 225 225 226 + depth = min_t(unsigned int, depth, scsi_device_max_queue_depth(sdev)); 227 + 226 228 /* 227 229 * realloc if new shift is calculated, which is caused by setting 228 230 * up one new default queue depth after calling ->slave_configure ··· 247 245 scsi_device_max_queue_depth(sdev), 248 246 new_shift, GFP_KERNEL, 249 247 sdev->request_queue->node, false, true); 248 + if (!ret) 249 + sbitmap_resize(&sdev->budget_map, depth); 250 + 250 251 if (need_free) { 251 252 if (ret) 252 253 sdev->budget_map = sb_backup;