iommu/amd: Enhance def_domain_type to handle untrusted device
Subsystems (2)
Vasant Hegde
maintainerPATCH 1/1 iommu/amd: Enhance def_domain_type to handle untrusted device
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 sstate.
This patch adds untrusted check in AMD IOMMU driver code. So that it lets eGPUs behind Thunderbolt work again.
Fine tuning amd_iommu_def_domain_type() will be done later.
---
@Eric,
Can you please test this patch?
-Vasant
drivers/iommu/amd/iommu.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/iommu/amd/iommu.c +4 -0
@@ -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 (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
Signature · 1 line
2.31.1
Quoted 9 lines · Vasant Hegde
Previously, IOMMU core layer was forcing
IOMMU_DOMAIN_DMAdomain for untrusted device. This always took precedence over driver'sdef_domain_type(). Commit59ddce4418da("iommu: Reorganizeiommu_get_default_domain_type()to respectdef_domain_type()") changed the behaviour. Current code callsdef_domain_type()but if it doesn't returnIOMMU_DOMAIN_DMAfor untrusted device it throws error. This results in IOMMU group (and potentially IOMMU itself) in undetermined sstate.
Quoted 4 lines
This patch adds untrusted check in AMD IOMMU driver code. So that it lets eGPUs behind Thunderbolt work again.
Fine tuning
amd_iommu_def_domain_type()will be done later.
As long as this is done, and with the commitment that identity rid with pasid will be eventually supported as well
Jason
[Public]
Quoted 27 lines
-----Original Message-----
From: Hegde, Vasant <[email protected]>
Sent: Friday, April 19, 2024 7:47 AM
To: [email protected]; [email protected]
Cc: Suthikulpanit, Suravee <[email protected]>; Deucher, Alexander <[email protected]>; Hegde, Vasant <[email protected]>; Eric Wagner <[email protected]>; Robin Murphy <[email protected]>; Jason Gunthorpe <[email protected]>; [email protected]
Subject: [PATCH] iommu/amd: Enhancedef_domain_typeto handle untrusted devicePreviously, IOMMU core layer was forcing
IOMMU_DOMAIN_DMAdomain for untrusted device. This always took precedence over driver'sdef_domain_type(). Commit59ddce4418da("iommu: Reorganizeiommu_get_default_domain_type()to respectdef_domain_type()") changed the behaviour. Current code callsdef_domain_type()but if it doesn't returnIOMMU_DOMAIN_DMAfor untrusted device it throws error. This results in IOMMU group (and potentially IOMMU itself) in undetermined sstate.This patch adds untrusted check in AMD IOMMU driver code. So that it lets eGPUs behind Thunderbolt work again.
Fine tuning
amd_iommu_def_domain_type()will be done later.
Quoted 7 lines
Fixes 59ddce4418da ("iommu: Reorganize
iommu_get_default_domain_type()to respectdef_domain_type()")Cc Robin Murphy <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc [email protected] # v6.7+Signed-off-by Vasant Hegde <[email protected]>
Assuming it fixes the issue, please add:
Alex
Quoted 27 lines
---
@Eric,
Can you please test this patch?(quoted diff) +0
-1-Vasant drivers/iommu/amd/iommu.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/iommu/amd/iommu.c +4
-0@@ -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 (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
Alex,
Quoted 37 lines · Alexander
[Public]
Quoted 27 lines
-----Original Message-----
From: Hegde, Vasant <[email protected]>
Sent: Friday, April 19, 2024 7:47 AM
To: [email protected]; [email protected]
Cc: Suthikulpanit, Suravee <[email protected]>; Deucher, Alexander <[email protected]>; Hegde, Vasant <[email protected]>; Eric Wagner <[email protected]>; Robin Murphy <[email protected]>; Jason Gunthorpe <[email protected]>; [email protected]
Subject: [PATCH] iommu/amd: Enhancedef_domain_typeto handle untrusted devicePreviously, IOMMU core layer was forcing
IOMMU_DOMAIN_DMAdomain for untrusted device. This always took precedence over driver'sdef_domain_type(). Commit59ddce4418da("iommu: Reorganizeiommu_get_default_domain_type()to respectdef_domain_type()") changed the behaviour. Current code callsdef_domain_type()but if it doesn't returnIOMMU_DOMAIN_DMAfor untrusted device it throws error. This results in IOMMU group (and potentially IOMMU itself) in undetermined sstate.This patch adds untrusted check in AMD IOMMU driver code. So that it lets eGPUs behind Thunderbolt work again.
Fine tuning
amd_iommu_def_domain_type()will be done later.Quoted 7 lines
Fixes 59ddce4418da ("iommu: Reorganize
iommu_get_default_domain_type()to respectdef_domain_type()")Cc Robin Murphy <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc [email protected] # v6.7+Signed-off-by Vasant Hegde <[email protected]>
Quoted 2 lines
Assuming it fixes the issue, please add:
Sure. Will add it in v2.
-Vasant
Quoted 47 lines · Vasant Hegde
Previously, IOMMU core layer was forcing
IOMMU_DOMAIN_DMAdomain for untrusted device. This always took precedence over driver'sdef_domain_type(). Commit59ddce4418da("iommu: Reorganizeiommu_get_default_domain_type()to respectdef_domain_type()") changed the behaviour. Current code callsdef_domain_type()but if it doesn't returnIOMMU_DOMAIN_DMAfor untrusted device it throws error. This results in IOMMU group (and potentially IOMMU itself) in undetermined sstate.This patch adds untrusted check in AMD IOMMU driver code. So that it lets eGPUs behind Thunderbolt work again.
Fine tuning
amd_iommu_def_domain_type()will be done later.Reported-by Eric Wagner <[email protected]>Link https://lore.kernel.org/linux-iommu/CAHudX3zLH6CsRmLE-yb+gRjhh-v4bU5_1jW_xCcxOo_oUUZKYg@mail.gmail.com open hereFixes 59ddce4418da ("iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()")Cc Robin Murphy <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc [email protected] # v6.7+Signed-off-by Vasant Hegde <[email protected]>---
@Eric,
Can you please test this patch?(quoted diff) +0
-1-Vasant drivers/iommu/amd/iommu.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/iommu/amd/iommu.c +4
-1@@ -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 (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 --
Quoted 2 lines
2.31.1
Tested the patch and confirmed it fixes the reported issue for me.
Quoted 35 lines · Vasant Hegde
Previously, IOMMU core layer was forcing
IOMMU_DOMAIN_DMAdomain for untrusted device. This always took precedence over driver'sdef_domain_type(). Commit59ddce4418da("iommu: Reorganizeiommu_get_default_domain_type()to respectdef_domain_type()") changed the behaviour. Current code callsdef_domain_type()but if it doesn't returnIOMMU_DOMAIN_DMAfor untrusted device it throws error. This results in IOMMU group (and potentially IOMMU itself) in undetermined sstate.This patch adds untrusted check in AMD IOMMU driver code. So that it lets eGPUs behind Thunderbolt work again.
Fine tuning
amd_iommu_def_domain_type()will be done later.Reported-by Eric Wagner<[email protected]>Link https://lore.kernel.org/linux-iommu/CAHudX3zLH6CsRmLE-yb+gRjhh-v4bU5_1jW_xCcxOo_oUUZKYg@mail.gmail.com open hereFixes 59ddce4418da ("iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()")Cc Robin Murphy<[email protected]>Cc Jason Gunthorpe<[email protected]>Cc [email protected] # v6.7+Signed-off-by Vasant Hegde<[email protected]>---
@Eric,
Can you please test this patch?(quoted diff) +0
-1-Vasant drivers/iommu/amd/iommu.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/iommu/amd/iommu.c +0
-0
drivers/iommu/amd/iommu.c static int amd_iommu_def_domain_type(struct device *dev) · line 2759
Quoted 6 lines
drivers/iommu/amd/iommu.c +3
-0@@ -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 (to_pci_dev (dev)->untrusted) +return IOMMU_DOMAIN_DMA ;
Are you sure that dev always represents a pci device? If not, perhaps here it needs a dev_is_pci() check?
Best regards,
baolu
Hi,
Quoted 32 lines · Baolu Lu
Quoted 31 lines · Vasant Hegde
Previously, IOMMU core layer was forcing
IOMMU_DOMAIN_DMAdomain for untrusted device. This always took precedence over driver'sdef_domain_type(). Commit59ddce4418da("iommu: Reorganizeiommu_get_default_domain_type()to respectdef_domain_type()") changed the behaviour. Current code callsdef_domain_type()but if it doesn't returnIOMMU_DOMAIN_DMAfor untrusted device it throws error. This results in IOMMU group (and potentially IOMMU itself) in undetermined sstate.This patch adds untrusted check in AMD IOMMU driver code. So that it lets eGPUs behind Thunderbolt work again.
Fine tuning
amd_iommu_def_domain_type()will be done later.Reported-by Eric Wagner<[email protected]>Link https://lore.kernel.org/linux-iommu/CAHudX3zLH6CsRmLE-yb+gRjhh-v4bU5_1jW_xCcxOo_oUUZKYg@mail.gmail.com open hereFixes 59ddce4418da ("iommu: Reorganize iommu_get_default_domain_type() torespect
def_domain_type()")Cc Robin Murphy<[email protected]>Cc Jason Gunthorpe<[email protected]>Cc [email protected] # v6.7+Signed-off-by Vasant Hegde<[email protected]>---
@Eric,
Can you please test this patch?-Vasant
drivers/iommu/amd/iommu.c| 4 ++++1 file changed, 4 insertions(+)
Quoted 13 lines
Quoted 10 lines
drivers/iommu/amd/iommu.c +0
-0@@ -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 (to_pci_dev(dev)->untrusted)
+ returnIOMMU_DOMAIN_DMA;Are you sure that dev always represents a pci device? If not, perhaps here it needs a
dev_is_pci()check?
You are right. I need to add check to verify whether its PCI device or not.
-Vasant