Skip to content

Commit d6e2d65

Browse files
tialaliuw
authored andcommitted
x86/hyperv: Add sev-snp enlightened guest static key
Introduce static key isolation_type_en_snp for enlightened sev-snp guest check. Reviewed-by: Dexuan Cui <decui@microsoft.com> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Signed-off-by: Tianyu Lan <tiala@microsoft.com> Signed-off-by: Wei Liu <wei.liu@kernel.org> Link: https://lore.kernel.org/r/20230818102919.1318039-2-ltykernel@gmail.com
1 parent 4f74fb3 commit d6e2d65

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

arch/x86/hyperv/ivm.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,14 @@ bool hv_isolation_type_snp(void)
413413
{
414414
return static_branch_unlikely(&isolation_type_snp);
415415
}
416+
417+
DEFINE_STATIC_KEY_FALSE(isolation_type_en_snp);
418+
/*
419+
* hv_isolation_type_en_snp - Check system runs in the AMD SEV-SNP based
420+
* isolation enlightened VM.
421+
*/
422+
bool hv_isolation_type_en_snp(void)
423+
{
424+
return static_branch_unlikely(&isolation_type_en_snp);
425+
}
426+

arch/x86/include/asm/mshyperv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
union hv_ghcb;
2727

2828
DECLARE_STATIC_KEY_FALSE(isolation_type_snp);
29+
DECLARE_STATIC_KEY_FALSE(isolation_type_en_snp);
2930

3031
typedef int (*hyperv_fill_flush_list_func)(
3132
struct hv_guest_mapping_flush_list *flush,
@@ -239,6 +240,7 @@ static inline void hv_vtom_init(void) {}
239240
#endif
240241

241242
extern bool hv_isolation_type_snp(void);
243+
extern bool hv_isolation_type_en_snp(void);
242244

243245
static inline bool hv_is_synic_reg(unsigned int reg)
244246
{

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,12 @@ static void __init ms_hyperv_init_platform(void)
402402
pr_info("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n",
403403
ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);
404404

405-
if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP)
405+
406+
if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) {
407+
static_branch_enable(&isolation_type_en_snp);
408+
} else if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) {
406409
static_branch_enable(&isolation_type_snp);
410+
}
407411
}
408412

409413
if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) {
@@ -473,7 +477,8 @@ static void __init ms_hyperv_init_platform(void)
473477

474478
#if IS_ENABLED(CONFIG_HYPERV)
475479
if ((hv_get_isolation_type() == HV_ISOLATION_TYPE_VBS) ||
476-
(hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP))
480+
((hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) &&
481+
ms_hyperv.paravisor_present))
477482
hv_vtom_init();
478483
/*
479484
* Setup the hook to get control post apic initialization.

drivers/hv/hv_common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ bool __weak hv_isolation_type_snp(void)
502502
}
503503
EXPORT_SYMBOL_GPL(hv_isolation_type_snp);
504504

505+
bool __weak hv_isolation_type_en_snp(void)
506+
{
507+
return false;
508+
}
509+
EXPORT_SYMBOL_GPL(hv_isolation_type_en_snp);
510+
505511
void __weak hv_setup_vmbus_handler(void (*handler)(void))
506512
{
507513
}

include/asm-generic/mshyperv.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,21 @@ struct ms_hyperv_info {
3636
u32 nested_features;
3737
u32 max_vp_index;
3838
u32 max_lp_index;
39-
u32 isolation_config_a;
39+
union {
40+
u32 isolation_config_a;
41+
struct {
42+
u32 paravisor_present : 1;
43+
u32 reserved_a1 : 31;
44+
};
45+
};
4046
union {
4147
u32 isolation_config_b;
4248
struct {
4349
u32 cvm_type : 4;
44-
u32 reserved1 : 1;
50+
u32 reserved_b1 : 1;
4551
u32 shared_gpa_boundary_active : 1;
4652
u32 shared_gpa_boundary_bits : 6;
47-
u32 reserved2 : 20;
53+
u32 reserved_b2 : 20;
4854
};
4955
};
5056
u64 shared_gpa_boundary;
@@ -58,6 +64,7 @@ extern void * __percpu *hyperv_pcpu_output_arg;
5864
extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr);
5965
extern u64 hv_do_fast_hypercall8(u16 control, u64 input8);
6066
extern bool hv_isolation_type_snp(void);
67+
extern bool hv_isolation_type_en_snp(void);
6168

6269
/* Helper functions that provide a consistent pattern for checking Hyper-V hypercall status. */
6370
static inline int hv_result(u64 status)

0 commit comments

Comments
 (0)