Skip to content

Commit 8df98ff

Browse files
sstabellinigregkh
authored andcommitted
swiotlb-xen: update dev_addr after swapping pages
[ Upstream commit f1225ee4c8fcf09afaa199b8b1f0450f38b8cd11 ] In xen_swiotlb_map_page and xen_swiotlb_map_sg_attrs, if the original page is not suitable, we swap it for another page from the swiotlb pool. In these cases, we don't update the previously calculated dma address for the page before calling xen_dma_map_page. Thus, we end up calling xen_dma_map_page passing the wrong dev_addr, resulting in xen_dma_map_page mistakenly assuming that the page is foreign when it is local. Fix the bug by updating dev_addr appropriately. This change has no effect on x86, because xen_dma_map_page is a stub there. Signed-off-by: Stefano Stabellini <sstabellini@kernel.org> Signed-off-by: Pooya Keshavarzi <Pooya.Keshavarzi@de.bosch.com> Tested-by: Pooya Keshavarzi <Pooya.Keshavarzi@de.bosch.com> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 23c7f01 commit 8df98ff

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

drivers/xen/swiotlb-xen.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
409409
if (map == SWIOTLB_MAP_ERROR)
410410
return DMA_ERROR_CODE;
411411

412+
dev_addr = xen_phys_to_bus(map);
412413
xen_dma_map_page(dev, pfn_to_page(map >> PAGE_SHIFT),
413414
dev_addr, map & ~PAGE_MASK, size, dir, attrs);
414-
dev_addr = xen_phys_to_bus(map);
415415

416416
/*
417417
* Ensure that the address returned is DMA'ble
@@ -567,13 +567,14 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
567567
sg_dma_len(sgl) = 0;
568568
return 0;
569569
}
570+
dev_addr = xen_phys_to_bus(map);
570571
xen_dma_map_page(hwdev, pfn_to_page(map >> PAGE_SHIFT),
571572
dev_addr,
572573
map & ~PAGE_MASK,
573574
sg->length,
574575
dir,
575576
attrs);
576-
sg->dma_address = xen_phys_to_bus(map);
577+
sg->dma_address = dev_addr;
577578
} else {
578579
/* we are not interested in the dma_addr returned by
579580
* xen_dma_map_page, only in the potential cache flushes executed

0 commit comments

Comments
 (0)