linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/1] scsi: storvsc: Fix calculation of sub-channel count
@ 2019-04-01 16:10 Michael Kelley
  2019-04-01 21:38 ` Long Li
  2019-04-04  3:30 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Kelley @ 2019-04-01 16:10 UTC (permalink / raw)
  To: KY Srinivasan, martin.petersen, Long Li, James.Bottomley, emilne,
	linux-hyperv, linux-kernel, linux-scsi
  Cc: 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).

Signed-off-by: Michael Kelley <mikelley@microsoft.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
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(-)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 84380ba..e186743 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -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


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

* RE: [PATCH v2 1/1] scsi: storvsc: Fix calculation of sub-channel count
  2019-04-01 16:10 [PATCH v2 1/1] scsi: storvsc: Fix calculation of sub-channel count Michael Kelley
@ 2019-04-01 21:38 ` Long Li
  2019-04-04  3:30 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Long Li @ 2019-04-01 21:38 UTC (permalink / raw)
  To: Michael Kelley, KY Srinivasan, martin.petersen, James.Bottomley,
	emilne, linux-hyperv, linux-kernel, linux-scsi

>>>-----Original Message-----
>>>From: Michael Kelley <mikelley@microsoft.com>
>>>Sent: Monday, April 1, 2019 9:11 AM
>>>To: KY Srinivasan <kys@microsoft.com>; martin.petersen@oracle.com; Long
>>>Li <longli@microsoft.com>; James.Bottomley@hansenpartnership.com;
>>>emilne@redhat.com; linux-hyperv@vger.kernel.org; linux-
>>>kernel@vger.kernel.org; linux-scsi@vger.kernel.org
>>>Cc: Michael Kelley <mikelley@microsoft.com>
>>>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).
>>>
>>>Signed-off-by: Michael Kelley <mikelley@microsoft.com>
>>>Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>>>---
>>>Changes in v2:
>>>* Put num_online_cpus() inline and eliminate num_cpus local
>>>  variable [Vitaly Kuznetsov]
>>>

Reviewed-by: Long Li <longli@microsoft.com>

>>>---
>>> drivers/scsi/storvsc_drv.c | 13 +++++++++++--
>>> 1 file changed, 11 insertions(+), 2 deletions(-)
>>>
>>>diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index
>>>84380ba..e186743 100644
>>>--- a/drivers/scsi/storvsc_drv.c
>>>+++ b/drivers/scsi/storvsc_drv.c
>>>@@ -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


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

* Re: [PATCH v2 1/1] scsi: storvsc: Fix calculation of sub-channel count
  2019-04-01 16:10 [PATCH v2 1/1] scsi: storvsc: Fix calculation of sub-channel count Michael Kelley
  2019-04-01 21:38 ` Long Li
@ 2019-04-04  3:30 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2019-04-04  3:30 UTC (permalink / raw)
  To: Michael Kelley
  Cc: KY Srinivasan, martin.petersen, Long Li, James.Bottomley, emilne,
	linux-hyperv, linux-kernel, linux-scsi


Michael,

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

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2019-04-04  3:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-01 16:10 [PATCH v2 1/1] scsi: storvsc: Fix calculation of sub-channel count Michael Kelley
2019-04-01 21:38 ` Long Li
2019-04-04  3:30 ` 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).