Commit e433715b authored by Oleksandr Tyshchenko's avatar Oleksandr Tyshchenko Committed by Juergen Gross

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: d6aca350 ("xen/grant-dma-ops: Add option to restrict memory access under Xen")
Signed-off-by: default avatarOleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Reviewed-by: default avatarStefano Stabellini <sstabellini@kernel.org>
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Link: https://lore.kernel.org/r/20221005174823.1800761-2-olekstysh@gmail.comSigned-off-by: default avatarJuergen Gross <jgross@suse.com>
parent 06c62f8c
...@@ -153,7 +153,7 @@ static dma_addr_t xen_grant_dma_map_page(struct device *dev, struct page *page, ...@@ -153,7 +153,7 @@ static dma_addr_t xen_grant_dma_map_page(struct device *dev, struct page *page,
unsigned long attrs) unsigned long attrs)
{ {
struct xen_grant_dma_data *data; struct xen_grant_dma_data *data;
unsigned int i, n_pages = PFN_UP(size); unsigned int i, n_pages = PFN_UP(offset + size);
grant_ref_t grant; grant_ref_t grant;
dma_addr_t dma_handle; dma_addr_t dma_handle;
...@@ -185,7 +185,8 @@ static void xen_grant_dma_unmap_page(struct device *dev, dma_addr_t dma_handle, ...@@ -185,7 +185,8 @@ static void xen_grant_dma_unmap_page(struct device *dev, dma_addr_t dma_handle,
unsigned long attrs) unsigned long attrs)
{ {
struct xen_grant_dma_data *data; struct xen_grant_dma_data *data;
unsigned int i, n_pages = PFN_UP(size); unsigned long offset = dma_handle & (PAGE_SIZE - 1);
unsigned int i, n_pages = PFN_UP(offset + size);
grant_ref_t grant; grant_ref_t grant;
if (WARN_ON(dir == DMA_NONE)) if (WARN_ON(dir == DMA_NONE))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment