All of lore.kernel.org
 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: alex.williamson@redhat.com, robin.murphy@arm.com,
	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,
	jacob.jun.pan@intel.com
Subject: [PATCH v2 12/12] iommu/vt-d: Add set_dev_pasid callback for nested domain
Date: Fri, 12 Apr 2024 01:15:16 -0700	[thread overview]
Message-ID: <20240412081516.31168-13-yi.l.liu@intel.com> (raw)
In-Reply-To: <20240412081516.31168-1-yi.l.liu@intel.com>

From: Lu Baolu <baolu.lu@linux.intel.com>

This allows the upper layers to set a nested type domain to a PASID of a
device if the PASID feature is supported by the IOMMU hardware.

The set_dev_pasid callback for non-nested domain has already be there, so
this only needs to add it for nested domains. Note that the S2 domain with
dirty tracking capability is not supported yet as no user for now.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/intel/iommu.c  | 23 +++++++++++++++++++----
 drivers/iommu/intel/iommu.h  |  3 +++
 drivers/iommu/intel/nested.c | 15 +++++++++++++++
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 9e79ffdd47db..052b90917ced 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -319,6 +319,11 @@ static int domain_type_is_si(struct dmar_domain *domain)
 	return domain->domain.type == IOMMU_DOMAIN_IDENTITY;
 }
 
+static int domain_type_is_nested(struct dmar_domain *domain)
+{
+	return domain->domain.type == IOMMU_DOMAIN_NESTED;
+}
+
 static int domain_pfn_supported(struct dmar_domain *domain, unsigned long pfn)
 {
 	int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT;
@@ -4626,9 +4631,9 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
 	intel_drain_pasid_prq(dev, pasid);
 }
 
-static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
-				     struct device *dev, ioasid_t pasid,
-				     struct iommu_domain *old)
+int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
+			      struct device *dev, ioasid_t pasid,
+			      struct iommu_domain *old)
 {
 	struct device_domain_info *info = dev_iommu_priv_get(dev);
 	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
@@ -4650,7 +4655,15 @@ static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
 	if (old)
 		intel_iommu_remove_dev_pasid(dev, pasid, old);
 
-	ret = prepare_domain_attach_device(domain, dev);
+	/*
+	 * Nested type domain should adjust its parent domain according
+	 * to iommu capability.
+	 */
+	if (domain_type_is_nested(dmar_domain))
+		ret = prepare_domain_attach_device(
+				&dmar_domain->s2_domain->domain, dev);
+	else
+		ret = prepare_domain_attach_device(domain, dev);
 	if (ret)
 		return ret;
 
@@ -4664,6 +4677,8 @@ static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
 
 	if (domain_type_is_si(dmar_domain))
 		ret = intel_pasid_setup_pass_through(iommu, dev, pasid);
+	else if (domain_type_is_nested(dmar_domain))
+		ret = intel_pasid_setup_nested(iommu, dev, pasid, dmar_domain);
 	else if (dmar_domain->use_first_level)
 		ret = domain_setup_first_level(iommu, dmar_domain,
 					       dev, pasid);
diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h
index 404d2476a877..3dfd183c9736 100644
--- a/drivers/iommu/intel/iommu.h
+++ b/drivers/iommu/intel/iommu.h
@@ -1082,6 +1082,9 @@ void device_block_translation(struct device *dev);
 int prepare_domain_attach_device(struct iommu_domain *domain,
 				 struct device *dev);
 void domain_update_iommu_cap(struct dmar_domain *domain);
+int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
+			      struct device *dev, ioasid_t pasid,
+			      struct iommu_domain *old);
 
 int dmar_ir_support(void);
 
diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c
index a7d68f3d518a..7cb124cc0ca0 100644
--- a/drivers/iommu/intel/nested.c
+++ b/drivers/iommu/intel/nested.c
@@ -70,6 +70,20 @@ static int intel_nested_attach_dev(struct iommu_domain *domain,
 	return 0;
 }
 
+static int intel_nested_set_dev_pasid(struct iommu_domain *domain,
+				      struct device *dev, ioasid_t pasid,
+				      struct iommu_domain *old)
+{
+	struct device_domain_info *info = dev_iommu_priv_get(dev);
+	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
+	struct intel_iommu *iommu = info->iommu;
+
+	if (iommu->agaw < dmar_domain->s2_domain->agaw)
+		return -EINVAL;
+
+	return intel_iommu_set_dev_pasid(domain, dev, pasid, old);
+}
+
 static void intel_nested_domain_free(struct iommu_domain *domain)
 {
 	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
@@ -170,6 +184,7 @@ static int intel_nested_cache_invalidate_user(struct iommu_domain *domain,
 
 static const struct iommu_domain_ops intel_nested_domain_ops = {
 	.attach_dev		= intel_nested_attach_dev,
+	.set_dev_pasid		= intel_nested_set_dev_pasid,
 	.free			= intel_nested_domain_free,
 	.cache_invalidate_user	= intel_nested_cache_invalidate_user,
 };
-- 
2.34.1


  parent reply	other threads:[~2024-04-12  8:15 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12  8:15 [PATCH v2 00/12] iommufd support pasid attach/replace Yi Liu
2024-04-12  8:15 ` [PATCH v2 01/12] iommu: Pass old domain to set_dev_pasid op Yi Liu
2024-04-15  5:32   ` Baolu Lu
2024-04-15 11:54     ` Jason Gunthorpe
2024-04-16  2:07       ` Baolu Lu
2024-04-16 17:47         ` Jason Gunthorpe
2024-04-12  8:15 ` [PATCH v2 02/12] iommu: Introduce a replace API for device pasid Yi Liu
2024-04-16  3:01   ` Duan, Zhenzhong
2024-04-16  9:18     ` Yi Liu
2024-04-17  8:44   ` Tian, Kevin
2024-04-17 12:17     ` Jason Gunthorpe
2024-04-18  0:08       ` Tian, Kevin
2024-04-29 13:55   ` Jason Gunthorpe
2024-04-30  5:00     ` Yi Liu
2024-04-30 12:26       ` Jason Gunthorpe
2024-04-12  8:15 ` [PATCH v2 03/12] iommufd: replace attach_fn with a structure Yi Liu
2024-04-12  8:15 ` [PATCH v2 04/12] iommufd: Support attach/replace hwpt per pasid Yi Liu
2024-04-29 13:56   ` Jason Gunthorpe
2024-04-12  8:15 ` [PATCH v2 05/12] iommu: Allow iommu driver to populate the max_pasids Yi Liu
2024-04-15  5:41   ` Baolu Lu
2024-04-17  8:49     ` Tian, Kevin
2024-04-20  5:45       ` Yi Liu
2024-04-22 11:52         ` Jason Gunthorpe
2024-04-12  8:15 ` [PATCH v2 06/12] iommufd/selftest: Add set_dev_pasid and remove_dev_pasid in mock iommu Yi Liu
2024-04-12  8:15 ` [PATCH v2 07/12] iommufd/selftest: Add a helper to get test device Yi Liu
2024-04-12  8:15 ` [PATCH v2 08/12] iommufd/selftest: Add test ops to test pasid attach/detach Yi Liu
2024-04-12  8:15 ` [PATCH v2 09/12] iommufd/selftest: Add coverage for iommufd " Yi Liu
2024-04-12  8:15 ` [PATCH v2 10/12] iommu/vt-d: Return if no dev_pasid is found in domain Yi Liu
2024-04-15  6:04   ` Baolu Lu
2024-04-16  9:21     ` Yi Liu
2024-04-17  2:30       ` Baolu Lu
2024-04-17  3:48         ` Yi Liu
2024-04-17  9:03   ` Tian, Kevin
2024-04-17  9:36     ` Yi Liu
2024-04-12  8:15 ` [PATCH v2 11/12] iommu/vt-d: Make intel_iommu_set_dev_pasid() to handle domain replacement Yi Liu
2024-04-17  9:19   ` Tian, Kevin
2024-04-17  9:35     ` Yi Liu
2024-04-17 12:19       ` Jason Gunthorpe
2024-04-12  8:15 ` Yi Liu [this message]
2024-04-17  9:25   ` [PATCH v2 12/12] iommu/vt-d: Add set_dev_pasid callback for nested domain Tian, Kevin
2024-04-30  9:19     ` Yi Liu
2024-05-06  7:42       ` Baolu Lu
2024-05-06 13:36         ` Jason Gunthorpe
2024-05-07  2:28           ` Yi Liu
2024-05-07 15:18             ` Jason Gunthorpe
2024-05-08  6:10               ` Yi Liu
2024-05-08 12:25                 ` Jason Gunthorpe
2024-05-08 13:26                   ` Yi Liu
2024-05-08 14:11                     ` Jason Gunthorpe
2024-05-09 14:22                       ` Liu, Yi L

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=20240412081516.31168-13-yi.l.liu@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=alex.williamson@redhat.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=jacob.jun.pan@intel.com \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=robin.murphy@arm.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.