[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-arm] [RFC v2 15/28] hw/arm/smmuv3: Notify on config changes
From: |
Eric Auger |
Subject: |
[Qemu-arm] [RFC v2 15/28] hw/arm/smmuv3: Notify on config changes |
Date: |
Fri, 21 Sep 2018 10:18:06 +0200 |
In case IOMMU config notifiers are attached to the
IOMMU memory region, we execute them, passing as argument
the iommu_pasid_table_config struct updated with the new
viommu translation config. Config notifiers are called on
STE changes. At physical level, they translate into
CMD_CFGI_STE_* commands.
Signed-off-by: Eric Auger <address@hidden>
---
v1 -> v2:
- do not notify anymore on CD change. Anyway the smmuv3 linux
driver is not sending any CD invalidation commands. If we were
to propagate CD invalidation commands, we would use the
CACHE_INVALIDATE VFIO ioctl.
- notify a precise config flags to prepare for addition of new
flags
---
hw/arm/smmuv3.c | 61 +++++++++++++++++++++++++++++++++++--------------
1 file changed, 44 insertions(+), 17 deletions(-)
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index d609038724..196835739f 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -16,6 +16,8 @@
* with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#include "linux/iommu.h"
+
#include "qemu/osdep.h"
#include "hw/boards.h"
#include "sysemu/sysemu.h"
@@ -843,6 +845,46 @@ static void smmuv3_inv_notifiers_iova(SMMUState *s, int
asid, dma_addr_t iova)
}
}
+static void smmuv3_notify_config_change(SMMUState *bs, uint32_t sid)
+{
+ IOMMUMemoryRegion *mr = smmu_iommu_mr(bs, sid);
+ SMMUEventInfo event = {.type = SMMU_EVT_NONE, .sid = sid};
+ SMMUTransCfg *cfg;
+ SMMUDevice *sdev;
+
+ if (!mr) {
+ return;
+ }
+
+ sdev = container_of(mr, SMMUDevice, iommu);
+
+ /* flush QEMU config cache */
+ smmuv3_flush_config(sdev);
+
+ if (mr->iommu_notify_flags & IOMMU_NOTIFIER_PASID_CFG) {
+ /* force a guest RAM config structure decoding */
+ cfg = smmuv3_get_config(sdev, &event);
+
+ if (cfg) {
+ IOMMUConfig *iommu_config = g_new0(IOMMUConfig, 1);
+
+ iommu_config->pasid_cfg.format = IOMMU_PASID_FORMAT_SMMUV3;
+ iommu_config->pasid_cfg.smmuv3.bypass =
+ cfg->disabled || cfg->bypassed;
+ iommu_config->pasid_cfg.smmuv3.abort = cfg->aborted;
+ iommu_config->pasid_cfg.smmuv3.s1contextptr = cfg->s1ctxptr;
+
+ memory_region_config_notify_iommu(mr, 0, IOMMU_NOTIFIER_PASID_CFG,
+ iommu_config);
+ g_free(iommu_config);
+ } else {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s error decoding the configuration for iommu
mr=%s\n",
+ __func__, mr->parent_obj.name);
+ }
+ }
+}
+
static int smmuv3_cmdq_consume(SMMUv3State *s)
{
SMMUState *bs = ARM_SMMU(s);
@@ -893,22 +935,14 @@ static int smmuv3_cmdq_consume(SMMUv3State *s)
case SMMU_CMD_CFGI_STE:
{
uint32_t sid = CMD_SID(&cmd);
- IOMMUMemoryRegion *mr = smmu_iommu_mr(bs, sid);
- SMMUDevice *sdev;
if (CMD_SSEC(&cmd)) {
cmd_error = SMMU_CERROR_ILL;
break;
}
- if (!mr) {
- break;
- }
-
trace_smmuv3_cmdq_cfgi_ste(sid);
- sdev = container_of(mr, SMMUDevice, iommu);
- smmuv3_flush_config(sdev);
-
+ smmuv3_notify_config_change(bs, sid);
break;
}
case SMMU_CMD_CFGI_STE_RANGE: /* same as SMMU_CMD_CFGI_ALL */
@@ -925,14 +959,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s)
trace_smmuv3_cmdq_cfgi_ste_range(start, end);
for (i = start; i <= end; i++) {
- IOMMUMemoryRegion *mr = smmu_iommu_mr(bs, i);
- SMMUDevice *sdev;
-
- if (!mr) {
- continue;
- }
- sdev = container_of(mr, SMMUDevice, iommu);
- smmuv3_flush_config(sdev);
+ smmuv3_notify_config_change(bs, i);
}
break;
}
--
2.17.1
- [Qemu-arm] [RFC v2 06/28] hw/arm/smmuv3: Implement get_attr API to report IOMMU_ATTR_VFIO_NESTED, (continued)
- [Qemu-arm] [RFC v2 06/28] hw/arm/smmuv3: Implement get_attr API to report IOMMU_ATTR_VFIO_NESTED, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 07/28] hw/vfio/common: Refactor container initialization, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 08/28] hw/vfio/common: Force nested if iommu requires it, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 09/28] memory: Introduce IOMMUIOLTBNotifier, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 10/28] memory: rename memory_region notify_iommu, notify_one, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 11/28] memory: Add IOMMUConfigNotifier, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 13/28] hw/arm/smmuv3: Store s1ctrptr in translation config data, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 12/28] memory: Add arch_id in IOTLBEntry, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 14/28] hw/arm/smmuv3: Implement dummy replay, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 16/28] hw/arm/smmuv3: Fill the IOTLBEntry arch_id on NH_VA invalidation, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 15/28] hw/arm/smmuv3: Notify on config changes,
Eric Auger <=
- [Qemu-arm] [RFC v2 17/28] hw/vfio/common: Introduce vfio_alloc_guest_iommu helper, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 18/28] hw/vfio/common: Introduce vfio_dma_(un)map_ram_section helpers, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 19/28] hw/vfio/common: Register specific nested mode notifiers and memory_listener, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 22/28] vfio/pci: Always set up MSI route before enabling vectors, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 21/28] target/arm/kvm: Notifies IOMMU on MSI stage 1 binding, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 20/28] hw/vfio/common: Register MAP notifier for MSI binding, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 24/28] memory: Introduce IOMMU_NOTIFIER_INIT_CFG IOMMU Config Notifier, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 23/28] hw/arm/smmuv3: Remove warning about unsupported MAP notifiers, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 25/28] memory: Introduce IOMMU Memory Region inject_faults API, Eric Auger, 2018/09/21
- [Qemu-arm] [RFC v2 26/28] hw/vfio/common: Handle fault_handler, Eric Auger, 2018/09/21