[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 19/19] intel_iommu: Check compatibility with host IOMMU capabi
From: |
Zhenzhong Duan |
Subject: |
[PATCH v3 19/19] intel_iommu: Check compatibility with host IOMMU capabilities |
Date: |
Mon, 29 Apr 2024 14:50:46 +0800 |
If check fails, host device (either VFIO or VDPA device) is not
compatible with current vIOMMU config and should not be passed to
guest.
Only aw_bits is checked for now, we don't care other capabilities
before scalable modern mode is introduced.
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
hw/i386/intel_iommu.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 4f84e2e801..4a295c41cc 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3819,6 +3819,26 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s,
PCIBus *bus,
return vtd_dev_as;
}
+static int vtd_check_hdev(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hdev,
+ Error **errp)
+{
+ HostIOMMUDevice *hiod = vtd_hdev->dev;
+ int ret;
+
+ /* Common checks */
+ ret = host_iommu_device_check_cap(hiod, HOST_IOMMU_DEVICE_CAP_AW_BITS,
+ errp);
+ if (ret < 0) {
+ return ret;
+ }
+ if (s->aw_bits > ret) {
+ error_setg(errp, "aw-bits %d > host aw-bits %d", s->aw_bits, ret);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn,
HostIOMMUDevice *hiod, Error **errp)
{
@@ -3829,6 +3849,7 @@ static int vtd_dev_set_iommu_device(PCIBus *bus, void
*opaque, int devfn,
.devfn = devfn,
};
struct vtd_as_key *new_key;
+ int ret;
assert(hiod);
@@ -3848,6 +3869,13 @@ static int vtd_dev_set_iommu_device(PCIBus *bus, void
*opaque, int devfn,
vtd_hdev->iommu_state = s;
vtd_hdev->dev = hiod;
+ ret = vtd_check_hdev(s, vtd_hdev, errp);
+ if (ret) {
+ g_free(vtd_hdev);
+ vtd_iommu_unlock(s);
+ return ret;
+ }
+
new_key = g_malloc(sizeof(*new_key));
new_key->bus = bus;
new_key->devfn = devfn;
--
2.34.1
- [PATCH v3 09/19] vfio/iommufd: Implement HostIOMMUDeviceClass::realize() handler, (continued)
- [PATCH v3 09/19] vfio/iommufd: Implement HostIOMMUDeviceClass::realize() handler, Zhenzhong Duan, 2024/04/29
- [PATCH v3 12/19] vfio: Introduce VFIOIOMMUClass::hiod_typename attribute, Zhenzhong Duan, 2024/04/29
- [PATCH v3 11/19] backends/iommufd: Implement HostIOMMUDeviceClass::check_cap() handler, Zhenzhong Duan, 2024/04/29
- [PATCH v3 10/19] vfio/container: Implement HostIOMMUDeviceClass::check_cap() handler, Zhenzhong Duan, 2024/04/29
- [PATCH v3 13/19] vfio: Create host IOMMU device instance, Zhenzhong Duan, 2024/04/29
- [PATCH v3 15/19] hw/pci: Introduce pci_device_[set|unset]_iommu_device(), Zhenzhong Duan, 2024/04/29
- [PATCH v3 14/19] hw/pci: Introduce helper function pci_device_get_iommu_bus_devfn(), Zhenzhong Duan, 2024/04/29
- [PATCH v3 17/19] intel_iommu: Extract out vtd_cap_init() to initialize cap/ecap, Zhenzhong Duan, 2024/04/29
- [PATCH v3 16/19] vfio/pci: Pass HostIOMMUDevice to vIOMMU, Zhenzhong Duan, 2024/04/29
- [PATCH v3 18/19] intel_iommu: Implement [set|unset]_iommu_device() callbacks, Zhenzhong Duan, 2024/04/29
- [PATCH v3 19/19] intel_iommu: Check compatibility with host IOMMU capabilities,
Zhenzhong Duan <=