linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map()
@ 2022-03-16  9:44 John Garry
  2022-03-16 11:38 ` Damien Le Moal
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: John Garry @ 2022-03-16  9:44 UTC (permalink / raw)
  To: jejb, martin.petersen
  Cc: damien.lemoal, linux-kernel, linux-scsi, bvanassche,
	martin.wilck, ming.lei, hch, hare, John Garry

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.

Fixes: edb854a3680b ("scsi: core: Reallocate device's budget map on queue depth change")
Signed-off-by: John Garry <john.garry@huawei.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
---
Changes since v1 (apart from sending as a separate patch):
- Add fixes and RB tag (thanks)
- mention in commit message why we don't init sbitmap at queue depth

diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index f4e6c68ac99e..2ef78083f1ef 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -223,6 +223,8 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
 	int ret;
 	struct sbitmap sb_backup;
 
+	depth = min_t(unsigned int, depth, scsi_device_max_queue_depth(sdev));
+
 	/*
 	 * realloc if new shift is calculated, which is caused by setting
 	 * up one new default queue depth after calling ->slave_configure
@@ -245,6 +247,9 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
 				scsi_device_max_queue_depth(sdev),
 				new_shift, GFP_KERNEL,
 				sdev->request_queue->node, false, true);
+	if (!ret)
+		sbitmap_resize(&sdev->budget_map, depth);
+
 	if (need_free) {
 		if (ret)
 			sdev->budget_map = sb_backup;
-- 
2.26.2


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

* Re: [PATCH v2] scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map()
  2022-03-16  9:44 [PATCH v2] scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map() John Garry
@ 2022-03-16 11:38 ` Damien Le Moal
  2022-03-16 14:29 ` Bart Van Assche
  2022-03-30  3:45 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2022-03-16 11:38 UTC (permalink / raw)
  To: John Garry, jejb, martin.petersen
  Cc: linux-kernel, linux-scsi, bvanassche, martin.wilck, ming.lei, hch, hare

On 3/16/22 18:44, John Garry wrote:
> 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.
> 
> Fixes: edb854a3680b ("scsi: core: Reallocate device's budget map on queue depth change")
> Signed-off-by: John Garry <john.garry@huawei.com>
> Reviewed-by: Ming Lei <ming.lei@redhat.com>
> ---
> Changes since v1 (apart from sending as a separate patch):
> - Add fixes and RB tag (thanks)
> - mention in commit message why we don't init sbitmap at queue depth
> 
> diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
> index f4e6c68ac99e..2ef78083f1ef 100644
> --- a/drivers/scsi/scsi_scan.c
> +++ b/drivers/scsi/scsi_scan.c
> @@ -223,6 +223,8 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
>  	int ret;
>  	struct sbitmap sb_backup;
>  
> +	depth = min_t(unsigned int, depth, scsi_device_max_queue_depth(sdev));
> +
>  	/*
>  	 * realloc if new shift is calculated, which is caused by setting
>  	 * up one new default queue depth after calling ->slave_configure
> @@ -245,6 +247,9 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
>  				scsi_device_max_queue_depth(sdev),
>  				new_shift, GFP_KERNEL,
>  				sdev->request_queue->node, false, true);
> +	if (!ret)
> +		sbitmap_resize(&sdev->budget_map, depth);
> +
>  	if (need_free) {
>  		if (ret)
>  			sdev->budget_map = sb_backup;

Tested-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

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

* Re: [PATCH v2] scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map()
  2022-03-16  9:44 [PATCH v2] scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map() John Garry
  2022-03-16 11:38 ` Damien Le Moal
@ 2022-03-16 14:29 ` Bart Van Assche
  2022-03-30  3:45 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2022-03-16 14:29 UTC (permalink / raw)
  To: John Garry, jejb, martin.petersen
  Cc: damien.lemoal, linux-kernel, linux-scsi, martin.wilck, ming.lei,
	hch, hare

On 3/16/22 02:44, John Garry wrote:
> 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.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

* Re: [PATCH v2] scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map()
  2022-03-16  9:44 [PATCH v2] scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map() John Garry
  2022-03-16 11:38 ` Damien Le Moal
  2022-03-16 14:29 ` Bart Van Assche
@ 2022-03-30  3:45 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-03-30  3:45 UTC (permalink / raw)
  To: John Garry
  Cc: jejb, martin.petersen, damien.lemoal, linux-kernel, linux-scsi,
	bvanassche, martin.wilck, ming.lei, hch, hare


John,

> 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.

Applied to 5.18/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2022-03-30  3:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16  9:44 [PATCH v2] scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map() John Garry
2022-03-16 11:38 ` Damien Le Moal
2022-03-16 14:29 ` Bart Van Assche
2022-03-30  3:45 ` Martin K. Petersen

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).