Skip to content

Commit 8f43710

Browse files
fbqliuw
authored andcommitted
scsi: storvsc: Support PAGE_SIZE larger than 4K
Hyper-V always use 4k page size (HV_HYP_PAGE_SIZE), so when communicating with Hyper-V, a guest should always use HV_HYP_PAGE_SIZE as the unit for page related data. For storvsc, the data is vmbus_packet_mpb_array. And since in scsi_cmnd, sglist of pages (in unit of PAGE_SIZE) is used, we need convert pages in the sglist of scsi_cmnd into Hyper-V pages in vmbus_packet_mpb_array. This patch does the conversion by dividing pages in sglist into Hyper-V pages, offset and indexes in vmbus_packet_mpb_array are recalculated accordingly. Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Link: https://lore.kernel.org/r/20200916034817.30282-12-boqun.feng@gmail.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 061dc93 commit 8f43710

1 file changed

Lines changed: 49 additions & 7 deletions

File tree

drivers/scsi/storvsc_drv.c

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,23 +1739,65 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
17391739
payload_sz = sizeof(cmd_request->mpb);
17401740

17411741
if (sg_count) {
1742-
if (sg_count > MAX_PAGE_BUFFER_COUNT) {
1742+
unsigned int hvpgoff = 0;
1743+
unsigned long offset_in_hvpg = sgl->offset & ~HV_HYP_PAGE_MASK;
1744+
unsigned int hvpg_count = HVPFN_UP(offset_in_hvpg + length);
1745+
u64 hvpfn;
17431746

1744-
payload_sz = (sg_count * sizeof(u64) +
1747+
if (hvpg_count > MAX_PAGE_BUFFER_COUNT) {
1748+
1749+
payload_sz = (hvpg_count * sizeof(u64) +
17451750
sizeof(struct vmbus_packet_mpb_array));
17461751
payload = kzalloc(payload_sz, GFP_ATOMIC);
17471752
if (!payload)
17481753
return SCSI_MLQUEUE_DEVICE_BUSY;
17491754
}
17501755

1756+
/*
1757+
* sgl is a list of PAGEs, and payload->range.pfn_array
1758+
* expects the page number in the unit of HV_HYP_PAGE_SIZE (the
1759+
* page size that Hyper-V uses, so here we need to divide PAGEs
1760+
* into HV_HYP_PAGE in case that PAGE_SIZE > HV_HYP_PAGE_SIZE.
1761+
* Besides, payload->range.offset should be the offset in one
1762+
* HV_HYP_PAGE.
1763+
*/
17511764
payload->range.len = length;
1752-
payload->range.offset = sgl[0].offset;
1765+
payload->range.offset = offset_in_hvpg;
1766+
hvpgoff = sgl->offset >> HV_HYP_PAGE_SHIFT;
17531767

17541768
cur_sgl = sgl;
1755-
for (i = 0; i < sg_count; i++) {
1756-
payload->range.pfn_array[i] =
1757-
page_to_pfn(sg_page((cur_sgl)));
1758-
cur_sgl = sg_next(cur_sgl);
1769+
for (i = 0; i < hvpg_count; i++) {
1770+
/*
1771+
* 'i' is the index of hv pages in the payload and
1772+
* 'hvpgoff' is the offset (in hv pages) of the first
1773+
* hv page in the the first page. The relationship
1774+
* between the sum of 'i' and 'hvpgoff' and the offset
1775+
* (in hv pages) in a payload page ('hvpgoff_in_page')
1776+
* is as follow:
1777+
*
1778+
* |------------------ PAGE -------------------|
1779+
* | NR_HV_HYP_PAGES_IN_PAGE hvpgs in total |
1780+
* |hvpg|hvpg| ... |hvpg|... |hvpg|
1781+
* ^ ^ ^ ^
1782+
* +-hvpgoff-+ +-hvpgoff_in_page-+
1783+
* ^ |
1784+
* +--------------------- i ---------------------------+
1785+
*/
1786+
unsigned int hvpgoff_in_page =
1787+
(i + hvpgoff) % NR_HV_HYP_PAGES_IN_PAGE;
1788+
1789+
/*
1790+
* Two cases that we need to fetch a page:
1791+
* 1) i == 0, the first step or
1792+
* 2) hvpgoff_in_page == 0, when we reach the boundary
1793+
* of a page.
1794+
*/
1795+
if (hvpgoff_in_page == 0 || i == 0) {
1796+
hvpfn = page_to_hvpfn(sg_page(cur_sgl));
1797+
cur_sgl = sg_next(cur_sgl);
1798+
}
1799+
1800+
payload->range.pfn_array[i] = hvpfn + hvpgoff_in_page;
17591801
}
17601802
}
17611803

0 commit comments

Comments
 (0)