diff options
-rw-r--r-- | arch/powerpc/include/asm/mem_encrypt.h | 26 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/Kconfig | 3 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/svm.c | 45 |
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 | |||
13 | static inline bool mem_encrypt_active(void) | ||
14 | { | ||
15 | return is_secure_guest(); | ||
16 | } | ||
17 | |||
18 | static inline bool force_dma_unencrypted(struct device *dev) | ||
19 | { | ||
20 | return is_secure_guest(); | ||
21 | } | ||
22 | |||
23 | int set_memory_encrypted(unsigned long addr, int numpages); | ||
24 | int 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 | |||
149 | config PPC_SVM | 149 | config 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 | ||
15 | static 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 | } | ||
35 | machine_early_initcall(pseries, init_svm); | ||
36 | |||
37 | int 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 | |||
47 | int 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 | ||