Skip to content

Commit 8ddac55

Browse files
bostrovsgregkh
authored andcommitted
swiotlb-xen: use vmalloc_to_page on vmalloc virt addresses
[ Upstream commit 8b1e868 ] xen_alloc_coherent_pages might return pages for which virt_to_phys and virt_to_page don't work, e.g. ioremap'ed pages. So in xen_swiotlb_free_coherent we can't assume that virt_to_page works. Instead add a is_vmalloc_addr check and use vmalloc_to_page on vmalloc virt addresses. This patch fixes the following crash at boot on RPi4 (the underlying issue is not RPi4 specific): https://marc.info/?l=xen-devel&m=158862573216800 Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Tested-by: Corey Minyard <cminyard@mvista.com> Tested-by: Roman Shaposhnik <roman@zededa.com> Link: https://lore.kernel.org/r/20200710223427.6897-1-sstabellini@kernel.org Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 81b4dc1 commit 8ddac55

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎drivers/xen/swiotlb-xen.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
335335
int order = get_order(size);
336336
phys_addr_t phys;
337337
u64 dma_mask = DMA_BIT_MASK(32);
338+
struct page *page;
338339

339340
if (hwdev && hwdev->coherent_dma_mask)
340341
dma_mask = hwdev->coherent_dma_mask;
@@ -346,9 +347,14 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
346347
/* Convert the size to actually allocated. */
347348
size = 1UL << (order + XEN_PAGE_SHIFT);
348349

350+
if (is_vmalloc_addr(vaddr))
351+
page = vmalloc_to_page(vaddr);
352+
else
353+
page = virt_to_page(vaddr);
354+
349355
if (!WARN_ON((dev_addr + size - 1 > dma_mask) ||
350356
range_straddles_page_boundary(phys, size)) &&
351-
TestClearPageXenRemapped(virt_to_page(vaddr)))
357+
TestClearPageXenRemapped(page))
352358
xen_destroy_contiguous_region(phys, order);
353359

354360
xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs);

0 commit comments

Comments
 (0)