1 // SPDX-License-Identifier: GPL-2.0-only
3 * Confidential Computing Platform Capability checks
5 * Copyright (C) 2021 Advanced Micro Devices, Inc.
10 #include <linux/export.h>
11 #include <linux/cc_platform.h>
12 #include <linux/mem_encrypt.h>
14 #include <asm/mshyperv.h>
15 #include <asm/processor.h>
17 static bool __maybe_unused intel_cc_platform_has(enum cc_attr attr)
19 #ifdef CONFIG_INTEL_TDX_GUEST
27 * SME and SEV are very similar but they are not the same, so there are
28 * times that the kernel will need to distinguish between SME and SEV. The
29 * cc_platform_has() function is used for this. When a distinction isn't
30 * needed, the CC_ATTR_MEM_ENCRYPT attribute can be used.
32 * The trampoline code is a good example for this requirement. Before
33 * paging is activated, SME will access all memory as decrypted, but SEV
34 * will access all memory as encrypted. So, when APs are being brought
35 * up under SME the trampoline area cannot be encrypted, whereas under SEV
36 * the trampoline area must be encrypted.
38 static bool amd_cc_platform_has(enum cc_attr attr)
40 #ifdef CONFIG_AMD_MEM_ENCRYPT
42 case CC_ATTR_MEM_ENCRYPT:
45 case CC_ATTR_HOST_MEM_ENCRYPT:
46 return sme_me_mask && !(sev_status & MSR_AMD64_SEV_ENABLED);
48 case CC_ATTR_GUEST_MEM_ENCRYPT:
49 return sev_status & MSR_AMD64_SEV_ENABLED;
51 case CC_ATTR_GUEST_STATE_ENCRYPT:
52 return sev_status & MSR_AMD64_SEV_ES_ENABLED;
55 * With SEV, the rep string I/O instructions need to be unrolled
56 * but SEV-ES supports them through the #VC handler.
58 case CC_ATTR_GUEST_UNROLL_STRING_IO:
59 return (sev_status & MSR_AMD64_SEV_ENABLED) &&
60 !(sev_status & MSR_AMD64_SEV_ES_ENABLED);
70 static bool hyperv_cc_platform_has(enum cc_attr attr)
72 return attr == CC_ATTR_GUEST_MEM_ENCRYPT;
75 bool cc_platform_has(enum cc_attr attr)
78 return amd_cc_platform_has(attr);
80 if (hv_is_isolation_supported())
81 return hyperv_cc_platform_has(attr);
85 EXPORT_SYMBOL_GPL(cc_platform_has);