From: Saurabh Sengar <ssengar@linux.microsoft.com>
To: kys@microsoft.com, haiyangz@microsoft.com,
sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
ssengar@microsoft.com, mikelley@microsoft.com
Subject: [PATCH] scsi: storvsc: Correct sysfs parameters as per Hyper-V storvsc requirement
Date: Fri, 10 Jun 2022 09:33:44 -0700 [thread overview]
Message-ID: <1654878824-25691-1-git-send-email-ssengar@linux.microsoft.com> (raw)
This patch corrects 3 parameters:
1. Correct the sysfs entry for maximum hardware transfer limit of single
transfer (max_hw_sectors_kb) by setting max_sectors, this was set to
default value 512kb before.
2. Correct SGL memory offset alignment as per Hyper-V page size.
3. Correct sg_tablesize which accounts for max SGL segments entries in a
single SGL.
Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
---
drivers/scsi/storvsc_drv.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index ca3530982e52..3e032660ae36 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1844,7 +1844,7 @@ static struct scsi_host_template scsi_driver = {
.cmd_per_lun = 2048,
.this_id = -1,
/* Ensure there are no gaps in presented sgls */
- .virt_boundary_mask = PAGE_SIZE-1,
+ .virt_boundary_mask = HV_HYP_PAGE_SIZE - 1,
.no_write_same = 1,
.track_queue_depth = 1,
.change_queue_depth = storvsc_change_queue_depth,
@@ -1969,11 +1969,31 @@ static int storvsc_probe(struct hv_device *device,
/* max cmd length */
host->max_cmd_len = STORVSC_MAX_CMD_LEN;
+ /* max_hw_sectors_kb */
+ host->max_sectors = (stor_device->max_transfer_bytes) >> 9;
/*
- * set the table size based on the info we got
- * from the host.
+ * There are 2 requirements for Hyper-V storvsc sgl segments,
+ * based on which the below calculation for max segments is
+ * done:
+ *
+ * 1. Except for the first and last sgl segment, all sgl segments
+ * should be align to HV_HYP_PAGE_SIZE, that also means the
+ * maximum number of segments in a sgl can be calculated by
+ * dividing the total max transfer length by HV_HYP_PAGE_SIZE.
+ *
+ * 2. Except for the first and last, each entry in the SGL must
+ * have an offset that is a multiple of HV_HYP_PAGE_SIZE,
+ * whereas the complete length of transfer may not be aligned
+ * to HV_HYP_PAGE_SIZE always. This can result in 2 cases:
+ * Example for unaligned case: Let's say the total transfer
+ * length is 6 KB, the max segments will be 3 (1,4,1).
+ * Example for aligned case: Let's say the total transfer length
+ * is 8KB, then max segments will still be 3(2,4,2) and not 4.
+ * 4 (read next higher value) segments will only be required
+ * once the length is at least 2 bytes more then 8KB (read any
+ * HV_HYP_PAGE_SIZE aligned length).
*/
- host->sg_tablesize = (stor_device->max_transfer_bytes >> PAGE_SHIFT);
+ host->sg_tablesize = ((stor_device->max_transfer_bytes - 2) >> HV_HYP_PAGE_SHIFT) + 2;
/*
* For non-IDE disks, the host supports multiple channels.
* Set the number of HW queues we are supporting.
--
2.25.1
next reply other threads:[~2022-06-10 16:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-10 16:33 Saurabh Sengar [this message]
2022-06-10 16:37 ` [PATCH] scsi: storvsc: Correct sysfs parameters as per Hyper-V storvsc requirement Saurabh Singh Sengar
2022-06-13 2:49 ` Michael Kelley (LINUX)
2022-06-13 4:05 ` Saurabh Singh Sengar
2022-06-13 13:55 ` Michael Kelley (LINUX)
2022-06-13 14:38 ` Saurabh Singh Sengar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1654878824-25691-1-git-send-email-ssengar@linux.microsoft.com \
--to=ssengar@linux.microsoft.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mikelley@microsoft.com \
--cc=ssengar@microsoft.com \
--cc=sthemmin@microsoft.com \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).