Linux IOMMU Development
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com,
	baolu.lu@linux.intel.com
Cc: eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org,
	chao.p.peng@linux.intel.com, yi.l.liu@intel.com,
	iommu@lists.linux.dev, zhenzhong.duan@intel.com,
	vasant.hegde@amd.com, will@kernel.org
Subject: [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid
Date: Wed,  4 Dec 2024 04:29:22 -0800	[thread overview]
Message-ID: <20241204122928.11987-2-yi.l.liu@intel.com> (raw)
In-Reply-To: <20241204122928.11987-1-yi.l.liu@intel.com>

driver should implement both set_dev_pasid and remove_dev_pasid op, otherwise
it is a problem how to detach pasid. In reality, it is impossible that an
iommu driver implements set_dev_pasid() but no remove_dev_pasid() op. However,
it is better to check it.

Move the group check to be the first as dev_iommu_ops() may fail when there
is no valid group. Also take the chance to remove the dev_has_iommu() check
as it is duplicated to the group check.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/iommu.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 9bc0c74cca3c..38c3f67e441f 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3368,16 +3368,19 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
 	/* Caller must be a probed driver on dev */
 	struct iommu_group *group = dev->iommu_group;
 	struct group_device *device;
+	const struct iommu_ops *ops;
 	int ret;
 
-	if (!domain->ops->set_dev_pasid)
-		return -EOPNOTSUPP;
-
 	if (!group)
 		return -ENODEV;
 
-	if (!dev_has_iommu(dev) || dev_iommu_ops(dev) != domain->owner ||
-	    pasid == IOMMU_NO_PASID)
+	ops = dev_iommu_ops(dev);
+
+	if (!domain->ops->set_dev_pasid ||
+	    !ops->remove_dev_pasid)
+		return -EOPNOTSUPP;
+
+	if (ops != domain->owner || pasid == IOMMU_NO_PASID)
 		return -EINVAL;
 
 	mutex_lock(&group->mutex);
-- 
2.34.1


  reply	other threads:[~2024-12-04 12:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04 12:29 [PATCH v6 0/7] Support attaching PASID to the blocked_domain Yi Liu
2024-12-04 12:29 ` Yi Liu [this message]
2024-12-05  2:13   ` [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Baolu Lu
2024-12-11  8:24   ` Tian, Kevin
2024-12-04 12:29 ` [PATCH v6 2/7] iommu: Consolidate the ops->remove_dev_pasid usage into a helper Yi Liu
2024-12-04 12:29 ` [PATCH v6 3/7] iommu: Detaching pasid by attaching to the blocked_domain Yi Liu
2024-12-04 12:29 ` [PATCH v6 4/7] iommu/arm-smmu-v3: Make the blocked domain support PASID Yi Liu
2024-12-04 12:29 ` [PATCH v6 5/7] iommu/vt-d: " Yi Liu
2024-12-04 12:29 ` [PATCH v6 6/7] iommu/amd: " Yi Liu
2024-12-04 12:29 ` [PATCH v6 7/7] iommu: Remove the remove_dev_pasid op Yi Liu
2024-12-18  8:40 ` [PATCH v6 0/7] Support attaching PASID to the blocked_domain Joerg Roedel

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=20241204122928.11987-2-yi.l.liu@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=eric.auger@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=vasant.hegde@amd.com \
    --cc=will@kernel.org \
    --cc=zhenzhong.duan@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