[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v3 17/25] vfio: add bind stage-1 page table support
From: |
Liu, Yi L |
Subject: |
[RFC v3 17/25] vfio: add bind stage-1 page table support |
Date: |
Wed, 29 Jan 2020 04:16:48 -0800 |
From: Liu Yi L <address@hidden>
This patch adds bind_stage1_pgtbl() definition in DualStageIOMMUOops,
also adds corresponding implementation in VFIO. This is to expose a
way for vIOMMU to setup dual stage DMA translation for passthru devices
on hardware.
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>
Cc: Alex Williamson <address@hidden>
Signed-off-by: Liu Yi L <address@hidden>
---
hw/iommu/dual_stage_iommu.c | 26 ++++++++++++++++++++
hw/vfio/common.c | 48 +++++++++++++++++++++++++++++++++++++
include/hw/iommu/dual_stage_iommu.h | 22 +++++++++++++++++
3 files changed, 96 insertions(+)
diff --git a/hw/iommu/dual_stage_iommu.c b/hw/iommu/dual_stage_iommu.c
index d5a7168..9d99e9e 100644
--- a/hw/iommu/dual_stage_iommu.c
+++ b/hw/iommu/dual_stage_iommu.c
@@ -47,6 +47,32 @@ int ds_iommu_pasid_free(DualStageIOMMUObject *dsi_obj,
uint32_t pasid)
return -ENOENT;
}
+int ds_iommu_bind_stage1_pgtbl(DualStageIOMMUObject *dsi_obj,
+ DualIOMMUStage1BindData *data)
+{
+ if (!dsi_obj) {
+ return -ENOENT;
+ }
+
+ if (dsi_obj->ops && dsi_obj->ops->bind_stage1_pgtbl) {
+ return dsi_obj->ops->bind_stage1_pgtbl(dsi_obj, data);
+ }
+ return -ENOENT;
+}
+
+int ds_iommu_unbind_stage1_pgtbl(DualStageIOMMUObject *dsi_obj,
+ DualIOMMUStage1BindData *data)
+{
+ if (!dsi_obj) {
+ return -ENOENT;
+ }
+
+ if (dsi_obj->ops && dsi_obj->ops->unbind_stage1_pgtbl) {
+ return dsi_obj->ops->unbind_stage1_pgtbl(dsi_obj, data);
+ }
+ return -ENOENT;
+}
+
void ds_iommu_object_init(DualStageIOMMUObject *dsi_obj,
DualStageIOMMUOps *ops,
DualStageIOMMUInfo *uinfo)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 014f4e7..d84bdc9 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1219,9 +1219,57 @@ static int vfio_ds_iommu_pasid_free(DualStageIOMMUObject
*dsi_obj,
return 0;
}
+static int vfio_ds_iommu_bind_stage1_pgtbl(DualStageIOMMUObject *dsi_obj,
+ DualIOMMUStage1BindData *bind_data)
+{
+ VFIOContainer *container = container_of(dsi_obj, VFIOContainer, dsi_obj);
+ struct vfio_iommu_type1_bind *bind;
+ unsigned long argsz;
+ int ret = 0;
+
+ argsz = sizeof(*bind) + sizeof(bind_data->bind_data);
+ bind = g_malloc0(argsz);
+ bind->argsz = argsz;
+ bind->flags = VFIO_IOMMU_BIND_GUEST_PGTBL;
+ memcpy(&bind->data, &bind_data->bind_data, sizeof(bind_data->bind_data));
+
+ if (ioctl(container->fd, VFIO_IOMMU_BIND, bind)) {
+ error_report("%s: pasid (%u) bind failed: %d",
+ __func__, bind_data->pasid, -errno);
+ ret = -errno;
+ }
+ g_free(bind);
+ return ret;
+}
+
+static int vfio_ds_iommu_unbind_stage1_pgtbl(DualStageIOMMUObject *dsi_obj,
+ DualIOMMUStage1BindData *bind_data)
+{
+ VFIOContainer *container = container_of(dsi_obj, VFIOContainer, dsi_obj);
+ struct vfio_iommu_type1_bind *bind;
+ unsigned long argsz;
+ int ret = 0;
+
+ argsz = sizeof(*bind) + sizeof(bind_data->bind_data);
+ bind = g_malloc0(argsz);
+ bind->argsz = argsz;
+ bind->flags = VFIO_IOMMU_UNBIND_GUEST_PGTBL;
+ memcpy(&bind->data, &bind_data->bind_data, sizeof(bind_data->bind_data));
+
+ if (ioctl(container->fd, VFIO_IOMMU_BIND, bind)) {
+ error_report("%s: pasid (%u) unbind failed: %d",
+ __func__, bind_data->pasid, -errno);
+ ret = -errno;
+ }
+ g_free(bind);
+ return ret;
+}
+
static struct DualStageIOMMUOps vfio_ds_iommu_ops = {
.pasid_alloc = vfio_ds_iommu_pasid_alloc,
.pasid_free = vfio_ds_iommu_pasid_free,
+ .bind_stage1_pgtbl = vfio_ds_iommu_bind_stage1_pgtbl,
+ .unbind_stage1_pgtbl = vfio_ds_iommu_unbind_stage1_pgtbl,
};
static int vfio_get_iommu_info(VFIOContainer *container,
diff --git a/include/hw/iommu/dual_stage_iommu.h
b/include/hw/iommu/dual_stage_iommu.h
index c6100b4..0eb983c 100644
--- a/include/hw/iommu/dual_stage_iommu.h
+++ b/include/hw/iommu/dual_stage_iommu.h
@@ -31,6 +31,7 @@
typedef struct DualStageIOMMUObject DualStageIOMMUObject;
typedef struct DualStageIOMMUOps DualStageIOMMUOps;
typedef struct DualStageIOMMUInfo DualStageIOMMUInfo;
+typedef struct DualIOMMUStage1BindData DualIOMMUStage1BindData;
struct DualStageIOMMUOps {
/* Allocate pasid from DualStageIOMMU (a.k.a. host IOMMU) */
@@ -41,6 +42,16 @@ struct DualStageIOMMUOps {
/* Reclaim a pasid from DualStageIOMMU (a.k.a. host IOMMU) */
int (*pasid_free)(DualStageIOMMUObject *dsi_obj,
uint32_t pasid);
+ /*
+ * Bind stage-1 page table to a DualStageIOMMU (a.k.a. host
+ * IOMMU which has dual stage DMA translation capability.
+ * @bind_data specifies the bind configurations.
+ */
+ int (*bind_stage1_pgtbl)(DualStageIOMMUObject *dsi_obj,
+ DualIOMMUStage1BindData *bind_data);
+ /* Undo a previous bind. @bind_data specifies the unbind info. */
+ int (*unbind_stage1_pgtbl)(DualStageIOMMUObject *dsi_obj,
+ DualIOMMUStage1BindData *bind_data);
};
struct DualStageIOMMUInfo {
@@ -55,9 +66,20 @@ struct DualStageIOMMUObject {
DualStageIOMMUInfo uinfo;
};
+struct DualIOMMUStage1BindData {
+ uint32_t pasid;
+ union {
+ struct iommu_gpasid_bind_data gpasid_bind;
+ } bind_data;
+};
+
int ds_iommu_pasid_alloc(DualStageIOMMUObject *dsi_obj, uint32_t min,
uint32_t max, uint32_t *pasid);
int ds_iommu_pasid_free(DualStageIOMMUObject *dsi_obj, uint32_t pasid);
+int ds_iommu_bind_stage1_pgtbl(DualStageIOMMUObject *dsi_obj,
+ DualIOMMUStage1BindData *bind_data);
+int ds_iommu_unbind_stage1_pgtbl(DualStageIOMMUObject *dsi_obj,
+ DualIOMMUStage1BindData *bind_data);
void ds_iommu_object_init(DualStageIOMMUObject *dsi_obj,
DualStageIOMMUOps *ops,
--
2.7.4
- [RFC v3 05/25] intel_iommu: provide get_iommu_context() callback, (continued)
- [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, 2020/01/29
- [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
- [RFC v3 17/25] vfio: add bind stage-1 page table support,
Liu, Yi L <=
- [RFC v3 18/25] intel_iommu: bind/unbind guest page table to host, Liu, Yi L, 2020/01/29
- [RFC v3 19/25] intel_iommu: replay guest pasid bindings to host, Liu, Yi L, 2020/01/29
- [RFC v3 20/25] intel_iommu: replay pasid binds after context cache invalidation, Liu, Yi L, 2020/01/29
- [RFC v3 22/25] vfio: add support for flush iommu stage-1 cache, Liu, Yi L, 2020/01/29
- [RFC v3 21/25] intel_iommu: do not pass down pasid bind for PASID #0, Liu, Yi L, 2020/01/29
- [RFC v3 23/25] intel_iommu: process PASID-based iotlb invalidation, Liu, Yi L, 2020/01/29
- [RFC v3 24/25] intel_iommu: propagate PASID-based iotlb invalidation to host, Liu, Yi L, 2020/01/29
- [RFC v3 25/25] intel_iommu: process PASID-based Device-TLB invalidation, Liu, Yi L, 2020/01/29
- Re: [RFC v3 00/25] intel_iommu: expose Shared Virtual Addressing to VMs, no-reply, 2020/01/29
- Re: [RFC v3 00/25] intel_iommu: expose Shared Virtual Addressing to VMs, no-reply, 2020/01/29