public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicolin Chen <nicolinc@nvidia.com>
To: <jgg@nvidia.com>, <kevin.tian@intel.com>, <will@kernel.org>
Cc: <joro@8bytes.org>, <suravee.suthikulpanit@amd.com>,
	<robin.murphy@arm.com>, <dwmw2@infradead.org>,
	<baolu.lu@linux.intel.com>, <shuah@kernel.org>,
	<linux-kernel@vger.kernel.org>, <iommu@lists.linux.dev>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kselftest@vger.kernel.org>, <eric.auger@redhat.com>,
	<jean-philippe@linaro.org>, <mdf@kernel.org>,
	<mshavit@google.com>, <shameerali.kolothum.thodi@huawei.com>,
	<smostafa@google.com>, <yi.l.liu@intel.com>, <aik@amd.com>,
	<patches@lists.linux.dev>
Subject: Re: [PATCH v3 11/11] iommu/arm-smmu-v3: Add IOMMU_VIOMMU_TYPE_ARM_SMMUV3 support
Date: Thu, 17 Oct 2024 09:28:16 -0700	[thread overview]
Message-ID: <ZxE7ILug+SL5eMsl@Asurada-Nvidia> (raw)
In-Reply-To: <562f2bfae1661e6ff6abdb280faa0dd49df9fbdc.1728491453.git.nicolinc@nvidia.com>

On Wed, Oct 09, 2024 at 09:38:11AM -0700, Nicolin Chen wrote:
> Add a new driver-type for ARM SMMUv3 to enum iommu_viommu_type. Implement
> the viommu_alloc op with an arm_vsmmu_alloc function. As an initial step,
> copy the VMID from s2_parent. A later cleanup series is required to move
> the VMID allocation out of the stage-2 domain allocation routine to this.
> 
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
> ---
>  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h   | 18 ++++++++++++++
>  include/uapi/linux/iommufd.h                  |  2 ++
>  .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c     | 24 +++++++++++++++++++
>  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c   |  1 +
>  4 files changed, 45 insertions(+)

I squashed the following changes to this commit (will be in v4).
It replaces nested_domain->s2_parent with nested_domain->vsmmu:

diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
index 5e235fca8f13..3cd8ad0a8980 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
@@ -36,14 +36,15 @@ arm_smmu_get_msi_mapping_domain(struct iommu_domain *domain)
 	struct arm_smmu_nested_domain *nested_domain =
 		container_of(domain, struct arm_smmu_nested_domain, domain);
 
