@samitouri / QOSamiQemu / commits / 674d57bf6e

hw/arm/smmuv3-accel: Add viommu free helper

Move viommu teardown into a helper function and use it from the last device removal path. This groups related cleanup logic in one place and improves readability. It also makes it easier to extend the teardown in future, for example when freeing related objects such as vEVENTQ. No functional change. Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Tested-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com> Message-id: 20260226084456.112142-3-skolothumtho@nvidia.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Shameer Kolothum committed Mar 6, 2026 at 09:01 UTC 674d57bf6e26a3ae7076a7ee56e6be90580d5208
1 file changed +15 -6
hw/arm/smmuv3-accel.c
+15 -6
@@ -390,6 +390,20 @@ bool smmuv3_accel_issue_inv_cmd(SMMUv3State *bs, void *cmd, SMMUDevice *sdev,
390 sizeof(Cmd), &entry_num, cmd, errp);
391 }
392
393 +static void smmuv3_accel_free_viommu(SMMUv3AccelState *accel)
394 +{
395 + IOMMUFDViommu *viommu = accel->viommu;
396 +
397 + if (!viommu) {
398 + return;
399 + }
400 + iommufd_backend_free_id(viommu->iommufd, accel->bypass_hwpt_id);
401 + iommufd_backend_free_id(viommu->iommufd, accel->abort_hwpt_id);
402 + iommufd_backend_free_id(viommu->iommufd, accel->viommu->viommu_id);
403 + g_free(viommu);
404 + accel->viommu = NULL;
405 +}
406 +
407 static bool
408 smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *idev,
409 Error **errp)
@@ -549,12 +563,7 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque,
563 trace_smmuv3_accel_unset_iommu_device(devfn, idev->devid);
564
565 if (QLIST_EMPTY(&accel->device_list)) {
552 - iommufd_backend_free_id(accel->viommu->iommufd, accel->bypass_hwpt_id);
553 - iommufd_backend_free_id(accel->viommu->iommufd, accel->abort_hwpt_id);
554 - iommufd_backend_free_id(accel->viommu->iommufd,
555 - accel->viommu->viommu_id);
556 - g_free(accel->viommu);
557 - accel->viommu = NULL;
566 + smmuv3_accel_free_viommu(accel);
567 }
568 }
569