* [PATCH v2 1/1] iommu: Allow attaching static domains in iommu_attach_device_pasid()
@ 2025-04-23 2:18 Lu Baolu
2025-04-23 2:52 ` Dave Jiang
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Lu Baolu @ 2025-04-23 2:18 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian,
Jason Gunthorpe, shangsong2, Dave Jiang
Cc: iommu, linux-kernel, Lu Baolu, stable
The idxd driver attaches the default domain to a PASID of the device to
perform kernel DMA using that PASID. The domain is attached to the
device's PASID through iommu_attach_device_pasid(), which checks if the
domain->owner matches the iommu_ops retrieved from the device. If they
do not match, it returns a failure.
if (ops != domain->owner || pasid == IOMMU_NO_PASID)
return -EINVAL;
The static identity domain implemented by the intel iommu driver doesn't
specify the domain owner. Therefore, kernel DMA with PASID doesn't work
for the idxd driver if the device translation mode is set to passthrough.
Generally the owner field of static domains are not set because they are
already part of iommu ops. Add a helper domain_iommu_ops_compatible()
that checks if a domain is compatible with the device's iommu ops. This
helper explicitly allows the static blocked and identity domains associated
with the device's iommu_ops to be considered compatible.
Fixes: 2031c469f816 ("iommu/vt-d: Add support for static identity domain")
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220031
Cc: stable@vger.kernel.org
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/linux-iommu/20250422191554.GC1213339@ziepe.ca/
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/iommu.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
Change log:
-v2:
- Make the solution generic for all static domains as suggested by
Jason.
-v1: https://lore.kernel.org/linux-iommu/20250422075422.2084548-1-baolu.lu@linux.intel.com/
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 4f91a740c15f..abda40ec377a 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3402,6 +3402,19 @@ static void __iommu_remove_group_pasid(struct iommu_group *group,
iommu_remove_dev_pasid(device->dev, pasid, domain);
}
+static bool domain_iommu_ops_compatible(const struct iommu_ops *ops,
+ struct iommu_domain *domain)
+{
+ if (domain->owner == ops)
+ return true;
+
+ /* For static domains, owner isn't set. */
+ if (domain == ops->blocked_domain || domain == ops->identity_domain)
+ return true;
+
+ return false;
+}
+
/*
* iommu_attach_device_pasid() - Attach a domain to pasid of device
* @domain: the iommu domain.
@@ -3435,7 +3448,8 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
!ops->blocked_domain->ops->set_dev_pasid)
return -EOPNOTSUPP;
- if (ops != domain->owner || pasid == IOMMU_NO_PASID)
+ if (!domain_iommu_ops_compatible(ops, domain) ||
+ pasid == IOMMU_NO_PASID)
return -EINVAL;
mutex_lock(&group->mutex);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2 1/1] iommu: Allow attaching static domains in iommu_attach_device_pasid()
2025-04-23 2:18 [PATCH v2 1/1] iommu: Allow attaching static domains in iommu_attach_device_pasid() Lu Baolu
@ 2025-04-23 2:52 ` Dave Jiang
2025-04-23 14:21 ` Jason Gunthorpe
2025-04-23 19:38 ` Robin Murphy
2 siblings, 0 replies; 5+ messages in thread
From: Dave Jiang @ 2025-04-23 2:52 UTC (permalink / raw)
To: Lu Baolu, Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian,
Jason Gunthorpe, shangsong2
Cc: iommu, linux-kernel, stable
On 4/22/25 7:18 PM, Lu Baolu wrote:
> The idxd driver attaches the default domain to a PASID of the device to
> perform kernel DMA using that PASID. The domain is attached to the
> device's PASID through iommu_attach_device_pasid(), which checks if the
> domain->owner matches the iommu_ops retrieved from the device. If they
> do not match, it returns a failure.
>
> if (ops != domain->owner || pasid == IOMMU_NO_PASID)
> return -EINVAL;
>
> The static identity domain implemented by the intel iommu driver doesn't
> specify the domain owner. Therefore, kernel DMA with PASID doesn't work
> for the idxd driver if the device translation mode is set to passthrough.
>
> Generally the owner field of static domains are not set because they are
> already part of iommu ops. Add a helper domain_iommu_ops_compatible()
> that checks if a domain is compatible with the device's iommu ops. This
> helper explicitly allows the static blocked and identity domains associated
> with the device's iommu_ops to be considered compatible.
>
> Fixes: 2031c469f816 ("iommu/vt-d: Add support for static identity domain")
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220031
> Cc: stable@vger.kernel.org
> Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
> Link: https://lore.kernel.org/linux-iommu/20250422191554.GC1213339@ziepe.ca/
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> drivers/iommu/iommu.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> Change log:
> -v2:
> - Make the solution generic for all static domains as suggested by
> Jason.
> -v1: https://lore.kernel.org/linux-iommu/20250422075422.2084548-1-baolu.lu@linux.intel.com/
>
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 4f91a740c15f..abda40ec377a 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -3402,6 +3402,19 @@ static void __iommu_remove_group_pasid(struct iommu_group *group,
> iommu_remove_dev_pasid(device->dev, pasid, domain);
> }
>
> +static bool domain_iommu_ops_compatible(const struct iommu_ops *ops,
> + struct iommu_domain *domain)
> +{
> + if (domain->owner == ops)
> + return true;
> +
> + /* For static domains, owner isn't set. */
> + if (domain == ops->blocked_domain || domain == ops->identity_domain)
> + return true;
> +
> + return false;
> +}
> +
> /*
> * iommu_attach_device_pasid() - Attach a domain to pasid of device
> * @domain: the iommu domain.
> @@ -3435,7 +3448,8 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
> !ops->blocked_domain->ops->set_dev_pasid)
> return -EOPNOTSUPP;
>
> - if (ops != domain->owner || pasid == IOMMU_NO_PASID)
> + if (!domain_iommu_ops_compatible(ops, domain) ||
> + pasid == IOMMU_NO_PASID)
> return -EINVAL;
>
> mutex_lock(&group->mutex);
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2 1/1] iommu: Allow attaching static domains in iommu_attach_device_pasid()
2025-04-23 2:18 [PATCH v2 1/1] iommu: Allow attaching static domains in iommu_attach_device_pasid() Lu Baolu
2025-04-23 2:52 ` Dave Jiang
@ 2025-04-23 14:21 ` Jason Gunthorpe
2025-04-24 1:36 ` Baolu Lu
2025-04-23 19:38 ` Robin Murphy
2 siblings, 1 reply; 5+ messages in thread
From: Jason Gunthorpe @ 2025-04-23 14:21 UTC (permalink / raw)
To: Lu Baolu
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian, shangsong2,
Dave Jiang, iommu, linux-kernel, stable
On Wed, Apr 23, 2025 at 10:18:39AM +0800, Lu Baolu wrote:
> @@ -3435,7 +3448,8 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
> !ops->blocked_domain->ops->set_dev_pasid)
> return -EOPNOTSUPP;
>
> - if (ops != domain->owner || pasid == IOMMU_NO_PASID)
> + if (!domain_iommu_ops_compatible(ops, domain) ||
> + pasid == IOMMU_NO_PASID)
> return -EINVAL;
Convert all the places checking domain->owner to the new function..
static int __iommu_attach_group(struct iommu_domain *domain,
struct iommu_group *group)
int iommu_replace_device_pasid(struct iommu_domain *domain,
struct device *dev, ioasid_t pasid,
struct iommu_attach_handle *handle)
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] iommu: Allow attaching static domains in iommu_attach_device_pasid()
2025-04-23 14:21 ` Jason Gunthorpe
@ 2025-04-24 1:36 ` Baolu Lu
0 siblings, 0 replies; 5+ messages in thread
From: Baolu Lu @ 2025-04-24 1:36 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian, shangsong2,
Dave Jiang, iommu, linux-kernel, stable
On 4/23/25 22:21, Jason Gunthorpe wrote:
> On Wed, Apr 23, 2025 at 10:18:39AM +0800, Lu Baolu wrote:
>> @@ -3435,7 +3448,8 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
>> !ops->blocked_domain->ops->set_dev_pasid)
>> return -EOPNOTSUPP;
>>
>> - if (ops != domain->owner || pasid == IOMMU_NO_PASID)
>> + if (!domain_iommu_ops_compatible(ops, domain) ||
>> + pasid == IOMMU_NO_PASID)
>> return -EINVAL;
> Convert all the places checking domain->owner to the new function..
>
> static int __iommu_attach_group(struct iommu_domain *domain,
> struct iommu_group *group)
>
> int iommu_replace_device_pasid(struct iommu_domain *domain,
> struct device *dev, ioasid_t pasid,
> struct iommu_attach_handle *handle)
Sure. Will make it in a new version.
Thanks,
baolu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] iommu: Allow attaching static domains in iommu_attach_device_pasid()
2025-04-23 2:18 [PATCH v2 1/1] iommu: Allow attaching static domains in iommu_attach_device_pasid() Lu Baolu
2025-04-23 2:52 ` Dave Jiang
2025-04-23 14:21 ` Jason Gunthorpe
@ 2025-04-23 19:38 ` Robin Murphy
2 siblings, 0 replies; 5+ messages in thread
From: Robin Murphy @ 2025-04-23 19:38 UTC (permalink / raw)
To: Lu Baolu, Joerg Roedel, Will Deacon, Kevin Tian, Jason Gunthorpe,
shangsong2, Dave Jiang
Cc: iommu, linux-kernel, stable
On 2025-04-23 3:18 am, Lu Baolu wrote:
> The idxd driver attaches the default domain to a PASID of the device to
> perform kernel DMA using that PASID. The domain is attached to the
> device's PASID through iommu_attach_device_pasid(), which checks if the
> domain->owner matches the iommu_ops retrieved from the device. If they
> do not match, it returns a failure.
>
> if (ops != domain->owner || pasid == IOMMU_NO_PASID)
> return -EINVAL;
>
> The static identity domain implemented by the intel iommu driver doesn't
> specify the domain owner. Therefore, kernel DMA with PASID doesn't work
> for the idxd driver if the device translation mode is set to passthrough.
>
> Generally the owner field of static domains are not set because they are
> already part of iommu ops. Add a helper domain_iommu_ops_compatible()
> that checks if a domain is compatible with the device's iommu ops. This
> helper explicitly allows the static blocked and identity domains associated
> with the device's iommu_ops to be considered compatible.
With the other domain->owner checks also wrapped as Jason pointed out
(since it would be weird but not impossible for static domains to get
into those paths as well),
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
> Fixes: 2031c469f816 ("iommu/vt-d: Add support for static identity domain")
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220031
> Cc: stable@vger.kernel.org
> Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
> Link: https://lore.kernel.org/linux-iommu/20250422191554.GC1213339@ziepe.ca/
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---
> drivers/iommu/iommu.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> Change log:
> -v2:
> - Make the solution generic for all static domains as suggested by
> Jason.
> -v1: https://lore.kernel.org/linux-iommu/20250422075422.2084548-1-baolu.lu@linux.intel.com/
>
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 4f91a740c15f..abda40ec377a 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -3402,6 +3402,19 @@ static void __iommu_remove_group_pasid(struct iommu_group *group,
> iommu_remove_dev_pasid(device->dev, pasid, domain);
> }
>
> +static bool domain_iommu_ops_compatible(const struct iommu_ops *ops,
> + struct iommu_domain *domain)
> +{
> + if (domain->owner == ops)
> + return true;
> +
> + /* For static domains, owner isn't set. */
> + if (domain == ops->blocked_domain || domain == ops->identity_domain)
> + return true;
> +
> + return false;
> +}
> +
> /*
> * iommu_attach_device_pasid() - Attach a domain to pasid of device
> * @domain: the iommu domain.
> @@ -3435,7 +3448,8 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
> !ops->blocked_domain->ops->set_dev_pasid)
> return -EOPNOTSUPP;
>
> - if (ops != domain->owner || pasid == IOMMU_NO_PASID)
> + if (!domain_iommu_ops_compatible(ops, domain) ||
> + pasid == IOMMU_NO_PASID)
> return -EINVAL;
>
> mutex_lock(&group->mutex);
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-24 1:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23 2:18 [PATCH v2 1/1] iommu: Allow attaching static domains in iommu_attach_device_pasid() Lu Baolu
2025-04-23 2:52 ` Dave Jiang
2025-04-23 14:21 ` Jason Gunthorpe
2025-04-24 1:36 ` Baolu Lu
2025-04-23 19:38 ` Robin Murphy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox