* [PATCH v2] iommu/amd: Enhance def_domain_type to handle untrusted device
@ 2024-04-23 11:17 Vasant Hegde
2024-04-23 11:26 ` Robin Murphy
2024-04-26 10:11 ` Joerg Roedel
0 siblings, 2 replies; 5+ messages in thread
From: Vasant Hegde @ 2024-04-23 11:17 UTC (permalink / raw)
To: iommu, joro
Cc: suravee.suthikulpanit, alexander.deucher, baolu.lu, Vasant Hegde,
Eric Wagner, Robin Murphy, Jason Gunthorpe, stable
Previously, IOMMU core layer was forcing IOMMU_DOMAIN_DMA domain for
untrusted device. This always took precedence over driver's
def_domain_type(). Commit 59ddce4418da ("iommu: Reorganize
iommu_get_default_domain_type() to respect def_domain_type()") changed
the behaviour. Current code calls def_domain_type() but if it doesn't
return IOMMU_DOMAIN_DMA for untrusted device it throws error. This
results in IOMMU group (and potentially IOMMU itself) in undetermined
state.
This patch adds untrusted check in AMD IOMMU driver code. So that it
allows eGPUs behind Thunderbolt work again.
Fine tuning amd_iommu_def_domain_type() will be done later.
Reported-by: Eric Wagner <ewagner12@gmail.com>
Link: https://lore.kernel.org/linux-iommu/CAHudX3zLH6CsRmLE-yb+gRjhh-v4bU5_1jW_xCcxOo_oUUZKYg@mail.gmail.com
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3182
Fixes: 59ddce4418da ("iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()")
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: stable@kernel.org # v6.7+
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
Changes in v2:
- Added dev_is_pci() check - Thanks Lu Baolu
-Vasant
drivers/iommu/amd/iommu.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index e692217fcb28..fb727f5b0b82 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2754,6 +2754,10 @@ static int amd_iommu_def_domain_type(struct device *dev)
if (!dev_data)
return 0;
+ /* Always use DMA domain for untrusted device */
+ if (dev_is_pci(dev) && to_pci_dev(dev)->untrusted)
+ return IOMMU_DOMAIN_DMA;
+
/*
* Do not identity map IOMMUv2 capable devices when:
* - memory encryption is active, because some of those devices
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] iommu/amd: Enhance def_domain_type to handle untrusted device
2024-04-23 11:17 [PATCH v2] iommu/amd: Enhance def_domain_type to handle untrusted device Vasant Hegde
@ 2024-04-23 11:26 ` Robin Murphy
2024-04-24 8:11 ` Vasant Hegde
2024-04-26 10:11 ` Joerg Roedel
1 sibling, 1 reply; 5+ messages in thread
From: Robin Murphy @ 2024-04-23 11:26 UTC (permalink / raw)
To: Vasant Hegde, iommu, joro
Cc: suravee.suthikulpanit, alexander.deucher, baolu.lu, Eric Wagner,
Jason Gunthorpe, stable
On 23/04/2024 12:17 pm, Vasant Hegde wrote:
> Previously, IOMMU core layer was forcing IOMMU_DOMAIN_DMA domain for
> untrusted device. This always took precedence over driver's
> def_domain_type(). Commit 59ddce4418da ("iommu: Reorganize
> iommu_get_default_domain_type() to respect def_domain_type()") changed
> the behaviour. Current code calls def_domain_type() but if it doesn't
> return IOMMU_DOMAIN_DMA for untrusted device it throws error. This
> results in IOMMU group (and potentially IOMMU itself) in undetermined
> state.
>
> This patch adds untrusted check in AMD IOMMU driver code. So that it
> allows eGPUs behind Thunderbolt work again.
Sorry, but I firmly disagree with this approach - regardless of what the
AMD driver is currently doing and how appropriate it may or may not be,
we should not be duplicating core code policy in drivers, and we
certainly shouldn't be doing so to bodge around a breakage in how the
core code implements said policy.
Thanks,
Robin.
> Fine tuning amd_iommu_def_domain_type() will be done later.
>
> Reported-by: Eric Wagner <ewagner12@gmail.com>
> Link: https://lore.kernel.org/linux-iommu/CAHudX3zLH6CsRmLE-yb+gRjhh-v4bU5_1jW_xCcxOo_oUUZKYg@mail.gmail.com
> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3182
> Fixes: 59ddce4418da ("iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()")
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: stable@kernel.org # v6.7+
> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
> ---
> Changes in v2:
> - Added dev_is_pci() check - Thanks Lu Baolu
>
> -Vasant
>
> drivers/iommu/amd/iommu.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index e692217fcb28..fb727f5b0b82 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2754,6 +2754,10 @@ static int amd_iommu_def_domain_type(struct device *dev)
> if (!dev_data)
> return 0;
>
> + /* Always use DMA domain for untrusted device */
> + if (dev_is_pci(dev) && to_pci_dev(dev)->untrusted)
> + return IOMMU_DOMAIN_DMA;
> +
> /*
> * Do not identity map IOMMUv2 capable devices when:
> * - memory encryption is active, because some of those devices
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] iommu/amd: Enhance def_domain_type to handle untrusted device
2024-04-23 11:26 ` Robin Murphy
@ 2024-04-24 8:11 ` Vasant Hegde
2024-04-24 13:08 ` Jason Gunthorpe
0 siblings, 1 reply; 5+ messages in thread
From: Vasant Hegde @ 2024-04-24 8:11 UTC (permalink / raw)
To: Robin Murphy, Vasant Hegde, iommu, joro
Cc: suravee.suthikulpanit, alexander.deucher, baolu.lu, Eric Wagner,
Jason Gunthorpe, stable
Hi Robin,
On 4/23/2024 4:56 PM, Robin Murphy wrote:
> On 23/04/2024 12:17 pm, Vasant Hegde wrote:
>> Previously, IOMMU core layer was forcing IOMMU_DOMAIN_DMA domain for
>> untrusted device. This always took precedence over driver's
>> def_domain_type(). Commit 59ddce4418da ("iommu: Reorganize
>> iommu_get_default_domain_type() to respect def_domain_type()") changed
>> the behaviour. Current code calls def_domain_type() but if it doesn't
>> return IOMMU_DOMAIN_DMA for untrusted device it throws error. This
>> results in IOMMU group (and potentially IOMMU itself) in undetermined
>> state.
>>
>> This patch adds untrusted check in AMD IOMMU driver code. So that it
>> allows eGPUs behind Thunderbolt work again.
>
> Sorry, but I firmly disagree with this approach - regardless of what the AMD
> driver is currently doing and how appropriate it may or may not be, we should
> not be duplicating core code policy in drivers, and we certainly shouldn't be
> doing so to bodge around a breakage in how the core code implements said policy.
Ack. I still think fixing in core layer (what your patch does) is the right fix.
@Joerg,
This is alternative to Robin's original patch [1]. If everyone agrees with
that fix then we don't need this patch.
[1]
https://lore.kernel.org/linux-iommu/fa14583e94cbf540b60a6be94b41bb24d0037e75.1713272443.git.robin.murphy@arm.com/
-Vasant
>
> Thanks,
> Robin.
>
>> Fine tuning amd_iommu_def_domain_type() will be done later.
>>
>> Reported-by: Eric Wagner <ewagner12@gmail.com>
>> Link:
>> https://lore.kernel.org/linux-iommu/CAHudX3zLH6CsRmLE-yb+gRjhh-v4bU5_1jW_xCcxOo_oUUZKYg@mail.gmail.com
>> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3182
>> Fixes: 59ddce4418da ("iommu: Reorganize iommu_get_default_domain_type() to
>> respect def_domain_type()")
>> Cc: Robin Murphy <robin.murphy@arm.com>
>> Cc: Jason Gunthorpe <jgg@ziepe.ca>
>> Cc: stable@kernel.org # v6.7+
>> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
>> ---
>> Changes in v2:
>> - Added dev_is_pci() check - Thanks Lu Baolu
>>
>> -Vasant
>>
>> drivers/iommu/amd/iommu.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
>> index e692217fcb28..fb727f5b0b82 100644
>> --- a/drivers/iommu/amd/iommu.c
>> +++ b/drivers/iommu/amd/iommu.c
>> @@ -2754,6 +2754,10 @@ static int amd_iommu_def_domain_type(struct device *dev)
>> if (!dev_data)
>> return 0;
>> + /* Always use DMA domain for untrusted device */
>> + if (dev_is_pci(dev) && to_pci_dev(dev)->untrusted)
>> + return IOMMU_DOMAIN_DMA;
>> +
>> /*
>> * Do not identity map IOMMUv2 capable devices when:
>> * - memory encryption is active, because some of those devices
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] iommu/amd: Enhance def_domain_type to handle untrusted device
2024-04-24 8:11 ` Vasant Hegde
@ 2024-04-24 13:08 ` Jason Gunthorpe
0 siblings, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2024-04-24 13:08 UTC (permalink / raw)
To: Vasant Hegde
Cc: Robin Murphy, Vasant Hegde, iommu, joro, suravee.suthikulpanit,
alexander.deucher, baolu.lu, Eric Wagner, stable
On Wed, Apr 24, 2024 at 01:41:57PM +0530, Vasant Hegde wrote:
> Hi Robin,
>
>
> On 4/23/2024 4:56 PM, Robin Murphy wrote:
> > On 23/04/2024 12:17 pm, Vasant Hegde wrote:
> >> Previously, IOMMU core layer was forcing IOMMU_DOMAIN_DMA domain for
> >> untrusted device. This always took precedence over driver's
> >> def_domain_type(). Commit 59ddce4418da ("iommu: Reorganize
> >> iommu_get_default_domain_type() to respect def_domain_type()") changed
> >> the behaviour. Current code calls def_domain_type() but if it doesn't
> >> return IOMMU_DOMAIN_DMA for untrusted device it throws error. This
> >> results in IOMMU group (and potentially IOMMU itself) in undetermined
> >> state.
> >>
> >> This patch adds untrusted check in AMD IOMMU driver code. So that it
> >> allows eGPUs behind Thunderbolt work again.
> >
> > Sorry, but I firmly disagree with this approach - regardless of what the AMD
> > driver is currently doing and how appropriate it may or may not be, we should
> > not be duplicating core code policy in drivers,
Then AMD should remove the PASID stuff from def_domain_type and we
need to fix it with properly designed core support for this limitation
before merging the SVA support.
> > and we certainly shouldn't be
> > doing so to bodge around a breakage in how the core code implements said policy.
It isn't breakage. It is evolution of the API.
Hacking in the AMD driver is temprary and Vasant will eventually fix
it. Regressing the core code to go back to allowing drivers to inform
policy is much harder to undo.
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] iommu/amd: Enhance def_domain_type to handle untrusted device
2024-04-23 11:17 [PATCH v2] iommu/amd: Enhance def_domain_type to handle untrusted device Vasant Hegde
2024-04-23 11:26 ` Robin Murphy
@ 2024-04-26 10:11 ` Joerg Roedel
1 sibling, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2024-04-26 10:11 UTC (permalink / raw)
To: Vasant Hegde
Cc: iommu, suravee.suthikulpanit, alexander.deucher, baolu.lu,
Eric Wagner, Robin Murphy, Jason Gunthorpe, stable
On Tue, Apr 23, 2024 at 11:17:25AM +0000, Vasant Hegde wrote:
> drivers/iommu/amd/iommu.c | 4 ++++
> 1 file changed, 4 insertions(+)
Since this fixes a regression I think it makes sense to apply as-is for
v6.9. Things can be done more properly later on-top of this fix.
So: Applied, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-26 10:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-23 11:17 [PATCH v2] iommu/amd: Enhance def_domain_type to handle untrusted device Vasant Hegde
2024-04-23 11:26 ` Robin Murphy
2024-04-24 8:11 ` Vasant Hegde
2024-04-24 13:08 ` Jason Gunthorpe
2024-04-26 10:11 ` Joerg Roedel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox