Skip to content

Commit 74ba917

Browse files
tlendackygregkh
authored andcommitted
arch/cc: Introduce a function to check for confidential computing features
commit 46b49b1 upstream. In preparation for other confidential computing technologies, introduce a generic helper function, cc_platform_has(), that can be used to check for specific active confidential computing attributes, like memory encryption. This is intended to eliminate having to add multiple technology-specific checks to the code (e.g. if (sev_active() || tdx_active() || ... ). [ bp: s/_CC_PLATFORM_H/_LINUX_CC_PLATFORM_H/g ] Co-developed-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Andi Kleen <ak@linux.intel.com> Co-developed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/20210928191009.32551-3-bp@alien8.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5be42b2 commit 74ba917

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

arch/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,9 @@ config RELR
10261026
config ARCH_HAS_MEM_ENCRYPT
10271027
bool
10281028

1029+
config ARCH_HAS_CC_PLATFORM
1030+
bool
1031+
10291032
config HAVE_SPARSE_SYSCALL_NR
10301033
bool
10311034
help

include/linux/cc_platform.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Confidential Computing Platform Capability checks
4+
*
5+
* Copyright (C) 2021 Advanced Micro Devices, Inc.
6+
*
7+
* Author: Tom Lendacky <thomas.lendacky@amd.com>
8+
*/
9+
10+
#ifndef _LINUX_CC_PLATFORM_H
11+
#define _LINUX_CC_PLATFORM_H
12+
13+
#include <linux/types.h>
14+
#include <linux/stddef.h>
15+
16+
/**
17+
* enum cc_attr - Confidential computing attributes
18+
*
19+
* These attributes represent confidential computing features that are
20+
* currently active.
21+
*/
22+
enum cc_attr {
23+
/**
24+
* @CC_ATTR_MEM_ENCRYPT: Memory encryption is active
25+
*
26+
* The platform/OS is running with active memory encryption. This
27+
* includes running either as a bare-metal system or a hypervisor
28+
* and actively using memory encryption or as a guest/virtual machine
29+
* and actively using memory encryption.
30+
*
31+
* Examples include SME, SEV and SEV-ES.
32+
*/
33+
CC_ATTR_MEM_ENCRYPT,
34+
35+
/**
36+
* @CC_ATTR_HOST_MEM_ENCRYPT: Host memory encryption is active
37+
*
38+
* The platform/OS is running as a bare-metal system or a hypervisor
39+
* and actively using memory encryption.
40+
*
41+
* Examples include SME.
42+
*/
43+
CC_ATTR_HOST_MEM_ENCRYPT,
44+
45+
/**
46+
* @CC_ATTR_GUEST_MEM_ENCRYPT: Guest memory encryption is active
47+
*
48+
* The platform/OS is running as a guest/virtual machine and actively
49+
* using memory encryption.
50+
*
51+
* Examples include SEV and SEV-ES.
52+
*/
53+
CC_ATTR_GUEST_MEM_ENCRYPT,
54+
55+
/**
56+
* @CC_ATTR_GUEST_STATE_ENCRYPT: Guest state encryption is active
57+
*
58+
* The platform/OS is running as a guest/virtual machine and actively
59+
* using memory encryption and register state encryption.
60+
*
61+
* Examples include SEV-ES.
62+
*/
63+
CC_ATTR_GUEST_STATE_ENCRYPT,
64+
};
65+
66+
#ifdef CONFIG_ARCH_HAS_CC_PLATFORM
67+
68+
/**
69+
* cc_platform_has() - Checks if the specified cc_attr attribute is active
70+
* @attr: Confidential computing attribute to check
71+
*
72+
* The cc_platform_has() function will return an indicator as to whether the
73+
* specified Confidential Computing attribute is currently active.
74+
*
75+
* Context: Any context
76+
* Return:
77+
* * TRUE - Specified Confidential Computing attribute is active
78+
* * FALSE - Specified Confidential Computing attribute is not active
79+
*/
80+
bool cc_platform_has(enum cc_attr attr);
81+
82+
#else /* !CONFIG_ARCH_HAS_CC_PLATFORM */
83+
84+
static inline bool cc_platform_has(enum cc_attr attr) { return false; }
85+
86+
#endif /* CONFIG_ARCH_HAS_CC_PLATFORM */
87+
88+
#endif /* _LINUX_CC_PLATFORM_H */

0 commit comments

Comments
 (0)