Skip to content

Commit

Permalink
xen/swiotlb: fix allocated size
Browse files Browse the repository at this point in the history
The allocated size in xen_swiotlb_alloc_coherent() and
xen_swiotlb_free_coherent() is calculated wrong for the case of
XEN_PAGE_SIZE not matching PAGE_SIZE. Fix that.

Fixes: 7250f42 ("xen-swiotlb: use actually allocated size on check physical continuous")
Reported-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Juergen Gross <jgross@suse.com>
  • Loading branch information
Juergen Gross committed Sep 17, 2024
1 parent 9f40ec8 commit c3dea3d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/xen/swiotlb-xen.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ xen_swiotlb_alloc_coherent(struct device *dev, size_t size,
void *ret;

/* Align the allocation to the Xen page size */
size = 1UL << (order + XEN_PAGE_SHIFT);
size = ALIGN(size, XEN_PAGE_SIZE);

ret = (void *)__get_free_pages(flags, get_order(size));
if (!ret)
Expand Down Expand Up @@ -179,7 +179,7 @@ xen_swiotlb_free_coherent(struct device *dev, size_t size, void *vaddr,
int order = get_order(size);

/* Convert the size to actually allocated. */
size = 1UL << (order + XEN_PAGE_SHIFT);
size = ALIGN(size, XEN_PAGE_SIZE);

if (WARN_ON_ONCE(dma_handle + size - 1 > dev->coherent_dma_mask) ||
WARN_ON_ONCE(range_straddles_page_boundary(phys, size)))
Expand Down

0 comments on commit c3dea3d

Please sign in to comment.