From: Nicolin Chen <nicolinc@nvidia.com>
To: <jgg@nvidia.com>, <kevin.tian@intel.com>
Cc: <will@kernel.org>, <robin.murphy@arm.com>, <joro@8bytes.org>,
<praan@google.com>, <yi.l.liu@intel.com>, <peterz@infradead.org>,
<jsnitsel@redhat.com>, <linux-arm-kernel@lists.infradead.org>,
<iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
<patches@lists.linux.dev>, <baolu.lu@linux.intel.com>
Subject: [PATCH v2 14/14] iommufd: Apply the new iommufd_object_alloc_ucmd helper
Date: Fri, 13 Jun 2025 23:35:26 -0700 [thread overview]
Message-ID: <107b24a3b791091bb09c92ffb0081c56c413b26d.1749882255.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1749882255.git.nicolinc@nvidia.com>
Now the new ucmd-based object allocator eases the finalize/abort routine,
apply this to all existing allocators that aren't protected by any lock.
Upgrade the for-driver vIOMMU alloctor too, and pass down to all existing
viommu_alloc op accordingly.
Note that __iommufd_object_alloc_ucmd() builds in some static tests that
cover both static_asserts in the iommufd_viommu_alloc(). Thus drop them.
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/iommufd/eventq.c | 14 ++++----------
drivers/iommu/iommufd/viommu.c | 24 ++++++------------------
2 files changed, 10 insertions(+), 28 deletions(-)
diff --git a/drivers/iommu/iommufd/eventq.c b/drivers/iommu/iommufd/eventq.c
index e373b9eec7f5..fc4de63b0bce 100644
--- a/drivers/iommu/iommufd/eventq.c
+++ b/drivers/iommu/iommufd/eventq.c
@@ -427,8 +427,8 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
if (cmd->flags)
return -EOPNOTSUPP;
- fault = __iommufd_object_alloc(ucmd->ictx, fault, IOMMUFD_OBJ_FAULT,
- common.obj);
+ fault = __iommufd_object_alloc_ucmd(ucmd, fault, IOMMUFD_OBJ_FAULT,
+ common.obj);
if (IS_ERR(fault))
return PTR_ERR(fault);
@@ -437,10 +437,8 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
fdno = iommufd_eventq_init(&fault->common, "[iommufd-pgfault]",
ucmd->ictx, &iommufd_fault_fops);
- if (fdno < 0) {
- rc = fdno;
- goto out_abort;
- }
+ if (fdno < 0)
+ return fdno;
cmd->out_fault_id = fault->common.obj.id;
cmd->out_fault_fd = fdno;
@@ -448,7 +446,6 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
if (rc)
goto out_put_fdno;
- iommufd_object_finalize(ucmd->ictx, &fault->common.obj);
fd_install(fdno, fault->common.filep);
@@ -456,9 +453,6 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
out_put_fdno:
put_unused_fd(fdno);
fput(fault->common.filep);
-out_abort:
- iommufd_object_abort_and_destroy(ucmd->ictx, &fault->common.obj);
-
return rc;
}
diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
index 044e3ef06e0f..25ac08fbb52a 100644
--- a/drivers/iommu/iommufd/viommu.c
+++ b/drivers/iommu/iommufd/viommu.c
@@ -63,8 +63,8 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
goto out_put_hwpt;
}
- viommu = (struct iommufd_viommu *)_iommufd_object_alloc(
- ucmd->ictx, viommu_size, IOMMUFD_OBJ_VIOMMU);
+ viommu = (struct iommufd_viommu *)_iommufd_object_alloc_ucmd(
+ ucmd, viommu_size, IOMMUFD_OBJ_VIOMMU);
if (IS_ERR(viommu)) {
rc = PTR_ERR(viommu);
goto out_put_hwpt;
@@ -86,23 +86,17 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
rc = ops->viommu_init(viommu, hwpt_paging->common.domain);
if (rc)
- goto out_abort;
+ goto out_put_hwpt;
/* It is a driver bug that viommu->ops isn't filled */
if (WARN_ON_ONCE(!viommu->ops)) {
rc = -EOPNOTSUPP;
- goto out_abort;
+ goto out_put_hwpt;
}
cmd->out_viommu_id = viommu->obj.id;
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
- if (rc)
- goto out_abort;
- iommufd_object_finalize(ucmd->ictx, &viommu->obj);
- goto out_put_hwpt;
-out_abort:
- iommufd_object_abort_and_destroy(ucmd->ictx, &viommu->obj);
out_put_hwpt:
iommufd_put_object(ucmd->ictx, &hwpt_paging->common.obj);
out_put_idev:
@@ -150,7 +144,7 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd)
goto out_put_idev;
}
- vdev = iommufd_object_alloc(ucmd->ictx, vdev, IOMMUFD_OBJ_VDEVICE);
+ vdev = iommufd_object_alloc_ucmd(ucmd, vdev, IOMMUFD_OBJ_VDEVICE);
if (IS_ERR(vdev)) {
rc = PTR_ERR(vdev);
goto out_put_idev;
@@ -165,18 +159,12 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd)
curr = xa_cmpxchg(&viommu->vdevs, virt_id, NULL, vdev, GFP_KERNEL);
if (curr) {
rc = xa_err(curr) ?: -EEXIST;
- goto out_abort;
+ goto out_put_idev;
}
cmd->out_vdevice_id = vdev->obj.id;
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
- if (rc)
- goto out_abort;
- iommufd_object_finalize(ucmd->ictx, &vdev->obj);
- goto out_put_idev;
-out_abort:
- iommufd_object_abort_and_destroy(ucmd->ictx, &vdev->obj);
out_put_idev:
iommufd_put_object(ucmd->ictx, &idev->obj);
out_put_viommu:
--
2.43.0
next prev parent reply other threads:[~2025-06-14 7:08 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-14 6:35 [PATCH v2 00/14] iommufd: Prepare for IOMMUFD_OBJ_HW_QUEUE Nicolin Chen
2025-06-14 6:35 ` [PATCH v2 01/14] iommufd: Apply obvious cosmetic fixes Nicolin Chen
2025-06-16 3:23 ` Baolu Lu
2025-06-14 6:35 ` [PATCH v2 02/14] iommufd: Drop unused ictx in struct iommufd_vdevice Nicolin Chen
2025-06-16 3:23 ` Baolu Lu
2025-06-14 6:35 ` [PATCH v2 03/14] iommufd: Use enum iommu_viommu_type for type in struct iommufd_viommu Nicolin Chen
2025-06-16 3:24 ` Baolu Lu
2025-06-16 21:45 ` Pranjal Shrivastava
2025-06-14 6:35 ` [PATCH v2 04/14] iommufd: Use enum iommu_veventq_type for type in struct iommufd_veventq Nicolin Chen
2025-06-16 3:24 ` Baolu Lu
2025-06-16 21:47 ` Pranjal Shrivastava
2025-06-14 6:35 ` [PATCH v2 05/14] iommufd: Return EOPNOTSUPP for failures due to driver bugs Nicolin Chen
2025-06-16 3:25 ` Baolu Lu
2025-06-16 12:28 ` Jason Gunthorpe
2025-06-16 21:49 ` Pranjal Shrivastava
2025-06-19 5:40 ` Tian, Kevin
2025-06-14 6:35 ` [PATCH v2 06/14] iommu: Introduce get_viommu_size and viommu_init ops Nicolin Chen
2025-06-16 3:25 ` Baolu Lu
2025-06-16 12:43 ` Jason Gunthorpe
2025-06-16 22:10 ` Pranjal Shrivastava
2025-06-19 5:42 ` Tian, Kevin
2025-06-14 6:35 ` [PATCH v2 07/14] iommufd/viommu: Support " Nicolin Chen
2025-06-16 3:26 ` Baolu Lu
2025-06-16 12:45 ` Jason Gunthorpe
2025-06-19 5:45 ` Tian, Kevin
2025-06-14 6:35 ` [PATCH v2 08/14] iommufd/selftest: Drop parent domain from mock_iommu_domain_nested Nicolin Chen
2025-06-16 12:46 ` Jason Gunthorpe
2025-06-19 5:46 ` Tian, Kevin
2025-06-14 6:35 ` [PATCH v2 09/14] iommufd/selftest: Replace mock_viommu_alloc with mock_viommu_init Nicolin Chen
2025-06-16 12:46 ` Jason Gunthorpe
2025-06-14 6:35 ` [PATCH v2 10/14] iommu/arm-smmu-v3: Replace arm_vsmmu_alloc with arm_vsmmu_init Nicolin Chen
2025-06-16 10:03 ` Will Deacon
2025-06-16 12:49 ` Jason Gunthorpe
2025-06-16 22:43 ` Pranjal Shrivastava
2025-06-17 2:15 ` Nicolin Chen
2025-06-17 5:43 ` Pranjal Shrivastava
2025-06-14 6:35 ` [PATCH v2 11/14] iommu: Deprecate viommu_alloc op Nicolin Chen
2025-06-16 3:26 ` Baolu Lu
2025-06-16 12:49 ` Jason Gunthorpe
2025-06-16 22:46 ` Pranjal Shrivastava
2025-06-14 6:35 ` [PATCH v2 12/14] iommufd: Move _iommufd_object_alloc out of driver.c Nicolin Chen
2025-06-16 3:26 ` Baolu Lu
2025-06-14 6:35 ` [PATCH v2 13/14] iommufd: Introduce iommufd_object_alloc_ucmd helper Nicolin Chen
2025-06-16 3:27 ` Baolu Lu
2025-06-16 22:52 ` [PATCH v2 13/14] iommufd: Introduce iommufd_object_alloc_ucmd helpery Pranjal Shrivastava
2025-07-09 5:31 ` [PATCH v2 13/14] iommufd: Introduce iommufd_object_alloc_ucmd helper Xu Yilun
2025-07-10 5:32 ` Tian, Kevin
2025-07-10 18:21 ` Nicolin Chen
2025-06-14 6:35 ` Nicolin Chen [this message]
2025-06-16 3:27 ` [PATCH v2 14/14] iommufd: Apply the new " Baolu Lu
2025-06-19 5:49 ` Tian, Kevin
2025-06-19 18:46 ` [PATCH v2 00/14] iommufd: Prepare for IOMMUFD_OBJ_HW_QUEUE Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=107b24a3b791091bb09c92ffb0081c56c413b26d.1749882255.git.nicolinc@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=jsnitsel@redhat.com \
--cc=kevin.tian@intel.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=peterz@infradead.org \
--cc=praan@google.com \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
--cc=yi.l.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).