[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 5/5] intel_iommu: Check for compatibility with iommufd backed
|
From: |
Zhenzhong Duan |
|
Subject: |
[PATCH v2 5/5] intel_iommu: Check for compatibility with iommufd backed device |
|
Date: |
Mon, 8 Apr 2024 16:44:04 +0800 |
Currently only stage-2 translation is supported which is backed by
shadow page table on host side. So we don't need exact matching of
each bit of cap/ecap between vIOMMU and host. However, we can still
ensure compatibility of host and vIOMMU's address width at least,
i.e., vIOMMU's aw-bits <= host IOMMU aw-bits, which is missed before.
When stage-1 translation is supported in future, a.k.a. scalable
modern mode, this mechanism will be further extended to check more
bits.
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
include/hw/i386/intel_iommu.h | 1 +
hw/i386/intel_iommu.c | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h
index bbc7b96add..2bbde41e45 100644
--- a/include/hw/i386/intel_iommu.h
+++ b/include/hw/i386/intel_iommu.h
@@ -47,6 +47,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(IntelIOMMUState,
INTEL_IOMMU_DEVICE)
#define VTD_HOST_AW_48BIT 48
#define VTD_HOST_ADDRESS_WIDTH VTD_HOST_AW_39BIT
#define VTD_HAW_MASK(aw) ((1ULL << (aw)) - 1)
+#define VTD_MGAW_FROM_CAP(cap) ((cap >> 16) & 0x3fULL)
#define DMAR_REPORT_F_INTR (1)
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index d2cd186df0..d8fac9ef9f 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3846,6 +3846,29 @@ static int vtd_check_iommufd_hdev(IntelIOMMUState *s,
HostIOMMUDevice *hiod,
Error **errp)
{
+ HostIOMMUDeviceClass *hiodc = HOST_IOMMU_DEVICE_GET_CLASS(hiod);
+ struct iommu_hw_info_vtd *vtd;
+ HIOD_IOMMUFD_INFO info;
+ int host_aw_bits, ret;
+
+ ret = hiodc->get_host_iommu_info(hiod, &info, sizeof(info), errp);
+ if (ret) {
+ return ret;
+ }
+
+ if (info.type != IOMMU_HW_INFO_TYPE_INTEL_VTD) {
+ error_setg(errp, "IOMMU hardware is not compatible");
+ return -EINVAL;
+ }
+
+ vtd = &info.data.vtd;
+ host_aw_bits = VTD_MGAW_FROM_CAP(vtd->cap_reg) + 1;
+ if (s->aw_bits > host_aw_bits) {
+ error_setg(errp, "aw-bits %d > host aw-bits %d",
+ s->aw_bits, host_aw_bits);
+ return -EINVAL;
+ }
+
return 0;
}
--
2.34.1
- RE: [PATCH v2 3/5] intel_iommu: Add a framework to do compatibility check with host IOMMU cap/ecap, (continued)
- RE: [PATCH v2 3/5] intel_iommu: Add a framework to do compatibility check with host IOMMU cap/ecap, Duan, Zhenzhong, 2024/04/17
- Re: [PATCH v2 3/5] intel_iommu: Add a framework to do compatibility check with host IOMMU cap/ecap, Cédric Le Goater, 2024/04/18
- RE: [PATCH v2 3/5] intel_iommu: Add a framework to do compatibility check with host IOMMU cap/ecap, Duan, Zhenzhong, 2024/04/18
- Re: [PATCH v2 3/5] intel_iommu: Add a framework to do compatibility check with host IOMMU cap/ecap, Cédric Le Goater, 2024/04/19
- RE: [PATCH v2 3/5] intel_iommu: Add a framework to do compatibility check with host IOMMU cap/ecap, Duan, Zhenzhong, 2024/04/19
- RE: [PATCH v2 3/5] intel_iommu: Add a framework to do compatibility check with host IOMMU cap/ecap, Duan, Zhenzhong, 2024/04/25
- Re: [PATCH v2 3/5] intel_iommu: Add a framework to do compatibility check with host IOMMU cap/ecap, Cédric Le Goater, 2024/04/25
- RE: [PATCH v2 3/5] intel_iommu: Add a framework to do compatibility check with host IOMMU cap/ecap, Duan, Zhenzhong, 2024/04/25
[PATCH v2 2/5] intel_iommu: Implement set/unset_iommu_device() callback, Zhenzhong Duan, 2024/04/08
[PATCH v2 4/5] intel_iommu: Check for compatibility with legacy device, Zhenzhong Duan, 2024/04/08
[PATCH v2 5/5] intel_iommu: Check for compatibility with iommufd backed device,
Zhenzhong Duan <=