Skip to content

Commit 655a0fa

Browse files
kirylsuryasaimadhu
authored andcommitted
x86/coco: Explicitly declare type of confidential computing platform
The kernel derives the confidential computing platform type it is running as from sme_me_mask on AMD or by using hv_is_isolation_supported() on HyperV isolation VMs. This detection process will be more complicated as more platforms get added. Declare a confidential computing vendor variable explicitly and set it via cc_set_vendor() on the respective platform. [ bp: Massage commit message, fixup HyperV check. ] Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Link: https://lore.kernel.org/r/20220222185740.26228-4-kirill.shutemov@linux.intel.com
1 parent 6198311 commit 655a0fa

4 files changed

Lines changed: 44 additions & 16 deletions

File tree

arch/x86/coco/core.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@
99

1010
#include <linux/export.h>
1111
#include <linux/cc_platform.h>
12-
#include <linux/mem_encrypt.h>
1312

14-
#include <asm/mshyperv.h>
13+
#include <asm/coco.h>
1514
#include <asm/processor.h>
1615

17-
static bool __maybe_unused intel_cc_platform_has(enum cc_attr attr)
16+
static enum cc_vendor vendor __ro_after_init;
17+
18+
static bool intel_cc_platform_has(enum cc_attr attr)
1819
{
19-
#ifdef CONFIG_INTEL_TDX_GUEST
20-
return false;
21-
#else
2220
return false;
23-
#endif
2421
}
2522

2623
/*
@@ -74,12 +71,20 @@ static bool hyperv_cc_platform_has(enum cc_attr attr)
7471

7572
bool cc_platform_has(enum cc_attr attr)
7673
{
77-
if (sme_me_mask)
74+
switch (vendor) {
75+
case CC_VENDOR_AMD:
7876
return amd_cc_platform_has(attr);
79-
80-
if (hv_is_isolation_supported())
77+
case CC_VENDOR_INTEL:
78+
return intel_cc_platform_has(attr);
79+
case CC_VENDOR_HYPERV:
8180
return hyperv_cc_platform_has(attr);
82-
83-
return false;
81+
default:
82+
return false;
83+
}
8484
}
8585
EXPORT_SYMBOL_GPL(cc_platform_has);
86+
87+
__init void cc_set_vendor(enum cc_vendor v)
88+
{
89+
vendor = v;
90+
}

arch/x86/include/asm/coco.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_X86_COCO_H
3+
#define _ASM_X86_COCO_H
4+
5+
enum cc_vendor {
6+
CC_VENDOR_NONE,
7+
CC_VENDOR_AMD,
8+
CC_VENDOR_HYPERV,
9+
CC_VENDOR_INTEL,
10+
};
11+
12+
void cc_set_vendor(enum cc_vendor v);
13+
14+
#endif /* _ASM_X86_COCO_H */

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <asm/nmi.h>
3434
#include <clocksource/hyperv_timer.h>
3535
#include <asm/numa.h>
36+
#include <asm/coco.h>
3637

3738
/* Is Linux running as the root partition? */
3839
bool hv_root_partition;
@@ -344,6 +345,11 @@ static void __init ms_hyperv_init_platform(void)
344345
*/
345346
swiotlb_force = SWIOTLB_FORCE;
346347
#endif
348+
/* Isolation VMs are unenlightened SEV-based VMs, thus this check: */
349+
if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
350+
if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)
351+
cc_set_vendor(CC_VENDOR_HYPERV);
352+
}
347353
}
348354

349355
if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) {

arch/x86/mm/mem_encrypt_identity.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <asm/setup.h>
4545
#include <asm/sections.h>
4646
#include <asm/cmdline.h>
47+
#include <asm/coco.h>
4748

4849
#include "mm_internal.h"
4950

@@ -565,8 +566,7 @@ void __init sme_enable(struct boot_params *bp)
565566
} else {
566567
/* SEV state cannot be controlled by a command line option */
567568
sme_me_mask = me_mask;
568-
physical_mask &= ~sme_me_mask;
569-
return;
569+
goto out;
570570
}
571571

572572
/*
@@ -600,6 +600,9 @@ void __init sme_enable(struct boot_params *bp)
600600
sme_me_mask = 0;
601601
else
602602
sme_me_mask = active_by_default ? me_mask : 0;
603-
604-
physical_mask &= ~sme_me_mask;
603+
out:
604+
if (sme_me_mask) {
605+
physical_mask &= ~sme_me_mask;
606+
cc_set_vendor(CC_VENDOR_AMD);
607+
}
605608
}

0 commit comments

Comments
 (0)