Skip to contentSkip to conversation

scsi: storvsc: Fix calculation of sub-channel count

PATCH Applied Michael Kelley 3 participants 3 messages Apr 1, 2019 – Apr 4, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi: storvsc: Fix calculation of sub-channel count

When the number of sub-channels offered by Hyper-V is >= the number of CPUs in the VM, calculate the correct number of sub-channels. The current code produces one too many.

This scenario arises only when the number of CPUs is artificially restricted (for example, with maxcpus=<n> on the kernel boot line), because Hyper-V normally offers a sub-channel count < number of CPUs. While the current code doesn't break, the extra sub-channel is unbalanced across the CPUs (for example, a total of 5 channels on a VM with 4 CPUs).

---
Changes in v2:
* Put num_online_cpus() inline and eliminate num_cpus local variable [Vitaly Kuznetsov]

---
 drivers/scsi/storvsc_drv.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/scsi/storvsc_drv.c +11 -2
index 84380ba..e186743 100644
@@ -668,13 +668,22 @@ static void  handle_multichannel_storage(struct hv_device *device, int max_chns)
 {
 	struct device *dev = &device->device;
 	struct storvsc_device *stor_device;
-	int num_cpus = num_online_cpus();
 	int num_sc;
 	struct storvsc_cmd_request *request;
 	struct vstor_packet *vstor_packet;
 	int ret, t;
 
-	num_sc = ((max_chns > num_cpus) ? num_cpus : max_chns);
+	/*
+	 * If the number of CPUs is artificially restricted, such as
+	 * with maxcpus=1 on the kernel boot line, Hyper-V could offer
+	 * sub-channels >= the number of CPUs. These sub-channels
+	 * should not be created. The primary channel is already created
+	 * and assigned to one CPU, so check against # CPUs - 1.
+	 */
+	num_sc = min((int)(num_online_cpus() - 1), max_chns);
+	if (!num_sc)
+		return;
+
 	stor_device = get_out_stor_device(device);
 	if (!stor_device)
 		return;
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

-----Original Message-----
From: Michael Kelley <[email protected]>
Sent: Monday, April 1, 2019 9:11 AM
To: KY Srinivasan <[email protected]>; [email protected]; Long Li <[email protected]>; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: Michael Kelley <[email protected]>
Subject: [PATCH v2 1/1] scsi: storvsc: Fix calculation of sub-channel count

When the number of sub-channels offered by Hyper-V is >= the number of CPUs in the VM, calculate the correct number of sub-channels. The current code produces one too many.

This scenario arises only when the number of CPUs is artificially restricted (for example, with maxcpus=<n> on the kernel boot line), because Hyper-V normally offers a sub-channel count < number of CPUs.
While the current code doesn't break, the extra sub-channel is unbalanced across the CPUs (for example, a total of 5 channels on a VM with 4 CPUs).

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

---
Changes in v2:
* Put num_online_cpus() inline and eliminate num_cpus local variable [Vitaly Kuznetsov]

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines

---
drivers/scsi/storvsc_drv.c | 13 +++++++++++--

1 file changed, 11 insertions(+), 2 deletions(-)
drivers/scsi/storvsc_drv.c index renamed from drivers/scsi/storvsc_drv.c +0 -0

84380ba..e186743 100644

drivers/scsi/storvsc_drv.c +11 -3
@@ -668,13 +668,22 @@ static void  handle_multichannel_storage(struct
 hv_device *device, int max_chns)  {
 	struct device *dev = &device->device;
 	struct storvsc_device *stor_device;
-	int num_cpus = num_online_cpus();
 	int num_sc;
 	struct storvsc_cmd_request *request;
 	struct vstor_packet *vstor_packet;
 	int ret, t;
 
-	num_sc = ((max_chns > num_cpus) ? num_cpus : max_chns);
+	/*
+	 * If the number of CPUs is artificially restricted, such as
+	 * with maxcpus=1 on the kernel boot line, Hyper-V could offer
+	 * sub-channels >= the number of CPUs. These sub-channels
+	 * should not be created. The primary channel is already created
+	 * and assigned to one CPU, so check against # CPUs - 1.
+	 */
+	num_sc = min((int)(num_online_cpus() - 1), max_chns);
+	if (!num_sc)
+		return;
+
 	stor_device = get_out_stor_device(device);
 	if (!stor_device)
 		return;
--

1.8.3.1

#2 lore raw
In reply to Michael Kelley

Michael,

Quoted 3 lines

When the number of sub-channels offered by Hyper-V is >= the number of CPUs in the VM, calculate the correct number of sub-channels. The current code produces one too many.

Applied to 5.1/scsi-fixes, thanks.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering