Skip to content

Commit c3dea3d

Browse files
committed
xen/swiotlb: fix allocated size
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 <[email protected]> Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Jan Beulich <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 9f40ec8 commit c3dea3d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/xen/swiotlb-xen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ xen_swiotlb_alloc_coherent(struct device *dev, size_t size,
147147
void *ret;
148148

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

152152
ret = (void *)__get_free_pages(flags, get_order(size));
153153
if (!ret)
@@ -179,7 +179,7 @@ xen_swiotlb_free_coherent(struct device *dev, size_t size, void *vaddr,
179179
int order = get_order(size);
180180

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

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

0 commit comments

Comments
 (0)