Message ID | 20190806052237.12525-14-bauerman@linux.ibm.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Secure Virtual Machine Enablement | expand |
On Tue, Aug 06, 2019 at 02:22:34AM -0300, Thiago Jung Bauermann wrote: > @@ -1318,7 +1319,10 @@ void iommu_init_early_pSeries(void) > of_reconfig_notifier_register(&iommu_reconfig_nb); > register_memory_notifier(&iommu_mem_nb); > > - set_pci_dma_ops(&dma_iommu_ops); > + if (is_secure_guest()) > + set_pci_dma_ops(NULL); > + else > + set_pci_dma_ops(&dma_iommu_ops); Shoudn't: if (!is_secure_guest()) set_pci_dma_ops(&dma_iommu_ops); be enough here, given that NULL is the default? Also either way I think this conditional needs a comment explaining why it is there.
Hello Christoph, Thanks for your review. Christoph Hellwig <hch@lst.de> writes: > On Tue, Aug 06, 2019 at 02:22:34AM -0300, Thiago Jung Bauermann wrote: >> @@ -1318,7 +1319,10 @@ void iommu_init_early_pSeries(void) >> of_reconfig_notifier_register(&iommu_reconfig_nb); >> register_memory_notifier(&iommu_mem_nb); >> >> - set_pci_dma_ops(&dma_iommu_ops); >> + if (is_secure_guest()) >> + set_pci_dma_ops(NULL); >> + else >> + set_pci_dma_ops(&dma_iommu_ops); > > Shoudn't: > > if (!is_secure_guest()) > set_pci_dma_ops(&dma_iommu_ops); > > be enough here, given that NULL is the default? Indeed, it is enough. > Also either way I think this conditional needs a comment explaining > why it is there. Good point. I added the commit message as a comment in the code. New version of this patch below. From 5dc3914efa4765eef2869d554d4ea1c676bb1e75 Mon Sep 17 00:00:00 2001 From: Thiago Jung Bauermann <bauerman@linux.ibm.com> Date: Thu, 24 Jan 2019 22:40:16 -0200 Subject: [PATCH] powerpc/pseries/iommu: Don't use dma_iommu_ops on secure guests Secure guest memory is inacessible to devices so regular DMA isn't possible. In that case set devices' dma_map_ops to NULL so that the generic DMA code path will use SWIOTLB to bounce buffers for DMA. Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com> --- arch/powerpc/platforms/pseries/iommu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c index 889dc2e44b89..8d9c2b17ad54 100644 --- a/arch/powerpc/platforms/pseries/iommu.c +++ b/arch/powerpc/platforms/pseries/iommu.c @@ -36,6 +36,7 @@ #include <asm/udbg.h> #include <asm/mmzone.h> #include <asm/plpar_wrappers.h> +#include <asm/svm.h> #include "pseries.h" @@ -1318,7 +1319,15 @@ void iommu_init_early_pSeries(void) of_reconfig_notifier_register(&iommu_reconfig_nb); register_memory_notifier(&iommu_mem_nb); - set_pci_dma_ops(&dma_iommu_ops); + /* + * Secure guest memory is inacessible to devices so regular DMA isn't + * possible. + * + * In that case keep devices' dma_map_ops as NULL so that the generic + * DMA code path will use SWIOTLB to bounce buffers for DMA. + */ + if (!is_secure_guest()) + set_pci_dma_ops(&dma_iommu_ops); } static int __init disable_multitce(char *str)
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c index 889dc2e44b89..6fd8c8581873 100644 --- a/arch/powerpc/platforms/pseries/iommu.c +++ b/arch/powerpc/platforms/pseries/iommu.c @@ -36,6 +36,7 @@ #include <asm/udbg.h> #include <asm/mmzone.h> #include <asm/plpar_wrappers.h> +#include <asm/svm.h> #include "pseries.h" @@ -1318,7 +1319,10 @@ void iommu_init_early_pSeries(void) of_reconfig_notifier_register(&iommu_reconfig_nb); register_memory_notifier(&iommu_mem_nb); - set_pci_dma_ops(&dma_iommu_ops); + if (is_secure_guest()) + set_pci_dma_ops(NULL); + else + set_pci_dma_ops(&dma_iommu_ops); } static int __init disable_multitce(char *str)
Secure guest memory is inacessible to devices so regular DMA isn't possible. In that case set devices' dma_map_ops to NULL so that the generic DMA code path will use SWIOTLB and DMA to bounce buffers. Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com> --- arch/powerpc/platforms/pseries/iommu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)