Skip to content

Commit c9b6180

Browse files
author
Christoph Hellwig
committed
swiotlb-xen: use the same foreign page check everywhere
xen_dma_map_page uses a different and more complicated check for foreign pages than the other three cache maintainance helpers. Switch it to the simpler pfn_valid method a well, and document the scheme with a single improved comment in xen_dma_map_page. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
1 parent 922659e commit c9b6180

1 file changed

Lines changed: 9 additions & 22 deletions

File tree

‎include/xen/arm/page-coherent.h‎

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,17 @@ static inline void xen_dma_map_page(struct device *hwdev, struct page *page,
5353
dma_addr_t dev_addr, unsigned long offset, size_t size,
5454
enum dma_data_direction dir, unsigned long attrs)
5555
{
56-
unsigned long page_pfn = page_to_xen_pfn(page);
57-
unsigned long dev_pfn = XEN_PFN_DOWN(dev_addr);
58-
unsigned long compound_pages =
59-
(1<<compound_order(page)) * XEN_PFN_PER_PAGE;
60-
bool local = (page_pfn <= dev_pfn) &&
61-
(dev_pfn - page_pfn < compound_pages);
56+
unsigned long pfn = PFN_DOWN(dev_addr);
6257

6358
/*
64-
* Dom0 is mapped 1:1, while the Linux page can span across
65-
* multiple Xen pages, it's not possible for it to contain a
66-
* mix of local and foreign Xen pages. So if the first xen_pfn
67-
* == mfn the page is local otherwise it's a foreign page
68-
* grant-mapped in dom0. If the page is local we can safely
69-
* call the native dma_ops function, otherwise we call the xen
70-
* specific function.
59+
* Dom0 is mapped 1:1, and while the Linux page can span across multiple
60+
* Xen pages, it is not possible for it to contain a mix of local and
61+
* foreign Xen pages. Calling pfn_valid on a foreign mfn will always
62+
* return false, so if pfn_valid returns true the pages is local and we
63+
* can use the native dma-direct functions, otherwise we call the Xen
64+
* specific version.
7165
*/
72-
if (local)
66+
if (pfn_valid(pfn))
7367
dma_direct_map_page(hwdev, page, offset, size, dir, attrs);
7468
else
7569
__xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs);
@@ -79,14 +73,7 @@ static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle,
7973
size_t size, enum dma_data_direction dir, unsigned long attrs)
8074
{
8175
unsigned long pfn = PFN_DOWN(handle);
82-
/*
83-
* Dom0 is mapped 1:1, while the Linux page can be spanned accross
84-
* multiple Xen page, it's not possible to have a mix of local and
85-
* foreign Xen page. Dom0 is mapped 1:1, so calling pfn_valid on a
86-
* foreign mfn will always return false. If the page is local we can
87-
* safely call the native dma_ops function, otherwise we call the xen
88-
* specific function.
89-
*/
76+
9077
if (pfn_valid(pfn))
9178
dma_direct_unmap_page(hwdev, handle, size, dir, attrs);
9279
else

0 commit comments

Comments
 (0)