Skip to content

Commit bc6f707

Browse files
committed
x86/cc: Add cc_platform_set/_clear() helpers
Add functionality to set and/or clear different attributes of the machine as a confidential computing platform. Add the first one too: whether the machine is running as a host for SEV-SNP guests. Fixes: 216d106 ("x86/sev: Add SEV-SNP host initialization support") Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Tested-by: Srikanth Aithal <sraithal@amd.com> Link: https://lore.kernel.org/r/20240327154317.29909-5-bp@alien8.de
1 parent 54f5f47 commit bc6f707

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

arch/x86/coco/core.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
enum cc_vendor cc_vendor __ro_after_init = CC_VENDOR_NONE;
2121
u64 cc_mask __ro_after_init;
2222

23+
static struct cc_attr_flags {
24+
__u64 host_sev_snp : 1,
25+
__resv : 63;
26+
} cc_flags;
27+
2328
static bool noinstr intel_cc_platform_has(enum cc_attr attr)
2429
{
2530
switch (attr) {
@@ -93,6 +98,9 @@ static bool noinstr amd_cc_platform_has(enum cc_attr attr)
9398
case CC_ATTR_GUEST_SEV_SNP:
9499
return sev_status & MSR_AMD64_SEV_SNP_ENABLED;
95100

101+
case CC_ATTR_HOST_SEV_SNP:
102+
return cc_flags.host_sev_snp;
103+
96104
default:
97105
return false;
98106
}
@@ -153,6 +161,50 @@ u64 cc_mkdec(u64 val)
153161
}
154162
EXPORT_SYMBOL_GPL(cc_mkdec);
155163

164+
static void amd_cc_platform_clear(enum cc_attr attr)
165+
{
166+
switch (attr) {
167+
case CC_ATTR_HOST_SEV_SNP:
168+
cc_flags.host_sev_snp = 0;
169+
break;
170+
default:
171+
break;
172+
}
173+
}
174+
175+
void cc_platform_clear(enum cc_attr attr)
176+
{
177+
switch (cc_vendor) {
178+
case CC_VENDOR_AMD:
179+
amd_cc_platform_clear(attr);
180+
break;
181+
default:
182+
break;
183+
}
184+
}
185+
186+
static void amd_cc_platform_set(enum cc_attr attr)
187+
{
188+
switch (attr) {
189+
case CC_ATTR_HOST_SEV_SNP:
190+
cc_flags.host_sev_snp = 1;
191+
break;
192+
default:
193+
break;
194+
}
195+
}
196+
197+
void cc_platform_set(enum cc_attr attr)
198+
{
199+
switch (cc_vendor) {
200+
case CC_VENDOR_AMD:
201+
amd_cc_platform_set(attr);
202+
break;
203+
default:
204+
break;
205+
}
206+
}
207+
156208
__init void cc_random_init(void)
157209
{
158210
/*

include/linux/cc_platform.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ enum cc_attr {
9090
* Examples include TDX Guest.
9191
*/
9292
CC_ATTR_HOTPLUG_DISABLED,
93+
94+
/**
95+
* @CC_ATTR_HOST_SEV_SNP: AMD SNP enabled on the host.
96+
*
97+
* The host kernel is running with the necessary features
98+
* enabled to run SEV-SNP guests.
99+
*/
100+
CC_ATTR_HOST_SEV_SNP,
93101
};
94102

95103
#ifdef CONFIG_ARCH_HAS_CC_PLATFORM
@@ -107,10 +115,14 @@ enum cc_attr {
107115
* * FALSE - Specified Confidential Computing attribute is not active
108116
*/
109117
bool cc_platform_has(enum cc_attr attr);
118+
void cc_platform_set(enum cc_attr attr);
119+
void cc_platform_clear(enum cc_attr attr);
110120

111121
#else /* !CONFIG_ARCH_HAS_CC_PLATFORM */
112122

113123
static inline bool cc_platform_has(enum cc_attr attr) { return false; }
124+
static inline void cc_platform_set(enum cc_attr attr) { }
125+
static inline void cc_platform_clear(enum cc_attr attr) { }
114126

115127
#endif /* CONFIG_ARCH_HAS_CC_PLATFORM */
116128

0 commit comments

Comments
 (0)