Skip to contentSkip to conversation

swiotlb-xen.c: Fixed cache invalidation fault

PATCH New Nataliya Korovkina 1 participant 1 message Feb 28, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 swiotlb-xen.c: Fixed cache invalidation fault

Problem: xen_swiotlb_map_sg_attrs() maps a set of buffers described in scatterlist. It calls xen_dma_map_page() and sets sglist.dma_address to the address calculated by xen_phys_to_bus(). Let's call it dma_address_1.

xen_dma_map_page() maps the area and gets dma address different from dma_address_1, let's call it dma_address_2. Then function __swiotlb_map_page() makes conversion:
dma_addr -> phys_addr -> virt_addr using dma_address_2 and passes "virt_addr"
to __dma_map_area(), the latter successfully invalidates cache.

When xen_swiotlb_unmap_sg_attrs() unmaps the area it passes dma_address_1
to __swiotlb_unmap_page(). __swiotlb_unmap_page() makes the same convertion:
dma_addr -> phys_addr -> virt_addr using dma_address_1 and passes "virt_addr" to __dma_map_area(), the latter gets Data Abort in attempt to invalidate cache.

The problem manfests on devices that have dma_pfn_offset != 0. Specifically, while loading brcmfmac module (BCM4345 WiFi chip) in Dom0.

What was done: sglist.dma_address is set to phys_to_dma("phys").

---
 drivers/xen/swiotlb-xen.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/swiotlb-xen.c +2 -2
index a6f9ba85dc4b..9363a52e4756 100644
@@ -583,7 +583,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
 						sg->length,
 						dir,
 						attrs);
-			sg->dma_address = dev_addr;
+			sg->dma_address = phys_to_dma(hwdev, dev_addr);
 		} else {
 			/* we are not interested in the dma_addr returned by
 			 * xen_dma_map_page, only in the potential cache flushes executed
@@ -594,7 +594,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
 						sg->length,
 						dir,
 						attrs);
-			sg->dma_address = dev_addr;
+			sg->dma_address = phys_to_dma(hwdev, dev_addr);
 		}
 		sg_dma_len(sg) = sg->length;
 	}
Signature · 7 lines
2.17.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel