Skip to content

Commit e433715

Browse files
Oleksandr Tyshchenkojgross1
authored andcommitted
xen/virtio: Fix n_pages calculation in xen_grant_dma_map(unmap)_page()
Take page offset into the account when calculating the number of pages to be granted. Fixes: d6aca35 ("xen/grant-dma-ops: Add option to restrict memory access under Xen") Signed-off-by: Oleksandr Tyshchenko <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]> Reviewed-by: Juergen Gross <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent 06c62f8 commit e433715

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/xen/grant-dma-ops.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static dma_addr_t xen_grant_dma_map_page(struct device *dev, struct page *page,
153153
unsigned long attrs)
154154
{
155155
struct xen_grant_dma_data *data;
156-
unsigned int i, n_pages = PFN_UP(size);
156+
unsigned int i, n_pages = PFN_UP(offset + size);
157157
grant_ref_t grant;
158158
dma_addr_t dma_handle;
159159

@@ -185,7 +185,8 @@ static void xen_grant_dma_unmap_page(struct device *dev, dma_addr_t dma_handle,
185185
unsigned long attrs)
186186
{
187187
struct xen_grant_dma_data *data;
188-
unsigned int i, n_pages = PFN_UP(size);
188+
unsigned long offset = dma_handle & (PAGE_SIZE - 1);
189+
unsigned int i, n_pages = PFN_UP(offset + size);
189190
grant_ref_t grant;
190191

191192
if (WARN_ON(dir == DMA_NONE))

0 commit comments

Comments
 (0)