Skip to content

Commit 6283f2e

Browse files
tlendackysuryasaimadhu
authored andcommitted
x86/sev: Replace occurrences of sev_es_active() with cc_platform_has()
Replace uses of sev_es_active() with the more generic cc_platform_has() using CC_ATTR_GUEST_STATE_ENCRYPT. If future support is added for other memory encyrption techonologies, the use of CC_ATTR_GUEST_STATE_ENCRYPT can be updated, as required. Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 4d96f91 commit 6283f2e

File tree

4 files changed

+7
-28
lines changed

4 files changed

+7
-28
lines changed

arch/x86/include/asm/mem_encrypt.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ void __init mem_encrypt_free_decrypted_mem(void);
5151
void __init mem_encrypt_init(void);
5252

5353
void __init sev_es_init_vc_handling(void);
54-
bool sev_es_active(void);
5554

5655
#define __bss_decrypted __section(".bss..decrypted")
5756

@@ -74,7 +73,6 @@ static inline void __init sme_encrypt_kernel(struct boot_params *bp) { }
7473
static inline void __init sme_enable(struct boot_params *bp) { }
7574

7675
static inline void sev_es_init_vc_handling(void) { }
77-
static inline bool sev_es_active(void) { return false; }
7876

7977
static inline int __init
8078
early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0; }

arch/x86/kernel/sev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <linux/sched/debug.h> /* For show_regs() */
1313
#include <linux/percpu-defs.h>
14-
#include <linux/mem_encrypt.h>
14+
#include <linux/cc_platform.h>
1515
#include <linux/printk.h>
1616
#include <linux/mm_types.h>
1717
#include <linux/set_memory.h>
@@ -615,7 +615,7 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd)
615615
int cpu;
616616
u64 pfn;
617617

618-
if (!sev_es_active())
618+
if (!cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT))
619619
return 0;
620620

621621
pflags = _PAGE_NX | _PAGE_RW;
@@ -774,7 +774,7 @@ void __init sev_es_init_vc_handling(void)
774774

775775
BUILD_BUG_ON(offsetof(struct sev_es_runtime_data, ghcb_page) % PAGE_SIZE);
776776

777-
if (!sev_es_active())
777+
if (!cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT))
778778
return;
779779

780780
if (!sev_es_check_cpu_features())

arch/x86/mm/mem_encrypt.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -361,25 +361,6 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size)
361361
return early_set_memory_enc_dec(vaddr, size, true);
362362
}
363363

364-
/*
365-
* SME and SEV are very similar but they are not the same, so there are
366-
* times that the kernel will need to distinguish between SME and SEV. The
367-
* cc_platform_has() function is used for this. When a distinction isn't
368-
* needed, the CC_ATTR_MEM_ENCRYPT attribute can be used.
369-
*
370-
* The trampoline code is a good example for this requirement. Before
371-
* paging is activated, SME will access all memory as decrypted, but SEV
372-
* will access all memory as encrypted. So, when APs are being brought
373-
* up under SME the trampoline area cannot be encrypted, whereas under SEV
374-
* the trampoline area must be encrypted.
375-
*/
376-
377-
/* Needs to be called from non-instrumentable code */
378-
bool noinstr sev_es_active(void)
379-
{
380-
return sev_status & MSR_AMD64_SEV_ES_ENABLED;
381-
}
382-
383364
/* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */
384365
bool force_dma_unencrypted(struct device *dev)
385366
{
@@ -449,7 +430,7 @@ static void print_mem_encrypt_feature_info(void)
449430
pr_cont(" SEV");
450431

451432
/* Encrypted Register State */
452-
if (sev_es_active())
433+
if (cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT))
453434
pr_cont(" SEV-ES");
454435

455436
pr_cont("\n");
@@ -468,7 +449,8 @@ void __init mem_encrypt_init(void)
468449
* With SEV, we need to unroll the rep string I/O instructions,
469450
* but SEV-ES supports them through the #VC handler.
470451
*/
471-
if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) && !sev_es_active())
452+
if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) &&
453+
!cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT))
472454
static_branch_enable(&sev_enable_key);
473455

474456
print_mem_encrypt_feature_info();

arch/x86/realmode/init.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <linux/io.h>
33
#include <linux/slab.h>
44
#include <linux/memblock.h>
5-
#include <linux/mem_encrypt.h>
65
#include <linux/cc_platform.h>
76
#include <linux/pgtable.h>
87

@@ -48,7 +47,7 @@ static void sme_sev_setup_real_mode(struct trampoline_header *th)
4847
if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
4948
th->flags |= TH_FLAGS_SME_ACTIVE;
5049

51-
if (sev_es_active()) {
50+
if (cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) {
5251
/*
5352
* Skip the call to verify_cpu() in secondary_startup_64 as it
5453
* will cause #VC exceptions when the AP can't handle them yet.

0 commit comments

Comments
 (0)