From: Yi Liu <yi.l.liu@intel.com>
To: joro@8bytes.org, kevin.tian@intel.com, baolu.lu@linux.intel.com,
jgg@nvidia.com
Cc: yi.l.liu@intel.com, iommu@lists.linux.dev, robin.murphy@arm.com,
nicolinc@nvidia.com, will@kernel.org, vasant.hegde@amd.com
Subject: [PATCH v7 07/13] iommufd: Enforce PASID-compatible domain for RID
Date: Sat, 15 Feb 2025 19:52:22 -0800 [thread overview]
Message-ID: <20250216035228.23831-8-yi.l.liu@intel.com> (raw)
In-Reply-To: <20250216035228.23831-1-yi.l.liu@intel.com>
Per the definition of IOMMU_HWPT_ALLOC_PASID, iommufd needs to enforce
the RID to use PASID-compatible domain if PASID has been attached, and
vice versa. The PASID path has already enforced it. This adds the
enforcement in the RID path.
This enforcement requires a lock across the RID and PASID attach path,
the idev->igroup->lock is used as both the RID and the PASID path holds
it.
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
drivers/iommu/iommufd/device.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
index 30dd2f79491a..e0f097b04467 100644
--- a/drivers/iommu/iommufd/device.c
+++ b/drivers/iommu/iommufd/device.c
@@ -357,6 +357,22 @@ iommufd_device_attach_reserved_iova(struct iommufd_device *idev,
/* The device attach/detach/replace helpers for attach_handle */
+static int iommufd_hwpt_pasid_compat(struct iommufd_hw_pagetable *hwpt,
+ struct iommufd_device *idev,
+ ioasid_t pasid)
+{
+ lockdep_assert_held(&idev->igroup->lock);
+
+ if (pasid == IOMMU_NO_PASID &&
+ !xa_empty(&idev->pasid_hwpts) && !hwpt->pasid_compat)
+ return -EINVAL;
+
+ if (pasid != IOMMU_NO_PASID &&
+ (!idev->igroup->hwpt->pasid_compat || !hwpt->pasid_compat))
+ return -EINVAL;
+ return 0;
+}
+
int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt,
struct iommufd_device *idev,
ioasid_t pasid)
@@ -364,10 +380,9 @@ int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt,
struct iommufd_attach_handle *handle;
int rc;
- lockdep_assert_held(&idev->igroup->lock);
-
- if (pasid != IOMMU_NO_PASID && !hwpt->pasid_compat)
- return -EINVAL;
+ rc = iommufd_hwpt_pasid_compat(hwpt, idev, pasid);
+ if (rc)
+ return rc;
handle = kzalloc(sizeof(*handle), GFP_KERNEL);
if (!handle)
@@ -441,8 +456,9 @@ int iommufd_hwpt_replace_device(struct iommufd_device *idev,
struct iommufd_attach_handle *handle, *old_handle;
int rc;
- if (pasid != IOMMU_NO_PASID && !hwpt->pasid_compat)
- return -EINVAL;
+ rc = iommufd_hwpt_pasid_compat(hwpt, idev, pasid);
+ if (rc)
+ return rc;
old_handle = iommufd_device_get_attach_handle(idev, pasid);
--
2.34.1
next prev parent reply other threads:[~2025-02-16 3:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-16 3:52 [PATCH v7 00/13] iommufd support pasid attach/replace Yi Liu
2025-02-16 3:52 ` [PATCH v7 01/13] iommu: Add iommu_attach_device_pasid_handle() Yi Liu
2025-02-25 9:47 ` Tian, Kevin
2025-02-16 3:52 ` [PATCH v7 02/13] iommu: Introduce a replace API for device pasid Yi Liu
2025-02-25 9:55 ` Tian, Kevin
2025-02-25 11:35 ` Yi Liu
2025-02-16 3:52 ` [PATCH v7 03/13] iommufd: Pass @pasid through the device attach/replace path Yi Liu
2025-02-16 3:52 ` [PATCH v7 04/13] iommufd/device: Only add reserved_iova in non-pasid path Yi Liu
2025-02-16 3:52 ` [PATCH v7 05/13] iommufd: Mark PASID-compatible domain Yi Liu
2025-02-16 3:52 ` [PATCH v7 06/13] iommufd: Support pasid attach/replace Yi Liu
2025-02-16 3:52 ` Yi Liu [this message]
2025-02-16 3:52 ` [PATCH v7 08/13] iommu/vt-d: Add IOMMU_HWPT_ALLOC_PASID support Yi Liu
2025-02-16 3:52 ` [PATCH v7 09/13] iommufd: Allow allocating PASID-compatible domain Yi Liu
2025-02-16 3:52 ` [PATCH v7 10/13] iommufd/selftest: Add set_dev_pasid in mock iommu Yi Liu
2025-02-16 3:52 ` [PATCH v7 11/13] iommufd/selftest: Add a helper to get test device Yi Liu
2025-02-16 3:52 ` [PATCH v7 12/13] iommufd/selftest: Add test ops to test pasid attach/detach Yi Liu
2025-02-16 3:52 ` [PATCH v7 13/13] iommufd/selftest: Add coverage for iommufd " Yi Liu
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=20250216035228.23831-8-yi.l.liu@intel.com \
--to=yi.l.liu@intel.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=nicolinc@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=vasant.hegde@amd.com \
--cc=will@kernel.org \
/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