From: Zhou Qihang zhouqihang@wxiat.com
Sunway inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I5G5T3
--------------------------------
Since the RCs of SW64 chipset do not support Peer-to-Peer DMA, we used to return -EINVAL error on iova mampping on PCI BARs. However, it will cause driver loading errors when QEMU calls vfio module to passthrough PCI devices with this kind of BARs, shown as follows:
qemu-system-sw64: VFIO_MAP_DMA: -22 qemu-system-sw64: vfio_dma_map(0x121c28020, 0x8800c0000000, 0x40000,
0x4165f21b2000) = -22 (Invalid argument)
qemu: hardware error: vfio: DMA mapping failed, unable to continue
To fix this problem, this patch will return success on the iova mapping of PCI BARs that pretends to support this feature.
Signed-off-by: Zhou Qihang zhouqihang@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- drivers/iommu/sw64/sunway_iommu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/sw64/sunway_iommu.c b/drivers/iommu/sw64/sunway_iommu.c index 8b851e0a0c20..5797adf8fbc5 100644 --- a/drivers/iommu/sw64/sunway_iommu.c +++ b/drivers/iommu/sw64/sunway_iommu.c @@ -1509,6 +1509,9 @@ sunway_iommu_iova_to_phys(struct iommu_domain *dom, dma_addr_t iova) struct sunway_iommu_domain *sdomain = to_sunway_domain(dom); unsigned long paddr, grn;
+ if (iova > SW64_BAR_ADDRESS) + return iova; + paddr = fetch_pte(sdomain, iova, PTE_LEVEL2_VAL);
if ((paddr & SW64_IOMMU_ENTRY_VALID) == 0) @@ -1544,7 +1547,7 @@ sunway_iommu_map(struct iommu_domain *dom, unsigned long iova, * to avoid VFIO trying to map pci config space. */ if (iova > SW64_BAR_ADDRESS) - return -EINVAL; + return 0;
mutex_lock(&sdomain->api_lock); ret = sunway_iommu_map_page(sdomain, iova, paddr, page_size);