[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 15/20] amd_iommu: Toggle memory regions based on address trans
From: |
Alejandro Jimenez |
Subject: |
[PATCH v2 15/20] amd_iommu: Toggle memory regions based on address translation mode |
Date: |
Fri, 2 May 2025 02:16:00 +0000 |
Enable the appropriate memory region for an address space depending on the
address translation mode selected for it. This is currently based on a
generic x86 IOMMMU property, and only done during the address space
initialization. Extract the code into a helper and toggle the regions based
on whether the specific address space is using address translation (via the
newly introduced addr_translation field). Later, region activation will also
be controlled by availability of DMA remapping capability (via dma-remap
property to be introduced in follow up changes).
Signed-off-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
---
hw/i386/amd_iommu.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index fa5dbc3cc700..71018d70dd10 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -74,6 +74,8 @@ struct AMDVIAddressSpace {
QLIST_ENTRY(AMDVIAddressSpace) next;
/* Record DMA translation ranges */
IOVATree *iova_tree;
+ /* DMA address translation active */
+ bool addr_translation;
};
/* AMDVI cache entry */
@@ -943,6 +945,23 @@ static void amdvi_iommu_address_space_sync_all(AMDVIState
*s)
}
}
+/*
+ * Toggle between address translation and passthrough modes by enabling the
+ * corresponding memory regions.
+ */
+static void amdvi_switch_address_space(AMDVIAddressSpace *amdvi_as)
+{
+ if (amdvi_as->addr_translation) {
+ /* Enabling DMA region */
+ memory_region_set_enabled(&amdvi_as->iommu_nodma, false);
+ memory_region_set_enabled(MEMORY_REGION(&amdvi_as->iommu), true);
+ } else {
+ /* Disabling DMA region, using passthrough */
+ memory_region_set_enabled(MEMORY_REGION(&amdvi_as->iommu), false);
+ memory_region_set_enabled(&amdvi_as->iommu_nodma, true);
+ }
+}
+
/* log error without aborting since linux seems to be using reserved bits */
static void amdvi_inval_devtab_entry(AMDVIState *s, uint64_t *cmd)
{
@@ -1986,7 +2005,6 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus,
void *opaque, int devfn)
AMDVIState *s = opaque;
AMDVIAddressSpace **iommu_as, *amdvi_dev_as;
int bus_num = pci_bus_num(bus);
- X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);
iommu_as = s->address_spaces[bus_num];
@@ -2006,6 +2024,7 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus,
void *opaque, int devfn)
iommu_as[devfn]->iommu_state = s;
iommu_as[devfn]->notifier_flags = IOMMU_NONE;
iommu_as[devfn]->iova_tree = iova_tree_new();
+ iommu_as[devfn]->addr_translation = false;
amdvi_dev_as = iommu_as[devfn];
@@ -2048,15 +2067,7 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus,
void *opaque, int devfn)
AMDVI_INT_ADDR_FIRST,
&amdvi_dev_as->iommu_ir, 1);
- if (!x86_iommu->pt_supported) {
- memory_region_set_enabled(&amdvi_dev_as->iommu_nodma, false);
- memory_region_set_enabled(MEMORY_REGION(&amdvi_dev_as->iommu),
- true);
- } else {
- memory_region_set_enabled(MEMORY_REGION(&amdvi_dev_as->iommu),
- false);
- memory_region_set_enabled(&amdvi_dev_as->iommu_nodma, true);
- }
+ amdvi_switch_address_space(amdvi_dev_as);
}
return &iommu_as[devfn]->as;
}
--
2.43.5
- [PATCH v2 06/20] amd_iommu: Return an error when unable to read PTE from guest memory, (continued)
- [PATCH v2 06/20] amd_iommu: Return an error when unable to read PTE from guest memory, Alejandro Jimenez, 2025/05/01
- [PATCH v2 05/20] amd_iommu: Add helper function to extract the DTE, Alejandro Jimenez, 2025/05/01
- [PATCH v2 04/20] amd_iommu: Helper to decode size of page invalidation command, Alejandro Jimenez, 2025/05/01
- [PATCH v2 10/20] amd_iommu: Sync shadow page tables on page invalidation, Alejandro Jimenez, 2025/05/01
- [PATCH v2 17/20] amd_iommu: Add dma-remap property to AMD vIOMMU device, Alejandro Jimenez, 2025/05/01
- [PATCH v2 07/20] amd_iommu: Add helpers to walk AMD v1 Page Table format, Alejandro Jimenez, 2025/05/01
- [PATCH v2 12/20] amd_iommu: Unmap all address spaces under the AMD IOMMU on reset, Alejandro Jimenez, 2025/05/01
- [PATCH v2 11/20] amd_iommu: Use iova_tree records to determine large page size on UNMAP, Alejandro Jimenez, 2025/05/01
- [PATCH v2 15/20] amd_iommu: Toggle memory regions based on address translation mode,
Alejandro Jimenez <=
- [PATCH v2 08/20] amd_iommu: Add a page walker to sync shadow page tables on invalidation, Alejandro Jimenez, 2025/05/01
- [PATCH v2 19/20] amd_iommu: Do not assume passthrough translation when DTE[TV]=0, Alejandro Jimenez, 2025/05/01
- [PATCH v2 13/20] amd_iommu: Add replay callback, Alejandro Jimenez, 2025/05/01
- [PATCH v2 18/20] amd_iommu: Toggle address translation mode on devtab entry invalidation, Alejandro Jimenez, 2025/05/01
- [PATCH v2 20/20] amd_iommu: Refactor amdvi_page_walk() to use common code for page walk, Alejandro Jimenez, 2025/05/01
- [PATCH v2 16/20] amd_iommu: Set all address spaces to default translation mode on reset, Alejandro Jimenez, 2025/05/01