On 7/29/25 11:20, Zhenzhong Duan wrote:
Call pci_device_get_viommu_cap() to get if vIOMMU supports VIOMMU_CAP_HW_NESTED,
if yes, create nested parent domain which could be reused by vIOMMU to create
nested domain.
It is safe because hw_caps & VIOMMU_CAP_HW_NESTED cannot be set yet because
s->flts is forbidden until we support passthrough device with x-flts=on.
Suggested-by: Nicolin Chen <[email protected]>
Suggested-by: Yi Liu <[email protected]>
Signed-off-by: Zhenzhong Duan <[email protected]>
Reviewed-by: Eric Auger <[email protected]>
---
hw/vfio/iommufd.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 48c590b6a9..61a548f13f 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -20,6 +20,7 @@
#include "trace.h"
#include "qapi/error.h"
#include "system/iommufd.h"
+#include "hw/iommu.h"
#include "hw/qdev-core.h"
#include "hw/vfio/vfio-cpr.h"
#include "system/reset.h"
@@ -379,6 +380,19 @@ static bool iommufd_cdev_autodomains_get(VFIODevice
*vbasedev,
flags = IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
}
+ /*
+ * If vIOMMU supports stage-1 translation, force to create nested parent
+ * domain which could be reused by vIOMMU to create nested domain.
+ */
+ if (vbasedev->type == VFIO_DEVICE_TYPE_PCI) {
+ VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
+
+ hw_caps = pci_device_get_viommu_cap(&vdev->pdev);
+ if (hw_caps & VIOMMU_CAP_HW_NESTED) {
+ flags |= IOMMU_HWPT_ALLOC_NEST_PARENT;
+ }
+ }
Could you please add a wrapper for the above ? Something like :
static bool vfio_device_viommu_get_nested(VFIODevice *vbasedev)
{
if (vbasedev->type == VFIO_DEVICE_TYPE_PCI) {
VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
return !!(pci_device_get_viommu_cap(&vdev->pdev) &
VIOMMU_CAP_HW_NESTED);
}
return false;
}
May be this routine belongs to hw/vfio/device.c.
Thanks,
C.
if (cpr_is_incoming()) {
hwpt_id = vbasedev->cpr.hwpt_id;
goto skip_alloc;