linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: storvsc: Cap scsi_driver.can_queue to fix a hang issue during boot
@ 2021-10-06  7:03 Dexuan Cui
  2021-10-06  7:17 ` Greg KH
  2021-10-06  8:17 ` John Garry
  0 siblings, 2 replies; 8+ messages in thread
From: Dexuan Cui @ 2021-10-06  7:03 UTC (permalink / raw)
  To: kys, sthemmin, wei.liu, jejb, martin.petersen, haiyangz,
	ming.lei, bvanassche, john.garry, linux-scsi, linux-hyperv
  Cc: linux-kernel, Dexuan Cui, stable

After commit ea2f0f77538c, a 416-CPU VM running on Hyper-V hangs during
boot because scsi_add_host_with_dma() sets shost->cmd_per_lun to a
negative number:
	'max_outstanding_req_per_channel' is 352,
	'max_sub_channels' is (416 - 1) / 4 = 103, so in storvsc_probe(),
scsi_driver.can_queue = 352 * (103 + 1) * (100 - 10) / 100 = 32947, which
is bigger than SHRT_MAX (i.e. 32767).

Fix the hang issue by capping scsi_driver.can_queue.

Add the below Fixed tag though ea2f0f77538c itself is good.

Fixes: ea2f0f77538c ("scsi: core: Cap scsi_host cmd_per_lun at can_queue")
Cc: stable@vger.kernel.org
Signed-off-by: Dexuan Cui <decui@microsoft.com>
---
 drivers/scsi/storvsc_drv.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index ebbbc1299c62..ba374908aec2 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1976,6 +1976,16 @@ static int storvsc_probe(struct hv_device *device,
 				(max_sub_channels + 1) *
 				(100 - ring_avail_percent_lowater) / 100;
 
+	/*
+	 * v5.14 (see commit ea2f0f77538c) implicitly requires that
+	 * scsi_driver.can_queue should not exceed SHRT_MAX, otherwise
+	 * scsi_add_host_with_dma() sets shost->cmd_per_lun to a negative
+	 * number (note: the type of the "cmd_per_lun" field is "short"), and
+	 * the system may hang during early boot.
+	 */
+	if (scsi_driver.can_queue > SHRT_MAX)
+		scsi_driver.can_queue = SHRT_MAX;
+
 	host = scsi_host_alloc(&scsi_driver,
 			       sizeof(struct hv_host_device));
 	if (!host)
-- 
2.17.1


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

end of thread, other threads:[~2021-10-06 17:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06  7:03 [PATCH] scsi: storvsc: Cap scsi_driver.can_queue to fix a hang issue during boot Dexuan Cui
2021-10-06  7:17 ` Greg KH
2021-10-06  8:17 ` John Garry
2021-10-06 15:01   ` Michael Kelley
2021-10-06 16:03     ` John Garry
2021-10-06 16:08       ` Michael Kelley
2021-10-06 16:24         ` John Garry
2021-10-06 17:28       ` Dexuan Cui

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