All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/amd: Do not disable SWIOTLB if SME is active
@ 2017-10-06 21:35 Tom Lendacky
       [not found] ` <20171006213540.19038.84350.stgit-qCXWGYdRb2BnqfbPTmsdiZQ+2ll4COg0XqFh9Ls21Oc@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Lendacky @ 2017-10-06 21:35 UTC (permalink / raw)
  To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA; +Cc: Borislav Petkov

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.

Signed-off-by: Tom Lendacky <thomas.lendacky-5C7GfCeVMHo@public.gmane.org>
---
 drivers/iommu/amd_iommu.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 51f8215..822679a 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -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;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] iommu/amd: Do not disable SWIOTLB if SME is active
       [not found] ` <20171006213540.19038.84350.stgit-qCXWGYdRb2BnqfbPTmsdiZQ+2ll4COg0XqFh9Ls21Oc@public.gmane.org>
@ 2017-10-06 21:39   ` Tom Lendacky
       [not found]     ` <800bd17c-475b-c5b2-c4d1-776c655f084a-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Lendacky @ 2017-10-06 21:39 UTC (permalink / raw)
  To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA; +Cc: Borislav Petkov

On 10/6/2017 4:35 PM, Tom Lendacky wrote:
> 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.
> 
> Signed-off-by: Tom Lendacky <thomas.lendacky-5C7GfCeVMHo@public.gmane.org>
> ---
>   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

> diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
> index 51f8215..822679a 100644
> --- a/drivers/iommu/amd_iommu.c
> +++ b/drivers/iommu/amd_iommu.c
> @@ -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;
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iommu/amd: Do not disable SWIOTLB if SME is active
       [not found]     ` <800bd17c-475b-c5b2-c4d1-776c655f084a-5C7GfCeVMHo@public.gmane.org>
@ 2017-10-10  9:58       ` Joerg Roedel
       [not found]         ` <20171010095814.ux7nrtsnylz573hh-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Joerg Roedel @ 2017-10-10  9:58 UTC (permalink / raw)
  To: Tom Lendacky
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Borislav Petkov

Hi Tom,

On Fri, Oct 06, 2017 at 04:39:07PM -0500, Tom Lendacky wrote:
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iommu/amd: Do not disable SWIOTLB if SME is active
       [not found]         ` <20171010095814.ux7nrtsnylz573hh-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
@ 2017-10-10 15:00           ` Tom Lendacky
       [not found]             ` <3117832f-db8f-a0db-c825-f97e3e097b1b-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Lendacky @ 2017-10-10 15:00 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Borislav Petkov

On 10/10/2017 4:58 AM, Joerg Roedel wrote:
> Hi Tom,

Hi Joerg,

> 
> On Fri, Oct 06, 2017 at 04:39:07PM -0500, Tom Lendacky wrote:
>> 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

> 
> 
> Thanks,
> 
> 	Joerg
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iommu/amd: Do not disable SWIOTLB if SME is active
       [not found]             ` <3117832f-db8f-a0db-c825-f97e3e097b1b-5C7GfCeVMHo@public.gmane.org>
@ 2017-10-10 17:50               ` Joerg Roedel
       [not found]                 ` <20171010175011.GB30803-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Joerg Roedel @ 2017-10-10 17:50 UTC (permalink / raw)
  To: Tom Lendacky
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Borislav Petkov

Hi Tom,

On Tue, Oct 10, 2017 at 10:00:26AM -0500, Tom Lendacky wrote:
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iommu/amd: Do not disable SWIOTLB if SME is active
       [not found]                 ` <20171010175011.GB30803-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
@ 2017-10-10 19:24                   ` Tom Lendacky
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Lendacky @ 2017-10-10 19:24 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Borislav Petkov

On 10/10/2017 12:50 PM, Joerg Roedel wrote:
> Hi Tom,
> 
> On Tue, Oct 10, 2017 at 10:00:26AM -0500, Tom Lendacky wrote:
>> 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

> 
> 
> Thanks,
> 
> 	Joerg
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-10-10 19:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-06 21:35 [PATCH] iommu/amd: Do not disable SWIOTLB if SME is active Tom Lendacky
     [not found] ` <20171006213540.19038.84350.stgit-qCXWGYdRb2BnqfbPTmsdiZQ+2ll4COg0XqFh9Ls21Oc@public.gmane.org>
2017-10-06 21:39   ` Tom Lendacky
     [not found]     ` <800bd17c-475b-c5b2-c4d1-776c655f084a-5C7GfCeVMHo@public.gmane.org>
2017-10-10  9:58       ` Joerg Roedel
     [not found]         ` <20171010095814.ux7nrtsnylz573hh-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2017-10-10 15:00           ` Tom Lendacky
     [not found]             ` <3117832f-db8f-a0db-c825-f97e3e097b1b-5C7GfCeVMHo@public.gmane.org>
2017-10-10 17:50               ` Joerg Roedel
     [not found]                 ` <20171010175011.GB30803-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2017-10-10 19:24                   ` Tom Lendacky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.