[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v3 03/25] hw/iommu: introduce IOMMUContext
From: |
Liu, Yi L |
Subject: |
[RFC v3 03/25] hw/iommu: introduce IOMMUContext |
Date: |
Wed, 29 Jan 2020 04:16:34 -0800 |
From: Peter Xu <address@hidden>
Currently, many platform vendors provide the capability of dual stage
DMA address translation in hardware. For example, nested translation
on Intel VT-d scalable mode, nested stage translation on ARM SMMUv3,
and etc. Also there are efforts to make QEMU vIOMMU be backed by dual
stage DMA address translation capability provided by hardware to have
better address translation support for passthru devices.
As so, making vIOMMU be backed by dual stage translation capability
requires QEMU vIOMMU to have a way to get aware of such hardware
capability and also require a way to receive DMA address translation
faults (e.g. I/O page request) from host as guest owns stage-1 translation
structures in dual stage DAM address translation.
This patch adds IOMMUContext as an abstract of vIOMMU related operations.
Like provide a way for passthru modules (e.g. VFIO) to register
DualStageIOMMUObject instances. And in future, it is expected to offer
support for receiving host DMA translation faults happened on stage-1
translation.
For more backgrounds, may refer to the discussion below, while there
is also difference between the current implementation and original
proposal. This patch introduces the IOMMUContext as an abstract layer
for passthru module (e.g. VFIO) calls into vIOMMU. The first introduced
interface is to make QEMU vIOMMU be aware of dual stage translation
capability.
https://lists.gnu.org/archive/html/qemu-devel/2019-07/msg05022.html
Cc: Kevin Tian <address@hidden>
Cc: Jacob Pan <address@hidden>
Cc: Peter Xu <address@hidden>
Cc: Eric Auger <address@hidden>
Cc: Yi Sun <address@hidden>
Cc: David Gibson <address@hidden>
Signed-off-by: Peter Xu <address@hidden>
Signed-off-by: Liu Yi L <address@hidden>
---
hw/iommu/Makefile.objs | 1 +
hw/iommu/iommu_context.c | 54 +++++++++++++++++++++++++++++++++++
include/hw/iommu/iommu_context.h | 61 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 116 insertions(+)
create mode 100644 hw/iommu/iommu_context.c
create mode 100644 include/hw/iommu/iommu_context.h
diff --git a/hw/iommu/Makefile.objs b/hw/iommu/Makefile.objs
index d4f3b39..1e45072 100644
--- a/hw/iommu/Makefile.objs
+++ b/hw/iommu/Makefile.objs
@@ -1 +1,2 @@
obj-y += dual_stage_iommu.o
+obj-y += iommu_context.o
diff --git a/hw/iommu/iommu_context.c b/hw/iommu/iommu_context.c
new file mode 100644
index 0000000..6340ca3
--- /dev/null
+++ b/hw/iommu/iommu_context.c
@@ -0,0 +1,54 @@
+/*
+ * QEMU abstract of vIOMMU context
+ *
+ * Copyright (C) 2020 Red Hat Inc.
+ *
+ * Authors: Peter Xu <address@hidden>,
+ * Liu Yi L <address@hidden>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/iommu/iommu_context.h"
+
+int iommu_context_register_ds_iommu(IOMMUContext *iommu_ctx,
+ DualStageIOMMUObject *dsi_obj)
+{
+ if (!iommu_ctx || !dsi_obj) {
+ return -ENOENT;
+ }
+
+ if (iommu_ctx->ops && iommu_ctx->ops->register_ds_iommu) {
+ return iommu_ctx->ops->register_ds_iommu(iommu_ctx, dsi_obj);
+ }
+ return -ENOENT;
+}
+
+void iommu_context_unregister_ds_iommu(IOMMUContext *iommu_ctx,
+ DualStageIOMMUObject *dsi_obj)
+{
+ if (!iommu_ctx || !dsi_obj) {
+ return;
+ }
+
+ if (iommu_ctx->ops && iommu_ctx->ops->unregister_ds_iommu) {
+ iommu_ctx->ops->unregister_ds_iommu(iommu_ctx, dsi_obj);
+ }
+}
+
+void iommu_context_init(IOMMUContext *iommu_ctx, IOMMUContextOps *ops)
+{
+ iommu_ctx->ops = ops;
+}
diff --git a/include/hw/iommu/iommu_context.h b/include/hw/iommu/iommu_context.h
new file mode 100644
index 0000000..6f2ccb5
--- /dev/null
+++ b/include/hw/iommu/iommu_context.h
@@ -0,0 +1,61 @@
+/*
+ * QEMU abstraction of IOMMU Context
+ *
+ * Copyright (C) 2020 Red Hat Inc.
+ *
+ * Authors: Peter Xu <address@hidden>,
+ * Liu, Yi L <address@hidden>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HW_IOMMU_CONTEXT_H
+#define HW_IOMMU_CONTEXT_H
+
+#include "qemu/queue.h"
+#ifndef CONFIG_USER_ONLY
+#include "exec/hwaddr.h"
+#endif
+#include "hw/iommu/dual_stage_iommu.h"
+
+typedef struct IOMMUContext IOMMUContext;
+typedef struct IOMMUContextOps IOMMUContextOps;
+
+struct IOMMUContextOps {
+ /*
+ * Register DualStageIOMMUObject to vIOMMU thus vIOMMU
+ * is aware of dual stage translation capability, and
+ * also be able to setup dual stage translation via
+ * interfaces exposed by DualStageIOMMUObject.
+ */
+ int (*register_ds_iommu)(IOMMUContext *iommu_ctx,
+ DualStageIOMMUObject *dsi_obj);
+ void (*unregister_ds_iommu)(IOMMUContext *iommu_ctx,
+ DualStageIOMMUObject *dsi_obj);
+};
+
+/*
+ * This is an abstraction of IOMMU context.
+ */
+struct IOMMUContext {
+ IOMMUContextOps *ops;
+};
+
+int iommu_context_register_ds_iommu(IOMMUContext *iommu_ctx,
+ DualStageIOMMUObject *dsi_obj);
+void iommu_context_unregister_ds_iommu(IOMMUContext *iommu_ctx,
+ DualStageIOMMUObject *dsi_obj);
+void iommu_context_init(IOMMUContext *iommu_ctx, IOMMUContextOps *ops);
+
+#endif
--
2.7.4
- [RFC v3 04/25] hw/pci: introduce pci_device_iommu_context(), (continued)
- [RFC v3 04/25] hw/pci: introduce pci_device_iommu_context(), Liu, Yi L, 2020/01/29
- [RFC v3 09/25] vfio: check VFIO_TYPE1_NESTING_IOMMU support, Liu, Yi L, 2020/01/29
- [RFC v3 08/25] vfio: pass IOMMUContext into vfio_get_group(), Liu, Yi L, 2020/01/29
- [RFC v3 02/25] hw/iommu: introduce DualStageIOMMUObject, Liu, Yi L, 2020/01/29
- [RFC v3 07/25] header file update VFIO/IOMMU vSVA APIs, Liu, Yi L, 2020/01/29
- [RFC v3 05/25] intel_iommu: provide get_iommu_context() callback, Liu, Yi L, 2020/01/29
- [RFC v3 03/25] hw/iommu: introduce IOMMUContext,
Liu, Yi L <=
- [RFC v3 10/25] vfio: register DualStageIOMMUObject to vIOMMU, Liu, Yi L, 2020/01/29
- [RFC v3 01/25] hw/pci: modify pci_setup_iommu() to set PCIIOMMUOps, Liu, Yi L, 2020/01/29
- [RFC v3 12/25] vfio/common: add pasid_alloc/free support, Liu, Yi L, 2020/01/29
- [RFC v3 13/25] intel_iommu: modify x-scalable-mode to be string option, Liu, Yi L, 2020/01/29
- [RFC v3 11/25] vfio: get stage-1 pasid formats from Kernel, Liu, Yi L, 2020/01/29
- [RFC v3 15/25] intel_iommu: process pasid cache invalidation, Liu, Yi L, 2020/01/29
- [RFC v3 14/25] intel_iommu: add virtual command capability support, Liu, Yi L, 2020/01/29
- [RFC v3 16/25] intel_iommu: add PASID cache management infrastructure, Liu, Yi L, 2020/01/29