Skip to content

Commit 86e619c

Browse files
dcuiliuw
authored andcommitted
x86/hyperv: Fix undefined reference to isolation_type_en_snp without CONFIG_HYPERV
When CONFIG_HYPERV is not set, arch/x86/hyperv/ivm.c is not built (see arch/x86/Kbuild), so 'isolation_type_en_snp' in the ivm.c is not defined, and this failure happens: ld: arch/x86/kernel/cpu/mshyperv.o: in function `ms_hyperv_init_platform': arch/x86/kernel/cpu/mshyperv.c:417: undefined reference to `isolation_type_en_snp' Fix the failure by testing hv_get_isolation_type() and ms_hyperv.paravisor_present for a fully enlightened SNP VM: when CONFIG_HYPERV is not set, hv_get_isolation_type() is defined as a static inline function that always returns HV_ISOLATION_TYPE_NONE (see include/asm-generic/mshyperv.h), so the compiler won't generate any code for the ms_hyperv.paravisor_present and static_branch_enable(). Reported-by: Tom Lendacky <thomas.lendacky@amd.com> Closes: https://lore.kernel.org/lkml/b4979997-23b9-0c43-574e-e4a3506500ff@amd.com/ Fixes: d6e2d65 ("x86/hyperv: Add sev-snp enlightened guest static key") Signed-off-by: Dexuan Cui <decui@microsoft.com> Signed-off-by: Wei Liu <wei.liu@kernel.org> Link: https://lore.kernel.org/r/20230823032008.18186-1-decui@microsoft.com
1 parent f0a3d1d commit 86e619c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,11 @@ static void __init ms_hyperv_init_platform(void)
413413
ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);
414414

415415

416-
if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) {
417-
static_branch_enable(&isolation_type_en_snp);
418-
} else if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) {
419-
static_branch_enable(&isolation_type_snp);
416+
if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) {
417+
if (ms_hyperv.paravisor_present)
418+
static_branch_enable(&isolation_type_snp);
419+
else
420+
static_branch_enable(&isolation_type_en_snp);
420421
}
421422
}
422423

0 commit comments

Comments
 (0)