Skip to content

Commit e9d1d2b

Browse files
tlendackysuryasaimadhu
authored andcommitted
treewide: Replace the use of mem_encrypt_active() with cc_platform_has()
Replace uses of mem_encrypt_active() with calls to cc_platform_has() with the CC_ATTR_MEM_ENCRYPT attribute. Remove the implementation of mem_encrypt_active() across all arches. For s390, since the default implementation of the cc_platform_has() matches the s390 implementation of mem_encrypt_active(), cc_platform_has() does not need to be implemented in s390 (the config option ARCH_HAS_CC_PLATFORM is not set). Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 6283f2e commit e9d1d2b

File tree

18 files changed

+36
-40
lines changed

18 files changed

+36
-40
lines changed

arch/powerpc/include/asm/mem_encrypt.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111
#include <asm/svm.h>
1212

13-
static inline bool mem_encrypt_active(void)
14-
{
15-
return is_secure_guest();
16-
}
17-
1813
static inline bool force_dma_unencrypted(struct device *dev)
1914
{
2015
return is_secure_guest();

arch/powerpc/platforms/pseries/svm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/mm.h>
1010
#include <linux/memblock.h>
11+
#include <linux/cc_platform.h>
1112
#include <asm/machdep.h>
1213
#include <asm/svm.h>
1314
#include <asm/swiotlb.h>
@@ -63,7 +64,7 @@ void __init svm_swiotlb_init(void)
6364

6465
int set_memory_encrypted(unsigned long addr, int numpages)
6566
{
66-
if (!mem_encrypt_active())
67+
if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
6768
return 0;
6869

6970
if (!PAGE_ALIGNED(addr))
@@ -76,7 +77,7 @@ int set_memory_encrypted(unsigned long addr, int numpages)
7677

7778
int set_memory_decrypted(unsigned long addr, int numpages)
7879
{
79-
if (!mem_encrypt_active())
80+
if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
8081
return 0;
8182

8283
if (!PAGE_ALIGNED(addr))

arch/s390/include/asm/mem_encrypt.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#ifndef __ASSEMBLY__
66

7-
static inline bool mem_encrypt_active(void) { return false; }
8-
97
int set_memory_encrypted(unsigned long addr, int numpages);
108
int set_memory_decrypted(unsigned long addr, int numpages);
119

arch/x86/include/asm/mem_encrypt.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ static inline void mem_encrypt_free_decrypted_mem(void) { }
9696

9797
extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypted_unused[];
9898

99-
static inline bool mem_encrypt_active(void)
100-
{
101-
return sme_me_mask;
102-
}
103-
10499
static inline u64 sme_get_me_mask(void)
105100
{
106101
return sme_me_mask;

arch/x86/kernel/head64.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <linux/start_kernel.h>
2020
#include <linux/io.h>
2121
#include <linux/memblock.h>
22-
#include <linux/mem_encrypt.h>
22+
#include <linux/cc_platform.h>
2323
#include <linux/pgtable.h>
2424

2525
#include <asm/processor.h>
@@ -284,8 +284,13 @@ unsigned long __head __startup_64(unsigned long physaddr,
284284
* The bss section will be memset to zero later in the initialization so
285285
* there is no need to zero it after changing the memory encryption
286286
* attribute.
287+
*
288+
* This is early code, use an open coded check for SME instead of
289+
* using cc_platform_has(). This eliminates worries about removing
290+
* instrumentation or checking boot_cpu_data in the cc_platform_has()
291+
* function.
287292
*/
288-
if (mem_encrypt_active()) {
293+
if (sme_get_me_mask()) {
289294
vaddr = (unsigned long)__start_bss_decrypted;
290295
vaddr_end = (unsigned long)__end_bss_decrypted;
291296
for (; vaddr < vaddr_end; vaddr += PMD_SIZE) {

arch/x86/mm/ioremap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
694694
bool arch_memremap_can_ram_remap(resource_size_t phys_addr, unsigned long size,
695695
unsigned long flags)
696696
{
697-
if (!mem_encrypt_active())
697+
if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
698698
return true;
699699

700700
if (flags & MEMREMAP_ENC)
@@ -724,7 +724,7 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,
724724
{
725725
bool encrypted_prot;
726726

727-
if (!mem_encrypt_active())
727+
if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
728728
return prot;
729729

730730
encrypted_prot = true;

arch/x86/mm/mem_encrypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ void __init mem_encrypt_free_decrypted_mem(void)
400400
* The unused memory range was mapped decrypted, change the encryption
401401
* attribute from decrypted to encrypted before freeing it.
402402
*/
403-
if (mem_encrypt_active()) {
403+
if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) {
404404
r = set_memory_encrypted(vaddr, npages);
405405
if (r) {
406406
pr_warn("failed to free unused decrypted pages\n");

arch/x86/mm/pat/set_memory.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/libnvdimm.h>
1919
#include <linux/vmstat.h>
2020
#include <linux/kernel.h>
21+
#include <linux/cc_platform.h>
2122

2223
#include <asm/e820/api.h>
2324
#include <asm/processor.h>
@@ -1986,7 +1987,7 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)
19861987
int ret;
19871988

19881989
/* Nothing to do if memory encryption is not active */
1989-
if (!mem_encrypt_active())
1990+
if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
19901991
return 0;
19911992

19921993
/* Should not be working on unaligned addresses */

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <drm/drm_probe_helper.h>
3939
#include <linux/mmu_notifier.h>
4040
#include <linux/suspend.h>
41+
#include <linux/cc_platform.h>
4142

4243
#include "amdgpu.h"
4344
#include "amdgpu_irq.h"
@@ -1269,7 +1270,8 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
12691270
* however, SME requires an indirect IOMMU mapping because the encryption
12701271
* bit is beyond the DMA mask of the chip.
12711272
*/
1272-
if (mem_encrypt_active() && ((flags & AMD_ASIC_MASK) == CHIP_RAVEN)) {
1273+
if (cc_platform_has(CC_ATTR_MEM_ENCRYPT) &&
1274+
((flags & AMD_ASIC_MASK) == CHIP_RAVEN)) {
12731275
dev_info(&pdev->dev,
12741276
"SME is not compatible with RAVEN\n");
12751277
return -ENOTSUPP;

drivers/gpu/drm/drm_cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <linux/dma-buf-map.h>
3232
#include <linux/export.h>
3333
#include <linux/highmem.h>
34-
#include <linux/mem_encrypt.h>
34+
#include <linux/cc_platform.h>
3535
#include <xen/xen.h>
3636

3737
#include <drm/drm_cache.h>
@@ -204,7 +204,7 @@ bool drm_need_swiotlb(int dma_bits)
204204
* Enforce dma_alloc_coherent when memory encryption is active as well
205205
* for the same reasons as for Xen paravirtual hosts.
206206
*/
207-
if (mem_encrypt_active())
207+
if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
208208
return true;
209209

210210
for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling)

0 commit comments

Comments
 (0)