Skip to contentSkip to conversation

iommu/amd: Do not disable SWIOTLB if SME is active

PATCH In review Tom Lendacky 2 participants 6 messages Oct 6, 2017 – Oct 10, 2017 5 messages not in the archive IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/amd: Do not disable SWIOTLB if SME is active

When SME memory encryption is active it will rely on SWIOTLB to handle DMA for devices that cannot support the addressing requirements of having the encryption mask set in the physical address. The IOMMU currently disables SWIOTLB if it is not running in passthrough mode. This is not desired as non-PCI devices attempting DMA may fail. Update the code to check if SME is active and not disable SWIOTLB.

---
 drivers/iommu/amd_iommu.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/iommu/amd_iommu.c +6 -4
index 51f8215..822679a 100644
@@ -2773,14 +2773,16 @@ int __init amd_iommu_init_api(void)
 
 int __init amd_iommu_init_dma_ops(void)
 {
-	swiotlb        = iommu_pass_through ? 1 : 0;
+	swiotlb        = (iommu_pass_through || sme_me_mask) ? 1 : 0;
 	iommu_detected = 1;
 
 	/*
 	 * In case we don't initialize SWIOTLB (actually the common case
-	 * when AMD IOMMU is enabled), make sure there are global
-	 * dma_ops set as a fall-back for devices not handled by this
-	 * driver (for example non-PCI devices).
+	 * when AMD IOMMU is enabled and SME is not active), make sure there
+	 * are global dma_ops set as a fall-back for devices not handled by
+	 * this driver (for example non-PCI devices). When SME is active,
+	 * make sure that swiotlb variable remains set so the global dma_ops
+	 * continue to be SWIOTLB.
 	 */
 	if (!swiotlb)
 		dma_ops = &nommu_dma_ops;

A message that is not in the archive (sent off-list or not yet received): 20171006213540.19038.84350.stgit-qCXWGYdRb2BnqfbPTmsdiZQ+2ll4COg0XqFh9Ls21Oc@public.gmane.org

#2 lore raw
Quoted 7 lines · Tom Lendacky

When SME memory encryption is active it will rely on SWIOTLB to handle DMA for devices that cannot support the addressing requirements of having the encryption mask set in the physical address. The IOMMU currently disables SWIOTLB if it is not running in passthrough mode. This is not desired as non-PCI devices attempting DMA may fail. Update the code to check if SME is active and not disable SWIOTLB.

Quoted 5 lines
---
  drivers/iommu/amd_iommu.c |   10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)

Hi Joerg,

This is an SME bug fix. Assuming this is acceptable, any chance it can be pushed to the current 4.14 linux rc release tree?

Thanks,
Tom

Quoted 26 lines
drivers/iommu/amd_iommu.c +6 -4
index 51f8215..822679a 100644
@@ -2773,14 +2773,16 @@ int __init amd_iommu_init_api(void)
 
  int __init amd_iommu_init_dma_ops(void)
  {
-	swiotlb        = iommu_pass_through ? 1 : 0;
+	swiotlb        = (iommu_pass_through || sme_me_mask) ? 1 : 0;
  	iommu_detected = 1;
 
  	/*
  	 * In case we don't initialize SWIOTLB (actually the common case
-	 * when AMD IOMMU is enabled), make sure there are global
-	 * dma_ops set as a fall-back for devices not handled by this
-	 * driver (for example non-PCI devices).
+	 * when AMD IOMMU is enabled and SME is not active), make sure there
+	 * are global dma_ops set as a fall-back for devices not handled by
+	 * this driver (for example non-PCI devices). When SME is active,
+	 * make sure that swiotlb variable remains set so the global dma_ops
+	 * continue to be SWIOTLB.
  	 */
  	if (!swiotlb)
  		dma_ops = &nommu_dma_ops;

A message that is not in the archive (sent off-list or not yet received): 800bd17c-475b-c5b2-c4d1-776c655f084a-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Hi Tom,

Quoted 2 lines · Tom Lendacky

This is an SME bug fix. Assuming this is acceptable, any chance it can be pushed to the current 4.14 linux rc release tree?

Sure, can you please also provide a "Fixes:"-tag?

Thanks,

Joerg

A message that is not in the archive (sent off-list or not yet received): 20171010095814.ux7nrtsnylz573hh-zLv9SwRftAIdnm+yROfE0A@public.gmane.org

#6 lore raw
Quoted 1 line · Joerg Roedel

Hi Tom,

Hi Joerg,

Quoted 6 lines · Tom Lendacky
Quoted 2 lines

This is an SME bug fix. Assuming this is acceptable, any chance it can be pushed to the current 4.14 linux rc release tree?

Sure, can you please also provide a "Fixes:"-tag?

I can. I'm not sure if you want me to re-submit the patch with it or if you just want to add it yourself. Let me know.

Fixes 2543a786aa25 ("iommu/amd: Allow the AMD IOMMU to work with memory encryption")

Thanks,
Tom

Quoted 6 lines

Thanks,

Joerg

A message that is not in the archive (sent off-list or not yet received): 3117832f-db8f-a0db-c825-f97e3e097b1b-5C7GfCeVMHo@public.gmane.org

#8 lore raw

Hi Tom,

Quoted 4 lines · Tom Lendacky

I can. I'm not sure if you want me to re-submit the patch with it or if you just want to add it yourself. Let me know.

Fixes 2543a786aa25 ("iommu/amd: Allow the AMD IOMMU to work with memory encryption")

No need to re-submit, I applied the patch and added the tag.

Thanks,

Joerg

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw
Quoted 9 lines · Joerg Roedel

Hi Tom,

Quoted 4 lines · Tom Lendacky

I can. I'm not sure if you want me to re-submit the patch with it or if you just want to add it yourself. Let me know.

Fixes 2543a786aa25 ("iommu/amd: Allow the AMD IOMMU to work with memory encryption")

No need to re-submit, I applied the patch and added the tag.

Thanks Joerg!

Tom

Quoted 6 lines

Thanks,

Joerg