[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 17/19] intel_iommu: Set address mask when a translation fails
From: |
CLEMENT MATHIEU--DRIF |
Subject: |
[PATCH v2 17/19] intel_iommu: Set address mask when a translation fails and adjust W permission |
Date: |
Mon, 20 Jan 2025 17:41:56 +0000 |
From: Clement Mathieu--Drif <clement.mathieu--drif@eviden.com>
Implements the behavior defined in section 10.2.3.5 of PCIe spec rev 5.
This is needed by devices that support ATS.
Signed-off-by: Clement Mathieu--Drif <clement.mathieu--drif@eviden.com>
---
hw/i386/intel_iommu.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 021834c41f..530b75a9a3 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2100,7 +2100,8 @@ static bool vtd_do_iommu_translate(VTDAddressSpace
*vtd_as, PCIBus *bus,
uint8_t bus_num = pci_bus_num(bus);
VTDContextCacheEntry *cc_entry;
uint64_t pte, page_mask;
- uint32_t level, pasid = vtd_as->pasid;
+ uint32_t level = UINT32_MAX;
+ uint32_t pasid = vtd_as->pasid;
uint16_t source_id = PCI_BUILD_BDF(bus_num, devfn);
int ret_fr;
bool is_fpd_set = false;
@@ -2259,14 +2260,19 @@ out:
entry->iova = addr & page_mask;
entry->translated_addr = vtd_get_pte_addr(pte, s->aw_bits) & page_mask;
entry->addr_mask = ~page_mask;
- entry->perm = access_flags;
+ entry->perm = (is_write ? access_flags : (access_flags & (~IOMMU_WO)));
return true;
error:
vtd_iommu_unlock(s);
entry->iova = 0;
entry->translated_addr = 0;
- entry->addr_mask = 0;
+ /*
+ * Set the mask for ATS (the range must be present even when the
+ * translation fails : PCIe rev 5 10.2.3.5)
+ */
+ entry->addr_mask = (level != UINT32_MAX) ?
+ (~vtd_pt_level_page_mask(level)) : (~VTD_PAGE_MASK_4K);
entry->perm = IOMMU_NONE;
return false;
}
--
2.47.1
- [PATCH v2 03/19] memory: Allow to store the PASID in IOMMUTLBEntry, (continued)
- [PATCH v2 03/19] memory: Allow to store the PASID in IOMMUTLBEntry, CLEMENT MATHIEU--DRIF, 2025/01/20
- [PATCH v2 08/19] pci: Cache the bus mastering status in the device, CLEMENT MATHIEU--DRIF, 2025/01/20
- [PATCH v2 10/19] intel_iommu: Implement the get_memory_region_pasid iommu operation, CLEMENT MATHIEU--DRIF, 2025/01/20
- [PATCH v2 09/19] pci: Add IOMMU operations to get memory regions with PASID, CLEMENT MATHIEU--DRIF, 2025/01/20
- [PATCH v2 11/19] memory: Store user data pointer in the IOMMU notifiers, CLEMENT MATHIEU--DRIF, 2025/01/20
- [PATCH v2 13/19] atc: Generic ATC that can be used by PCIe devices that support SVM, CLEMENT MATHIEU--DRIF, 2025/01/20
- [PATCH v2 14/19] atc: Add unit tests, CLEMENT MATHIEU--DRIF, 2025/01/20
- [PATCH v2 16/19] pci: Add a pci-level API for ATS, CLEMENT MATHIEU--DRIF, 2025/01/20
- [PATCH v2 19/19] intel_iommu: Add support for ATS, CLEMENT MATHIEU--DRIF, 2025/01/20
- [PATCH v2 18/19] intel_iommu: Return page walk level even when the translation fails, CLEMENT MATHIEU--DRIF, 2025/01/20
- [PATCH v2 17/19] intel_iommu: Set address mask when a translation fails and adjust W permission,
CLEMENT MATHIEU--DRIF <=