-	return &nested_domain->s2_parent->domain;
+	return &nested_domain->vsmmu->s2_parent->domain;
 }
 
 static void arm_smmu_make_nested_cd_table_ste(
 	struct arm_smmu_ste *target, struct arm_smmu_master *master,
 	struct arm_smmu_nested_domain *nested_domain, bool ats_enabled)
 {
-	arm_smmu_make_s2_domain_ste(target, master, nested_domain->s2_parent,
+	arm_smmu_make_s2_domain_ste(target, master,
+				    nested_domain->vsmmu->s2_parent,
 				    ats_enabled);
 
 	target->data[0] = cpu_to_le64(STRTAB_STE_0_V |
@@ -84,7 +85,8 @@ static void arm_smmu_make_nested_domain_ste(
 		break;
 	case STRTAB_STE_0_CFG_BYPASS:
 		arm_smmu_make_s2_domain_ste(
-			target, master, nested_domain->s2_parent, ats_enabled);
+			target, master, nested_domain->vsmmu->s2_parent,
+			ats_enabled);
 		break;
 	case STRTAB_STE_0_CFG_ABORT:
 	default:
@@ -109,7 +111,7 @@ static int arm_smmu_attach_dev_nested(struct iommu_domain *domain,
 	struct arm_smmu_ste ste;
 	int ret;
 
-	if (nested_domain->s2_parent->smmu != master->smmu)
+	if (nested_domain->vsmmu->smmu != master->smmu)
 		return -EINVAL;
 	if (arm_smmu_ssids_in_use(&master->cd_table))
 		return -EBUSY;
@@ -164,8 +166,10 @@ static int arm_smmu_validate_vste(struct iommu_hwpt_arm_smmuv3 *arg)
 struct iommu_domain *
 arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags,
 			      struct iommu_domain *parent,
+			      struct iommufd_viommu *viommu,
 			      const struct iommu_user_data *user_data)
 {
+	struct arm_vsmmu *vsmmu = container_of(viommu, struct arm_vsmmu, core);
 	struct arm_smmu_master *master = dev_iommu_priv_get(dev);
 	struct arm_smmu_nested_domain *nested_domain;
 	struct arm_smmu_domain *smmu_parent;
@@ -183,6 +187,10 @@ arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags,
 	    !(master->smmu->features & ARM_SMMU_FEAT_S2FWB))
 		return ERR_PTR(-EOPNOTSUPP);
 
+	/* Driver only supports nesting with the vIOMMU infrastructure */
+	if (!viommu)
+		return ERR_PTR(-EOPNOTSUPP);
+
 	/*
 	 * The core code checks that parent was created with
 	 * IOMMU_HWPT_ALLOC_NEST_PARENT
@@ -206,7 +214,7 @@ arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags,
 
 	nested_domain->domain.type = IOMMU_DOMAIN_NESTED;
 	nested_domain->domain.ops = &arm_smmu_nested_ops;
-	nested_domain->s2_parent = smmu_parent;
+	nested_domain->vsmmu = vsmmu;
 	nested_domain->ste[0] = arg.ste[0];
 	nested_domain->ste[1] = arg.ste[1] & ~cpu_to_le64(STRTAB_STE_1_EATS);
 
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 6a23e6dcd5cf..460d2fe5dd49 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2660,7 +2661,7 @@ to_smmu_domain_devices(struct iommu_domain *domain)
 	    domain->type == IOMMU_DOMAIN_SVA)
 		return to_smmu_domain(domain);
 	if (domain->type == IOMMU_DOMAIN_NESTED)
-		return to_smmu_nested_domain(domain)->s2_parent;
+		return to_smmu_nested_domain(domain)->vsmmu->s2_parent;
 	return NULL;
 }
 
@@ -3128,7 +3129,7 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags,
 
 	if (parent)
 		return arm_smmu_domain_alloc_nesting(dev, flags, parent,
-						     user_data);
+						     viommu, user_data);
 
 	if (flags & ~PAGING_FLAGS)
 		return ERR_PTR(-EOPNOTSUPP);
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index 844d1dfdea55..0ea1afe1bb7a 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -836,7 +836,7 @@ struct arm_smmu_domain {
 
 struct arm_smmu_nested_domain {
 	struct iommu_domain domain;
-	struct arm_smmu_domain *s2_parent;
+	struct arm_vsmmu *vsmmu;
 
 	__le64 ste[2];
 };
@@ -1018,6 +1018,7 @@ void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type);
 struct iommu_domain *
 arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags,
 			      struct iommu_domain *parent,
+			      struct iommufd_viommu *viommu,
 			      const struct iommu_user_data *user_data);
 struct iommufd_viommu *
 arm_vsmmu_alloc(struct iommu_device *iommu_dev, struct iommu_domain *parent,
@@ -1027,6 +1028,7 @@ arm_vsmmu_alloc(struct iommu_device *iommu_dev, struct iommu_domain *parent,
 static inline struct iommu_domain *
 arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags,
 			      struct iommu_domain *parent,
+			      struct iommufd_viommu *viommu,
 			      const struct iommu_user_data *user_data)
 {
 	return ERR_PTR(-EOPNOTSUPP);

  reply	other threads:[~2024-10-17 16:28 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-09 16:38 [PATCH v3 00/11] cover-letter: iommufd: Add vIOMMU infrastructure (Part-1) Nicolin Chen
2024-10-09 16:38 ` [PATCH v3 01/11] iommufd: Move struct iommufd_object to public iommufd header Nicolin Chen
2024-10-09 16:38 ` [PATCH v3 02/11] iommufd: Rename _iommufd_object_alloc to iommufd_object_alloc_elm Nicolin Chen
2024-10-17 14:14   ` Jason Gunthorpe
2024-10-17 15:37     ` Jason Gunthorpe
2024-10-17 16:12       ` Nicolin Chen
2024-10-17 16:35         ` Jason Gunthorpe
2024-10-17 16:48           ` Nicolin Chen
2024-10-17 16:54             ` Jason Gunthorpe
2024-10-21  1:26       ` Alexey Kardashevskiy
2024-10-21 18:21         ` Nicolin Chen
2024-10-09 16:38 ` [PATCH v3 03/11] iommufd: Introduce IOMMUFD_OBJ_VIOMMU and its related struct Nicolin Chen
2024-10-12  3:23   ` Zhangfei Gao
2024-10-12  4:49     ` Nicolin Chen
2024-10-12 10:18       ` Zhangfei Gao
2024-10-14  7:58         ` Zhangfei Gao
2024-10-14 15:46           ` Nicolin Chen
2024-10-15  1:15             ` Zhangfei Gao
2024-10-15  2:01               ` Nicolin Chen
2024-10-15 18:44                 ` Nicolin Chen
2024-10-16  1:56                   ` Zhangfei Gao
2024-10-16  6:51                     ` Nicolin Chen
2024-10-16  7:08                       ` Zhangfei Gao
2024-10-17 16:33   ` Jason Gunthorpe
2024-10-17 17:01     ` Nicolin Chen
2024-10-17 17:07       ` Jason Gunthorpe
2024-10-09 16:38 ` [PATCH v3 04/11] iommufd/viommu: Add IOMMU_VIOMMU_ALLOC ioctl Nicolin Chen
2024-10-16  6:38   ` Nicolin Chen
2024-10-17 16:40   ` Jason Gunthorpe
2024-10-21  8:11   ` Alexey Kardashevskiy
2024-10-21 12:19     ` Jason Gunthorpe
2024-10-21 23:41     ` Nicolin Chen
2024-10-09 16:38 ` [PATCH v3 05/11] iommu: Pass in a viommu pointer to domain_alloc_user op Nicolin Chen
2024-10-17 16:51   ` Jason Gunthorpe
2024-10-17 17:21     ` Nicolin Chen
2024-10-17 17:38       ` Jason Gunthorpe
2024-10-17 17:40         ` Nicolin Chen
2024-10-09 16:38 ` [PATCH v3 06/11] iommufd: Allow pt_id to carry viommu_id for IOMMU_HWPT_ALLOC Nicolin Chen
2024-10-17 17:06   ` Jason Gunthorpe
2024-10-09 16:38 ` [PATCH v3 07/11] iommufd/selftest: Add refcount to mock_iommu_device Nicolin Chen
2024-10-17 17:13   ` Jason Gunthorpe
2024-10-09 16:38 ` [PATCH v3 08/11] iommufd/selftest: Add IOMMU_VIOMMU_TYPE_SELFTEST Nicolin Chen
2024-10-17 17:15   ` Jason Gunthorpe
2024-10-17 17:25     ` Nicolin Chen
2024-10-09 16:38 ` [PATCH v3 09/11] iommufd/selftest: Add IOMMU_VIOMMU_ALLOC test coverage Nicolin Chen
2024-10-21  8:30   ` Alexey Kardashevskiy
2024-10-21 18:25     ` Nicolin Chen
2024-10-09 16:38 ` [PATCH v3 10/11] Documentation: userspace-api: iommufd: Update vIOMMU Nicolin Chen
2024-10-17 19:12   ` Jason Gunthorpe
2024-10-09 16:38 ` [PATCH v3 11/11] iommu/arm-smmu-v3: Add IOMMU_VIOMMU_TYPE_ARM_SMMUV3 support Nicolin Chen
2024-10-17 16:28   ` Nicolin Chen [this message]
2024-10-17 16:41     ` Jason Gunthorpe
2024-10-17 16:43       ` Nicolin Chen
2024-10-17 16:48         ` Jason Gunthorpe
2024-10-17 18:40   ` Jason Gunthorpe
2024-10-17 18:48     ` Nicolin Chen
2024-10-09 16:38 ` [PATCH v3 00/16] cover-letter: iommufd: Add vIOMMU infrastructure (Part-2: vDEVICE) Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 01/16] iommufd/viommu: Introduce IOMMUFD_OBJ_VDEVICE and its related struct Nicolin Chen
2024-10-17 18:45     ` Jason Gunthorpe
2024-10-20  1:35       ` Nicolin Chen
2024-10-21 12:21         ` Jason Gunthorpe
2024-10-21 16:42           ` Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 02/16] iommufd/viommu: Add a default_viommu_ops for IOMMU_VIOMMU_TYPE_DEFAULT Nicolin Chen
2024-10-17 18:47     ` Jason Gunthorpe
2024-10-17 18:50       ` Nicolin Chen
2024-10-17 18:52         ` Jason Gunthorpe
2024-10-09 16:38   ` [PATCH v3 03/16] iommufd/viommu: Add IOMMU_VDEVICE_ALLOC ioctl Nicolin Chen
2024-10-17 18:52     ` Jason Gunthorpe
2024-10-20  1:42       ` Nicolin Chen
2024-10-21 12:22         ` Jason Gunthorpe
2024-10-21 16:42           ` Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 04/16] iommufd/selftest: Add IOMMU_VDEVICE_ALLOC test coverage Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 05/16] iommu/viommu: Add cache_invalidate for IOMMU_VIOMMU_TYPE_DEFAULT Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 06/16] iommufd/hw_pagetable: Allow viommu->ops->cache_invalidate for hwpt_nested Nicolin Chen
2024-10-17 18:54     ` Jason Gunthorpe
2024-10-09 16:38   ` [PATCH v3 07/16] iommufd: Allow hwpt_id to carry viommu_id for IOMMU_HWPT_INVALIDATE Nicolin Chen
2024-10-17 19:08     ` Jason Gunthorpe
2024-10-09 16:38   ` [PATCH v3 08/16] iommu: Add iommu_copy_struct_from_full_user_array helper Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 09/16] iommufd/viommu: Add vdev_to_dev helper Nicolin Chen
2024-10-17 19:09     ` Jason Gunthorpe
2024-10-09 16:38   ` [PATCH v3 10/16] iommufd/selftest: Add mock_viommu_cache_invalidate Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 11/16] iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_CACHE test command Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 12/16] iommufd/selftest: Add vIOMMU coverage for IOMMU_HWPT_INVALIDATE ioctl Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 13/16] Documentation: userspace-api: iommufd: Update vDEVICE Nicolin Chen
2024-10-17 19:12     ` Jason Gunthorpe
2024-10-09 16:38   ` [PATCH v3 14/16] iommu/arm-smmu-v3: Add arm_vsmmu_cache_invalidate Nicolin Chen
2024-10-12  3:12     ` Zhangfei Gao
2024-10-12  4:56       ` Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 15/16] iommu/arm-smmu-v3: Allow ATS for IOMMU_DOMAIN_NESTED Nicolin Chen
2024-10-09 16:38   ` [PATCH v3 16/16] iommu/arm-smmu-v3: Update comments about ATS and bypass Nicolin Chen
2024-10-17 19:14   ` [PATCH v3 00/16] cover-letter: iommufd: Add vIOMMU infrastructure (Part-2: vDEVICE) Jason Gunthorpe
2024-10-17 19:19     ` Nicolin Chen

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=ZxE7ILug+SL5eMsl@Asurada-Nvidia \
    --to=nicolinc@nvidia.com \
    --cc=aik@amd.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=dwmw2@infradead.org \
    --cc=eric.auger@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jean-philippe@linaro.org \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mdf@kernel.org \
    --cc=mshavit@google.com \
    --cc=patches@lists.linux.dev \
    --cc=robin.murphy@arm.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=shuah@kernel.org \
    --cc=smostafa@google.com \
    --cc=suravee.suthikulpanit@amd.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