aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnshuman Khandual <khandual@linux.vnet.ibm.com>2019-08-19 22:13:24 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2019-08-29 19:55:41 -0400
commit2efbc58f157a39ad9e9199b92d9c47736023a2fe (patch)
tree05345d5a02d206351c5127415d4f334e6eb4a59e
parentedea902c1c1efb855f77e041f9daf1abe7a9768a (diff)
powerpc/pseries/svm: Force SWIOTLB for secure guests
SWIOTLB checks range of incoming CPU addresses to be bounced and sees if the device can access it through its DMA window without requiring bouncing. In such cases it just chooses to skip bouncing. But for cases like secure guests on powerpc platform all addresses need to be bounced into the shared pool of memory because the host cannot access it otherwise. Hence the need to do the bouncing is not related to device's DMA window and use of bounce buffers is forced by setting swiotlb_force. Also, connect the shared memory conversion functions into the ARCH_HAS_MEM_ENCRYPT hooks and call swiotlb_update_mem_attributes() to convert SWIOTLB's memory pool to shared memory. Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com> [ bauerman: Use ARCH_HAS_MEM_ENCRYPT hooks to share swiotlb memory pool. ] Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20190820021326.6884-15-bauerman@linux.ibm.com
-rw-r--r--arch/powerpc/include/asm/mem_encrypt.h26
-rw-r--r--arch/powerpc/platforms/pseries/Kconfig3
-rw-r--r--arch/powerpc/platforms/pseries/svm.c45
3 files changed, 74 insertions, 0 deletions
diff --git a/arch/powerpc/include/asm/mem_encrypt.h b/arch/powerpc/include/asm/mem_encrypt.h
new file mode 100644
index 000000000000..ba9dab07c1be
--- /dev/null
+++ b/arch/powerpc/include/asm/mem_encrypt.h
@@ -0,0 +1,26 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * SVM helper functions
4 *
5 * Copyright 2018 IBM Corporation
6 */
7
8#ifndef _ASM_POWERPC_MEM_ENCRYPT_H
9#define _ASM_POWERPC_MEM_ENCRYPT_H
10
11#include <asm/svm.h>
12
13static inline bool mem_encrypt_active(void)
14{
15 return is_secure_guest();
16}
17
18static inline bool force_dma_unencrypted(struct device *dev)
19{
20 return is_secure_guest();
21}
22
23int set_memory_encrypted(unsigned long addr, int numpages);
24int set_memory_decrypted(unsigned long addr, int numpages);
25
26#endif /* _ASM_POWERPC_MEM_ENCRYPT_H */
diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
index d09deb05bb66..9e35cddddf73 100644
--- a/arch/powerpc/platforms/pseries/Kconfig
+++ b/arch/powerpc/platforms/pseries/Kconfig
@@ -149,6 +149,9 @@ config PAPR_SCM
149config PPC_SVM 149config PPC_SVM
150 bool "Secure virtual machine (SVM) support for POWER" 150 bool "Secure virtual machine (SVM) support for POWER"
151 depends on PPC_PSERIES 151 depends on PPC_PSERIES
152 select SWIOTLB
153 select ARCH_HAS_MEM_ENCRYPT
154 select ARCH_HAS_FORCE_DMA_UNENCRYPTED
152 help 155 help
153 There are certain POWER platforms which support secure guests using 156 There are certain POWER platforms which support secure guests using
154 the Protected Execution Facility, with the help of an Ultravisor 157 the Protected Execution Facility, with the help of an Ultravisor
diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index 2b2b1a77ca1e..40c0637203d5 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -7,8 +7,53 @@
7 */ 7 */
8 8
9#include <linux/mm.h> 9#include <linux/mm.h>
10#include <asm/machdep.h>
11#include <asm/svm.h>
12#include <asm/swiotlb.h>
10#include <asm/ultravisor.h> 13#include <asm/ultravisor.h>
11 14
15static int __init init_svm(void)
16{
17 if (!is_secure_guest())
18 return 0;
19
20 /* Don't release the SWIOTLB buffer. */
21 ppc_swiotlb_enable = 1;
22
23 /*
24 * Since the guest memory is inaccessible to the host, devices always
25 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
26 * otherwise.
27 */
28 swiotlb_force = SWIOTLB_FORCE;
29
30 /* Share the SWIOTLB buffer with the host. */
31 swiotlb_update_mem_attributes();
32
33 return 0;
34}
35machine_early_initcall(pseries, init_svm);
36
37int set_memory_encrypted(unsigned long addr, int numpages)
38{
39 if (!PAGE_ALIGNED(addr))
40 return -EINVAL;
41
42 uv_unshare_page(PHYS_PFN(__pa(addr)), numpages);
43
44 return 0;
45}
46
47int set_memory_decrypted(unsigned long addr, int numpages)
48{
49 if (!PAGE_ALIGNED(addr))
50 return -EINVAL;
51
52 uv_share_page(PHYS_PFN(__pa(addr)), numpages);
53
54 return 0;
55}
56
12/* There's one dispatch log per CPU. */ 57/* There's one dispatch log per CPU. */
13#define NR_DTL_PAGE (DISPATCH_LOG_BYTES * CONFIG_NR_CPUS / PAGE_SIZE) 58#define NR_DTL_PAGE (DISPATCH_LOG_BYTES * CONFIG_NR_CPUS / PAGE_SIZE)
14 59