xref: /linux-6.15/include/linux/cc_platform.h (revision 85b60ca9)
146b49b12STom Lendacky /* SPDX-License-Identifier: GPL-2.0-only */
246b49b12STom Lendacky /*
346b49b12STom Lendacky  * Confidential Computing Platform Capability checks
446b49b12STom Lendacky  *
546b49b12STom Lendacky  * Copyright (C) 2021 Advanced Micro Devices, Inc.
646b49b12STom Lendacky  *
746b49b12STom Lendacky  * Author: Tom Lendacky <[email protected]>
846b49b12STom Lendacky  */
946b49b12STom Lendacky 
1046b49b12STom Lendacky #ifndef _LINUX_CC_PLATFORM_H
1146b49b12STom Lendacky #define _LINUX_CC_PLATFORM_H
1246b49b12STom Lendacky 
1346b49b12STom Lendacky #include <linux/types.h>
1446b49b12STom Lendacky #include <linux/stddef.h>
1546b49b12STom Lendacky 
1646b49b12STom Lendacky /**
1746b49b12STom Lendacky  * enum cc_attr - Confidential computing attributes
1846b49b12STom Lendacky  *
1946b49b12STom Lendacky  * These attributes represent confidential computing features that are
2046b49b12STom Lendacky  * currently active.
2146b49b12STom Lendacky  */
2246b49b12STom Lendacky enum cc_attr {
2346b49b12STom Lendacky 	/**
2446b49b12STom Lendacky 	 * @CC_ATTR_MEM_ENCRYPT: Memory encryption is active
2546b49b12STom Lendacky 	 *
2646b49b12STom Lendacky 	 * The platform/OS is running with active memory encryption. This
2746b49b12STom Lendacky 	 * includes running either as a bare-metal system or a hypervisor
2846b49b12STom Lendacky 	 * and actively using memory encryption or as a guest/virtual machine
2946b49b12STom Lendacky 	 * and actively using memory encryption.
3046b49b12STom Lendacky 	 *
3146b49b12STom Lendacky 	 * Examples include SME, SEV and SEV-ES.
3246b49b12STom Lendacky 	 */
3346b49b12STom Lendacky 	CC_ATTR_MEM_ENCRYPT,
3446b49b12STom Lendacky 
3546b49b12STom Lendacky 	/**
3646b49b12STom Lendacky 	 * @CC_ATTR_HOST_MEM_ENCRYPT: Host memory encryption is active
3746b49b12STom Lendacky 	 *
3846b49b12STom Lendacky 	 * The platform/OS is running as a bare-metal system or a hypervisor
3946b49b12STom Lendacky 	 * and actively using memory encryption.
4046b49b12STom Lendacky 	 *
4146b49b12STom Lendacky 	 * Examples include SME.
4246b49b12STom Lendacky 	 */
4346b49b12STom Lendacky 	CC_ATTR_HOST_MEM_ENCRYPT,
4446b49b12STom Lendacky 
4546b49b12STom Lendacky 	/**
4646b49b12STom Lendacky 	 * @CC_ATTR_GUEST_MEM_ENCRYPT: Guest memory encryption is active
4746b49b12STom Lendacky 	 *
4846b49b12STom Lendacky 	 * The platform/OS is running as a guest/virtual machine and actively
4946b49b12STom Lendacky 	 * using memory encryption.
5046b49b12STom Lendacky 	 *
5146b49b12STom Lendacky 	 * Examples include SEV and SEV-ES.
5246b49b12STom Lendacky 	 */
5346b49b12STom Lendacky 	CC_ATTR_GUEST_MEM_ENCRYPT,
5446b49b12STom Lendacky 
5546b49b12STom Lendacky 	/**
5646b49b12STom Lendacky 	 * @CC_ATTR_GUEST_STATE_ENCRYPT: Guest state encryption is active
5746b49b12STom Lendacky 	 *
5846b49b12STom Lendacky 	 * The platform/OS is running as a guest/virtual machine and actively
5946b49b12STom Lendacky 	 * using memory encryption and register state encryption.
6046b49b12STom Lendacky 	 *
6146b49b12STom Lendacky 	 * Examples include SEV-ES.
6246b49b12STom Lendacky 	 */
6346b49b12STom Lendacky 	CC_ATTR_GUEST_STATE_ENCRYPT,
648260b982SKuppuswamy Sathyanarayanan 
658260b982SKuppuswamy Sathyanarayanan 	/**
668260b982SKuppuswamy Sathyanarayanan 	 * @CC_ATTR_GUEST_UNROLL_STRING_IO: String I/O is implemented with
678260b982SKuppuswamy Sathyanarayanan 	 *                                  IN/OUT instructions
688260b982SKuppuswamy Sathyanarayanan 	 *
698260b982SKuppuswamy Sathyanarayanan 	 * The platform/OS is running as a guest/virtual machine and uses
708260b982SKuppuswamy Sathyanarayanan 	 * IN/OUT instructions in place of string I/O.
718260b982SKuppuswamy Sathyanarayanan 	 *
728260b982SKuppuswamy Sathyanarayanan 	 * Examples include TDX guest & SEV.
738260b982SKuppuswamy Sathyanarayanan 	 */
748260b982SKuppuswamy Sathyanarayanan 	CC_ATTR_GUEST_UNROLL_STRING_IO,
75f742b90eSBrijesh Singh 
76f742b90eSBrijesh Singh 	/**
77f742b90eSBrijesh Singh 	 * @CC_ATTR_SEV_SNP: Guest SNP is active.
78f742b90eSBrijesh Singh 	 *
79f742b90eSBrijesh Singh 	 * The platform/OS is running as a guest/virtual machine and actively
80f742b90eSBrijesh Singh 	 * using AMD SEV-SNP features.
81f742b90eSBrijesh Singh 	 */
82f742b90eSBrijesh Singh 	CC_ATTR_GUEST_SEV_SNP,
833a755ebcSLinus Torvalds 
843a755ebcSLinus Torvalds 	/**
85*85b60ca9SNikunj A Dadhania 	 * @CC_ATTR_GUEST_SNP_SECURE_TSC: SNP Secure TSC is active.
86*85b60ca9SNikunj A Dadhania 	 *
87*85b60ca9SNikunj A Dadhania 	 * The platform/OS is running as a guest/virtual machine and actively
88*85b60ca9SNikunj A Dadhania 	 * using AMD SEV-SNP Secure TSC feature.
89*85b60ca9SNikunj A Dadhania 	 */
90*85b60ca9SNikunj A Dadhania 	CC_ATTR_GUEST_SNP_SECURE_TSC,
91*85b60ca9SNikunj A Dadhania 
92*85b60ca9SNikunj A Dadhania 	/**
93bc6f707fSBorislav Petkov (AMD) 	 * @CC_ATTR_HOST_SEV_SNP: AMD SNP enabled on the host.
94bc6f707fSBorislav Petkov (AMD) 	 *
95bc6f707fSBorislav Petkov (AMD) 	 * The host kernel is running with the necessary features
96bc6f707fSBorislav Petkov (AMD) 	 * enabled to run SEV-SNP guests.
97bc6f707fSBorislav Petkov (AMD) 	 */
98bc6f707fSBorislav Petkov (AMD) 	CC_ATTR_HOST_SEV_SNP,
9946b49b12STom Lendacky };
10046b49b12STom Lendacky 
10146b49b12STom Lendacky #ifdef CONFIG_ARCH_HAS_CC_PLATFORM
10246b49b12STom Lendacky 
10346b49b12STom Lendacky /**
10446b49b12STom Lendacky  * cc_platform_has() - Checks if the specified cc_attr attribute is active
10546b49b12STom Lendacky  * @attr: Confidential computing attribute to check
10646b49b12STom Lendacky  *
10746b49b12STom Lendacky  * The cc_platform_has() function will return an indicator as to whether the
10846b49b12STom Lendacky  * specified Confidential Computing attribute is currently active.
10946b49b12STom Lendacky  *
11046b49b12STom Lendacky  * Context: Any context
11146b49b12STom Lendacky  * Return:
11246b49b12STom Lendacky  * * TRUE  - Specified Confidential Computing attribute is active
11346b49b12STom Lendacky  * * FALSE - Specified Confidential Computing attribute is not active
11446b49b12STom Lendacky  */
11546b49b12STom Lendacky bool cc_platform_has(enum cc_attr attr);
116bc6f707fSBorislav Petkov (AMD) void cc_platform_set(enum cc_attr attr);
117bc6f707fSBorislav Petkov (AMD) void cc_platform_clear(enum cc_attr attr);
11846b49b12STom Lendacky 
11946b49b12STom Lendacky #else	/* !CONFIG_ARCH_HAS_CC_PLATFORM */
12046b49b12STom Lendacky 
cc_platform_has(enum cc_attr attr)12146b49b12STom Lendacky static inline bool cc_platform_has(enum cc_attr attr) { return false; }
cc_platform_set(enum cc_attr attr)122bc6f707fSBorislav Petkov (AMD) static inline void cc_platform_set(enum cc_attr attr) { }
cc_platform_clear(enum cc_attr attr)123bc6f707fSBorislav Petkov (AMD) static inline void cc_platform_clear(enum cc_attr attr) { }
12446b49b12STom Lendacky 
12546b49b12STom Lendacky #endif	/* CONFIG_ARCH_HAS_CC_PLATFORM */
12646b49b12STom Lendacky 
12746b49b12STom Lendacky #endif	/* _LINUX_CC_PLATFORM_H */
128