Same for the two wrappers and their call sites.
Suggested-by: Shameer Kolothum Thodi <skolothumtho@nvidia.com>
Suggested-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Yi Liu <yi.l.liu@intel.com>
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Tested-by: Xudong Hao <xudong.hao@intel.com>
---
include/system/iommufd.h | 16 +++++++++++-----
backends/iommufd.c | 9 +++++----
hw/arm/smmuv3-accel.c | 12 ++++++++----
hw/i386/intel_iommu_accel.c | 19 ++++++++++---------
hw/vfio/iommufd.c | 10 +++++-----
5 files changed, 39 insertions(+), 27 deletions(-)
diff --git a/include/system/iommufd.h b/include/system/iommufd.h
index 2925d116ac..da98e79439 100644
--- a/include/system/iommufd.h
+++ b/include/system/iommufd.h
@@ -138,14 +138,16 @@ struct HostIOMMUDeviceIOMMUFDClass {
*
* @hiodi: host IOMMU device backed by IOMMUFD backend.
*
+ * @pasid: target pasid of the device to be attached.
+ *
* @hwpt_id: ID of IOMMUFD hardware page table.
*
* @errp: pass an Error out when attachment fails.
*
* Returns: true on success, false on failure.
*/
- bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t hwpt_id,
- Error **errp);
+ bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t pasid,
+ uint32_t hwpt_id, Error **errp);
/**
* @detach_hwpt: detach host IOMMU device from IOMMUFD hardware page table.
* VFIO and VDPA device can have different implementation.
@@ -154,15 +156,19 @@ struct HostIOMMUDeviceIOMMUFDClass {
*
* @hiodi: host IOMMU device backed by IOMMUFD backend.
*
+ * @pasid: target pasid of the device to be detached.
+ *
* @errp: pass an Error out when attachment fails.
*
* Returns: true on success, false on failure.
*/
- bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, Error **errp);
+ bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t pasid,
+ Error **errp);
};
bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
- uint32_t hwpt_id, Error **errp);
-bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
+ uint32_t pasid, uint32_t hwpt_id,
Error **errp);
+bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
+ uint32_t pasid, Error **errp);
#endif
diff --git a/backends/iommufd.c b/backends/iommufd.c
index 410b044370..cfde6f2b2c 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -539,23 +539,24 @@ bool iommufd_backend_alloc_veventq(IOMMUFDBackend *be, uint32_t viommu_id,
}
bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
- uint32_t hwpt_id, Error **errp)
+ uint32_t pasid, uint32_t hwpt_id,
+ Error **errp)
{
HostIOMMUDeviceIOMMUFDClass *hiodic =
HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi);
g_assert(hiodic->attach_hwpt);
- return hiodic->attach_hwpt(hiodi, hwpt_id, errp);
+ return hiodic->attach_hwpt(hiodi, pasid, hwpt_id, errp);
}
bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
- Error **errp)
+ uint32_t pasid, Error **errp)
{
HostIOMMUDeviceIOMMUFDClass *hiodic =
HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi);
g_assert(hiodic->detach_hwpt);
- return hiodic->detach_hwpt(hiodi, errp);
+ return hiodic->detach_hwpt(hiodi, pasid, errp);
}
static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c
index 3630078751..3201bb25af 100644
--- a/hw/arm/smmuv3-accel.c
+++ b/hw/arm/smmuv3-accel.c
@@ -300,7 +300,8 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid,
return false;
}
- if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) {
+ if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt_id,
+ errp)) {
if (s1_hwpt) {
iommufd_backend_free_id(hiodi->iommufd, s1_hwpt->hwpt_id);
g_free(s1_hwpt);
@@ -575,7 +576,8 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *hiodi,
/* Attach a HWPT based on SMMUv3 GBPA.ABORT value */
hwpt_id = smmuv3_accel_gbpa_hwpt(s, accel);
- if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) {
+ if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt_id,
+ errp)) {
goto free_veventq;
}
return true;
@@ -665,7 +667,8 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque,
hiodi = accel_dev->hiodi;
accel = accel_dev->s_accel;
/* Re-attach the default s2 hwpt id */
- if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_id, NULL)) {
+ if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID,
+ hiodi->hwpt_id, NULL)) {
error_report("Unable to attach the default HW pagetable: hiodi devid "
"0x%x", hiodi->devid);
}
@@ -879,7 +882,8 @@ bool smmuv3_accel_attach_gbpa_hwpt(SMMUv3State *s, Error **errp)
hwpt_id = smmuv3_accel_gbpa_hwpt(s, accel);
QLIST_FOREACH(accel_dev, &accel->device_list, next) {
- if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi, hwpt_id,
+ if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi,
+ IOMMU_NO_PASID, hwpt_id,
&local_err)) {
error_append_hint(&local_err, "Failed to attach GBPA hwpt %u for "
"hiodi devid %u", hwpt_id,
diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c
index ed3793602b..3217a2afac 100644
--- a/hw/i386/intel_iommu_accel.c
+++ b/hw/i386/intel_iommu_accel.c
@@ -121,8 +121,9 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
}
}
- ret = host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp);
- trace_vtd_device_attach_hwpt(hiodi->devid, vtd_as->pasid, hwpt_id, ret);
+ ret = host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt_id,
+ errp);
+ trace_vtd_device_attach_hwpt(hiodi->devid, IOMMU_NO_PASID, hwpt_id, ret);
if (ret) {
/* Destroy old fs_hwpt if it's a replacement */
vtd_destroy_old_fs_hwpt(hiodi, vtd_as);
@@ -141,22 +142,22 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
{
HostIOMMUDeviceIOMMUFD *hiodi = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);
IntelIOMMUState *s = vtd_as->iommu_state;
- uint32_t pasid = vtd_as->pasid;
bool ret;
if (s->dmar_enabled && s->root_scalable) {
- ret = host_iommu_device_iommufd_detach_hwpt(hiodi, errp);
- trace_vtd_device_detach_hwpt(hiodi->devid, pasid, ret);
+ ret = host_iommu_device_iommufd_detach_hwpt(hiodi, IOMMU_NO_PASID,
+ errp);
+ trace_vtd_device_detach_hwpt(hiodi->devid, IOMMU_NO_PASID, ret);
} else {
/*
* If DMAR remapping is disabled or guest switches to legacy mode,
* we fallback to the default HWPT which contains shadow page table.
* So guest DMA could still work.
*/
- ret = host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_id,
- errp);
- trace_vtd_device_reattach_def_hwpt(hiodi->devid, pasid, hiodi->hwpt_id,
- ret);
+ ret = host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID,
+ hiodi->hwpt_id, errp);
+ trace_vtd_device_reattach_def_hwpt(hiodi->devid, IOMMU_NO_PASID,
+ hiodi->hwpt_id, ret);
}
if (ret) {
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index f020b56208..ecabc33064 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -927,21 +927,21 @@ static void vfio_iommu_iommufd_class_init(ObjectClass *klass, const void *data)
static bool
host_iommu_device_iommufd_vfio_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
- uint32_t hwpt_id, Error **errp)
+ uint32_t pasid, uint32_t hwpt_id,
+ Error **errp)
{
VFIODevice *vbasedev = HOST_IOMMU_DEVICE(hiodi)->agent;
- return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, IOMMU_NO_PASID,
- hwpt_id, errp);
+ return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, pasid, hwpt_id, errp);
}
static bool
host_iommu_device_iommufd_vfio_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
- Error **errp)
+ uint32_t pasid, Error **errp)
{
VFIODevice *vbasedev = HOST_IOMMU_DEVICE(hiodi)->agent;
- return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, errp);
+ return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, pasid, errp);
}
static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque,
--
2.47.3
On 4/3/26 05:55, Zhenzhong Duan wrote:
> Same for the two wrappers and their call sites.
>
> Suggested-by: Shameer Kolothum Thodi <skolothumtho@nvidia.com>
> Suggested-by: Nicolin Chen <nicolinc@nvidia.com>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> Reviewed-by: Yi Liu <yi.l.liu@intel.com>
> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
> Tested-by: Xudong Hao <xudong.hao@intel.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Thanks,
C.
> ---
> include/system/iommufd.h | 16 +++++++++++-----
> backends/iommufd.c | 9 +++++----
> hw/arm/smmuv3-accel.c | 12 ++++++++----
> hw/i386/intel_iommu_accel.c | 19 ++++++++++---------
> hw/vfio/iommufd.c | 10 +++++-----
> 5 files changed, 39 insertions(+), 27 deletions(-)
>
> diff --git a/include/system/iommufd.h b/include/system/iommufd.h
> index 2925d116ac..da98e79439 100644
> --- a/include/system/iommufd.h
> +++ b/include/system/iommufd.h
> @@ -138,14 +138,16 @@ struct HostIOMMUDeviceIOMMUFDClass {
> *
> * @hiodi: host IOMMU device backed by IOMMUFD backend.
> *
> + * @pasid: target pasid of the device to be attached.
> + *
> * @hwpt_id: ID of IOMMUFD hardware page table.
> *
> * @errp: pass an Error out when attachment fails.
> *
> * Returns: true on success, false on failure.
> */
> - bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t hwpt_id,
> - Error **errp);
> + bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t pasid,
> + uint32_t hwpt_id, Error **errp);
> /**
> * @detach_hwpt: detach host IOMMU device from IOMMUFD hardware page table.
> * VFIO and VDPA device can have different implementation.
> @@ -154,15 +156,19 @@ struct HostIOMMUDeviceIOMMUFDClass {
> *
> * @hiodi: host IOMMU device backed by IOMMUFD backend.
> *
> + * @pasid: target pasid of the device to be detached.
> + *
> * @errp: pass an Error out when attachment fails.
> *
> * Returns: true on success, false on failure.
> */
> - bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, Error **errp);
> + bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t pasid,
> + Error **errp);
> };
>
> bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
> - uint32_t hwpt_id, Error **errp);
> -bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
> + uint32_t pasid, uint32_t hwpt_id,
> Error **errp);
> +bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
> + uint32_t pasid, Error **errp);
> #endif
> diff --git a/backends/iommufd.c b/backends/iommufd.c
> index 410b044370..cfde6f2b2c 100644
> --- a/backends/iommufd.c
> +++ b/backends/iommufd.c
> @@ -539,23 +539,24 @@ bool iommufd_backend_alloc_veventq(IOMMUFDBackend *be, uint32_t viommu_id,
> }
>
> bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
> - uint32_t hwpt_id, Error **errp)
> + uint32_t pasid, uint32_t hwpt_id,
> + Error **errp)
> {
> HostIOMMUDeviceIOMMUFDClass *hiodic =
> HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi);
>
> g_assert(hiodic->attach_hwpt);
> - return hiodic->attach_hwpt(hiodi, hwpt_id, errp);
> + return hiodic->attach_hwpt(hiodi, pasid, hwpt_id, errp);
> }
>
> bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
> - Error **errp)
> + uint32_t pasid, Error **errp)
> {
> HostIOMMUDeviceIOMMUFDClass *hiodic =
> HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi);
>
> g_assert(hiodic->detach_hwpt);
> - return hiodic->detach_hwpt(hiodi, errp);
> + return hiodic->detach_hwpt(hiodi, pasid, errp);
> }
>
> static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
> diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c
> index 3630078751..3201bb25af 100644
> --- a/hw/arm/smmuv3-accel.c
> +++ b/hw/arm/smmuv3-accel.c
> @@ -300,7 +300,8 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid,
> return false;
> }
>
> - if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) {
> + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt_id,
> + errp)) {
> if (s1_hwpt) {
> iommufd_backend_free_id(hiodi->iommufd, s1_hwpt->hwpt_id);
> g_free(s1_hwpt);
> @@ -575,7 +576,8 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *hiodi,
>
> /* Attach a HWPT based on SMMUv3 GBPA.ABORT value */
> hwpt_id = smmuv3_accel_gbpa_hwpt(s, accel);
> - if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) {
> + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt_id,
> + errp)) {
> goto free_veventq;
> }
> return true;
> @@ -665,7 +667,8 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque,
> hiodi = accel_dev->hiodi;
> accel = accel_dev->s_accel;
> /* Re-attach the default s2 hwpt id */
> - if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_id, NULL)) {
> + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID,
> + hiodi->hwpt_id, NULL)) {
> error_report("Unable to attach the default HW pagetable: hiodi devid "
> "0x%x", hiodi->devid);
> }
> @@ -879,7 +882,8 @@ bool smmuv3_accel_attach_gbpa_hwpt(SMMUv3State *s, Error **errp)
>
> hwpt_id = smmuv3_accel_gbpa_hwpt(s, accel);
> QLIST_FOREACH(accel_dev, &accel->device_list, next) {
> - if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi, hwpt_id,
> + if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi,
> + IOMMU_NO_PASID, hwpt_id,
> &local_err)) {
> error_append_hint(&local_err, "Failed to attach GBPA hwpt %u for "
> "hiodi devid %u", hwpt_id,
> diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c
> index ed3793602b..3217a2afac 100644
> --- a/hw/i386/intel_iommu_accel.c
> +++ b/hw/i386/intel_iommu_accel.c
> @@ -121,8 +121,9 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
> }
> }
>
> - ret = host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp);
> - trace_vtd_device_attach_hwpt(hiodi->devid, vtd_as->pasid, hwpt_id, ret);
> + ret = host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt_id,
> + errp);
> + trace_vtd_device_attach_hwpt(hiodi->devid, IOMMU_NO_PASID, hwpt_id, ret);
> if (ret) {
> /* Destroy old fs_hwpt if it's a replacement */
> vtd_destroy_old_fs_hwpt(hiodi, vtd_as);
> @@ -141,22 +142,22 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
> {
> HostIOMMUDeviceIOMMUFD *hiodi = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);
> IntelIOMMUState *s = vtd_as->iommu_state;
> - uint32_t pasid = vtd_as->pasid;
> bool ret;
>
> if (s->dmar_enabled && s->root_scalable) {
> - ret = host_iommu_device_iommufd_detach_hwpt(hiodi, errp);
> - trace_vtd_device_detach_hwpt(hiodi->devid, pasid, ret);
> + ret = host_iommu_device_iommufd_detach_hwpt(hiodi, IOMMU_NO_PASID,
> + errp);
> + trace_vtd_device_detach_hwpt(hiodi->devid, IOMMU_NO_PASID, ret);
> } else {
> /*
> * If DMAR remapping is disabled or guest switches to legacy mode,
> * we fallback to the default HWPT which contains shadow page table.
> * So guest DMA could still work.
> */
> - ret = host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_id,
> - errp);
> - trace_vtd_device_reattach_def_hwpt(hiodi->devid, pasid, hiodi->hwpt_id,
> - ret);
> + ret = host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID,
> + hiodi->hwpt_id, errp);
> + trace_vtd_device_reattach_def_hwpt(hiodi->devid, IOMMU_NO_PASID,
> + hiodi->hwpt_id, ret);
> }
>
> if (ret) {
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index f020b56208..ecabc33064 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -927,21 +927,21 @@ static void vfio_iommu_iommufd_class_init(ObjectClass *klass, const void *data)
>
> static bool
> host_iommu_device_iommufd_vfio_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
> - uint32_t hwpt_id, Error **errp)
> + uint32_t pasid, uint32_t hwpt_id,
> + Error **errp)
> {
> VFIODevice *vbasedev = HOST_IOMMU_DEVICE(hiodi)->agent;
>
> - return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, IOMMU_NO_PASID,
> - hwpt_id, errp);
> + return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, pasid, hwpt_id, errp);
> }
>
> static bool
> host_iommu_device_iommufd_vfio_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
> - Error **errp)
> + uint32_t pasid, Error **errp)
> {
> VFIODevice *vbasedev = HOST_IOMMU_DEVICE(hiodi)->agent;
>
> - return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, errp);
> + return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, pasid, errp);
> }
>
> static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque,
© 2016 - 2026 Red Hat, Inc.