Shameer,

Hi,

On 3/11/25 10:10 AM, Shameer Kolothum wrote:
From: Nicolin Chen <nicol...@nvidia.com>

Allocate and associate a vDEVICE object for the Guest device
with the vIOMMU. This will help the kernel to do the
vSID --> sid translation whenever required (eg: device specific
invalidations).

Signed-off-by: Nicolin Chen <nicol...@nvidia.com>
Signed-off-by: Shameer Kolothum <shameerali.kolothum.th...@huawei.com>
---
  hw/arm/smmuv3-accel.c         | 22 ++++++++++++++++++++++
  include/hw/arm/smmuv3-accel.h |  6 ++++++
  2 files changed, 28 insertions(+)

diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c
index d3a5cf9551..056bd23b2e 100644
--- a/hw/arm/smmuv3-accel.c
+++ b/hw/arm/smmuv3-accel.c
@@ -109,6 +109,20 @@ void smmuv3_accel_install_nested_ste(SMMUDevice *sdev, int 
sid)
          return;
      }
+ if (!accel_dev->vdev && accel_dev->idev) {
+        SMMUVdev *vdev;
+        uint32_t vdev_id;
+        SMMUViommu *viommu = accel_dev->viommu;
+
+        iommufd_backend_alloc_vdev(viommu->core.iommufd, 
accel_dev->idev->devid,
+                                   viommu->core.viommu_id, sid, &vdev_id,
+                                   &error_abort);
+        vdev = g_new0(SMMUVdev, 1);
+        vdev->vdev_id = vdev_id;
+        vdev->sid = sid;
+        accel_dev->vdev = vdev;
+    }
+
      ret = smmu_find_ste(sdev->smmu, sid, &ste, &event);
      if (ret) {
          /*
@@ -283,6 +297,7 @@ static bool smmuv3_accel_set_iommu_device(PCIBus *bus, void 
*opaque, int devfn,
  static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque,
                                              int devfn)
  {
+    SMMUVdev *vdev;
      SMMUDevice *sdev;
      SMMUv3AccelDevice *accel_dev;
      SMMUViommu *viommu;
@@ -312,6 +327,13 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, 
void *opaque,
      trace_smmuv3_accel_unset_iommu_device(devfn, smmu_get_sid(sdev));
viommu = s_accel->viommu;
+    vdev = accel_dev->vdev;
+    if (vdev) {
+        iommufd_backend_free_id(viommu->iommufd, vdev->vdev_id);
+        g_free(vdev);
+        accel_dev->vdev = NULL;
+    }
+
      if (QLIST_EMPTY(&viommu->device_list)) {
          iommufd_backend_free_id(viommu->iommufd, viommu->bypass_hwpt_id);
          iommufd_backend_free_id(viommu->iommufd, viommu->abort_hwpt_id);
diff --git a/include/hw/arm/smmuv3-accel.h b/include/hw/arm/smmuv3-accel.h
index d6b0b1ca30..54b217ab4f 100644
--- a/include/hw/arm/smmuv3-accel.h
+++ b/include/hw/arm/smmuv3-accel.h
@@ -35,6 +35,11 @@ typedef struct SMMUViommu {
      QLIST_ENTRY(SMMUViommu) next;
  } SMMUViommu;
+typedef struct SMMUVdev {
+    uint32_t vdev_id;
+    uint32_t sid;
+} SMMUVdev;
+
Shouldn't this be 'IOMMUFDVdev' ... it's not an SMMU (v)dev , it's an 
IOMMUFD/vIOMMU vDEVICE for this SMMU


  typedef struct SMMUS1Hwpt {
      IOMMUFDBackend *iommufd;
      uint32_t hwpt_id;
@@ -45,6 +50,7 @@ typedef struct SMMUv3AccelDevice {
      HostIOMMUDeviceIOMMUFD *idev;
      SMMUS1Hwpt  *s1_hwpt;
      SMMUViommu *viommu;
+    SMMUVdev   *vdev;
      QLIST_ENTRY(SMMUv3AccelDevice) next;
  } SMMUv3AccelDevice;


Reply via email to