1 // SPDX-License-Identifier: GPL-2.0-only
3 * Confidential Computing Platform Capability checks
5 * Copyright (C) 2021 Advanced Micro Devices, Inc.
7 * Author: Tom Lendacky <thomas.lendacky@amd.com>
10 #include <linux/export.h>
11 #include <linux/cc_platform.h>
12 #include <linux/mem_encrypt.h>
14 #include <asm/processor.h>
16 static bool __maybe_unused intel_cc_platform_has(enum cc_attr attr)
18 #ifdef CONFIG_INTEL_TDX_GUEST
26 * SME and SEV are very similar but they are not the same, so there are
27 * times that the kernel will need to distinguish between SME and SEV. The
28 * cc_platform_has() function is used for this. When a distinction isn't
29 * needed, the CC_ATTR_MEM_ENCRYPT attribute can be used.
31 * The trampoline code is a good example for this requirement. Before
32 * paging is activated, SME will access all memory as decrypted, but SEV
33 * will access all memory as encrypted. So, when APs are being brought
34 * up under SME the trampoline area cannot be encrypted, whereas under SEV
35 * the trampoline area must be encrypted.
37 static bool amd_cc_platform_has(enum cc_attr attr)
39 #ifdef CONFIG_AMD_MEM_ENCRYPT
41 case CC_ATTR_MEM_ENCRYPT:
44 case CC_ATTR_HOST_MEM_ENCRYPT:
45 return sme_me_mask && !(sev_status & MSR_AMD64_SEV_ENABLED);
47 case CC_ATTR_GUEST_MEM_ENCRYPT:
48 return sev_status & MSR_AMD64_SEV_ENABLED;
50 case CC_ATTR_GUEST_STATE_ENCRYPT:
51 return sev_status & MSR_AMD64_SEV_ES_ENABLED;
62 bool cc_platform_has(enum cc_attr attr)
65 return amd_cc_platform_has(attr);
69 EXPORT_SYMBOL_GPL(cc_platform_has);