Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 7250f422da04 ("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>

+2 -2
+2 -2
drivers/xen/swiotlb-xen.c
··· 147 147 void *ret; 148 148 149 149 /* Align the allocation to the Xen page size */ 150 - size = 1UL << (order + XEN_PAGE_SHIFT); 150 + size = ALIGN(size, XEN_PAGE_SIZE); 151 151 152 152 ret = (void *)__get_free_pages(flags, get_order(size)); 153 153 if (!ret) ··· 179 179 int order = get_order(size); 180 180 181 181 /* Convert the size to actually allocated. */ 182 - size = 1UL << (order + XEN_PAGE_SHIFT); 182 + size = ALIGN(size, XEN_PAGE_SIZE); 183 183 184 184 if (WARN_ON_ONCE(dma_handle + size - 1 > dev->coherent_dma_mask) || 185 185 WARN_ON_ONCE(range_straddles_page_boundary(phys, size)))