Skip to content

Commit 875553e

Browse files
Oleksandr Tyshchenkojgross1
authored andcommitted
xen/virtio: Handle cases when page offset > PAGE_SIZE properly
Passed to xen_grant_dma_map_page() offset in the page can be > PAGE_SIZE even if the guest uses the same page granularity as Xen (4KB). Before current patch, if such case happened we ended up providing grants for the whole region in xen_grant_dma_map_page() which was really unnecessary. The more, we ended up not releasing all grants which represented that region in xen_grant_dma_unmap_page(). Current patch updates the code to be able to deal with such cases. Signed-off-by: Oleksandr Tyshchenko <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]> Reviewed-by: Xenia Ragiadakou <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent 7880672 commit 875553e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/xen/grant-dma-ops.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ static dma_addr_t xen_grant_dma_map_page(struct device *dev, struct page *page,
168168
unsigned long attrs)
169169
{
170170
struct xen_grant_dma_data *data;
171-
unsigned int i, n_pages = PFN_UP(offset + size);
171+
unsigned long dma_offset = offset_in_page(offset),
172+
pfn_offset = PFN_DOWN(offset);
173+
unsigned int i, n_pages = PFN_UP(dma_offset + size);
172174
grant_ref_t grant;
173175
dma_addr_t dma_handle;
174176

@@ -187,10 +189,11 @@ static dma_addr_t xen_grant_dma_map_page(struct device *dev, struct page *page,
187189

188190
for (i = 0; i < n_pages; i++) {
189191
gnttab_grant_foreign_access_ref(grant + i, data->backend_domid,
190-
xen_page_to_gfn(page) + i, dir == DMA_TO_DEVICE);
192+
pfn_to_gfn(page_to_xen_pfn(page) + i + pfn_offset),
193+
dir == DMA_TO_DEVICE);
191194
}
192195

193-
dma_handle = grant_to_dma(grant) + offset;
196+
dma_handle = grant_to_dma(grant) + dma_offset;
194197

195198
return dma_handle;
196199
}

0 commit comments

Comments
 (0)