Skip to contentSkip to conversation

x86/hyperv: Fix undefined reference to isolation_type_en_snp without CONFIG_HYPERV

PATCH Applied Dexuan Cui 2 participants 2 messages Aug 23, 2023

Subsystems (3)
lore
Share & tools
lore

Dexuan Cui

author maintainer
#0 lore raw

PATCH 1/1 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().

Fixes d6e2d6524437 ("x86/hyperv: Add sev-snp enlightened guest static key")
---
 arch/x86/kernel/cpu/mshyperv.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/mshyperv.c +5 -4
index 26b9fcabd7d95..c8d3ca2b0e0ee 100644
@@ -413,10 +413,11 @@ static void __init ms_hyperv_init_platform(void)
 			ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);
 
 
-		if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) {
-			static_branch_enable(&isolation_type_en_snp);
-		} else if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) {
-			static_branch_enable(&isolation_type_snp);
+		if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) {
+			if (ms_hyperv.paravisor_present)
+				static_branch_enable(&isolation_type_snp);
+			else
+				static_branch_enable(&isolation_type_en_snp);
 		}
 	}
 
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 14 lines · Dexuan Cui

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().

Quoted 4 lines
Fixes d6e2d6524437 ("x86/hyperv: Add sev-snp enlightened guest static key")

Applied. Thanks.