Skip to contentSkip to conversation

scsi: storvsc: Fix calculation of sub-channel count

PATCH Superseded Michael Kelley 2 participants 2 messages Mar 31, 2019 – Apr 1, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

---
 drivers/scsi/storvsc_drv.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/scsi/storvsc_drv.c +11 -1
index 84380ba..fbaa11a 100644
@@ -674,7 +674,17 @@ static void  handle_multichannel_storage(struct hv_device *device, int max_chns)
 	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((num_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 v1 1/1
#1 lore raw
Quoted 22 lines · Michael Kelley

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

---
 drivers/scsi/storvsc_drv.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/scsi/storvsc_drv.c +0 -0
index 84380ba..fbaa11a 100644
@@ -674,7 +674,17 @@ static void  handle_multichannel_storage(struct hv_device *device, int max_chns)
 	struct vstor_packet *vstor_packet;

drivers/scsi/storvsc_drv.c static void handle_multichannel_storage(struct hv_device *device, int max_chns) · line 683

Quoted 10 lines
drivers/scsi/storvsc_drv.c +7 -1
 	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.
+	 */

Indeed.

drivers/scsi/storvsc_drv.c static void handle_multichannel_storage(struct hv_device *device, int max_chns) · line 684

Quoted 1 line
drivers/scsi/storvsc_drv.c +1 -0
+	num_sc = min((num_cpus - 1), max_chns);

(nit: you could've written

num_sc = min((num_online_cpus() - 1), max_chns);

and got rid of the now-unneeded num_cpus variable).

Quoted 6 lines
drivers/scsi/storvsc_drv.c +3 -0
+	if (!num_sc)
+		return;
+
 	stor_device = get_out_stor_device(device);
 	if (!stor_device)
 		return;
Signature · 1 line
Vitaly