Skip to content

Commit 27f31c8

Browse files
author
Maxim Levitsky
committed
KVM: SEV: Disable SEV-SNP support on initialization failure
JIRA: https://issues.redhat.com/browse/RHEL-120168 commit 179a842 Author: Ashish Kalra <ashish.kalra@amd.com> Date: Mon May 12 22:16:34 2025 +0000 KVM: SEV: Disable SEV-SNP support on initialization failure During platform init, SNP initialization may fail for several reasons, such as firmware command failures and incompatible versions. However, the KVM capability may continue to advertise support for it. The platform may have SNP enabled but if SNP_INIT fails then SNP is not supported by KVM. During KVM module initialization query the SNP platform status to obtain the SNP initialization state and use it as an additional condition to determine support for SEV-SNP. Co-developed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Co-developed-by: Pratik R. Sampat <prsampat@amd.com> Signed-off-by: Pratik R. Sampat <prsampat@amd.com> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com> Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com> Reviewed-by: Pavan Kumar Paluri <papaluri@amd.com> Message-ID: <20250512221634.12045-1-Ashish.Kalra@amd.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
1 parent afdb658 commit 27f31c8

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,6 +2883,33 @@ void __init sev_set_cpu_caps(void)
28832883
}
28842884
}
28852885

2886+
static bool is_sev_snp_initialized(void)
2887+
{
2888+
struct sev_user_data_snp_status *status;
2889+
struct sev_data_snp_addr buf;
2890+
bool initialized = false;
2891+
int ret, error = 0;
2892+
2893+
status = snp_alloc_firmware_page(GFP_KERNEL | __GFP_ZERO);
2894+
if (!status)
2895+
return false;
2896+
2897+
buf.address = __psp_pa(status);
2898+
ret = sev_do_cmd(SEV_CMD_SNP_PLATFORM_STATUS, &buf, &error);
2899+
if (ret) {
2900+
pr_err("SEV: SNP_PLATFORM_STATUS failed ret=%d, fw_error=%d (%#x)\n",
2901+
ret, error, error);
2902+
goto out;
2903+
}
2904+
2905+
initialized = !!status->state;
2906+
2907+
out:
2908+
snp_free_firmware_page(status);
2909+
2910+
return initialized;
2911+
}
2912+
28862913
void __init sev_hardware_setup(void)
28872914
{
28882915
unsigned int eax, ebx, ecx, edx, sev_asid_count, sev_es_asid_count;
@@ -2977,6 +3004,14 @@ void __init sev_hardware_setup(void)
29773004
sev_snp_supported = sev_snp_enabled && cc_platform_has(CC_ATTR_HOST_SEV_SNP);
29783005

29793006
out:
3007+
if (sev_enabled) {
3008+
init_args.probe = true;
3009+
if (sev_platform_init(&init_args))
3010+
sev_supported = sev_es_supported = sev_snp_supported = false;
3011+
else if (sev_snp_supported)
3012+
sev_snp_supported = is_sev_snp_initialized();
3013+
}
3014+
29803015
if (boot_cpu_has(X86_FEATURE_SEV))
29813016
pr_info("SEV %s (ASIDs %u - %u)\n",
29823017
sev_supported ? min_sev_asid <= max_sev_asid ? "enabled" :
@@ -3003,15 +3038,6 @@ void __init sev_hardware_setup(void)
30033038
sev_supported_vmsa_features = 0;
30043039
if (sev_es_debug_swap_enabled)
30053040
sev_supported_vmsa_features |= SVM_SEV_FEAT_DEBUG_SWAP;
3006-
3007-
if (!sev_enabled)
3008-
return;
3009-
3010-
/*
3011-
* Do both SNP and SEV initialization at KVM module load.
3012-
*/
3013-
init_args.probe = true;
3014-
sev_platform_init(&init_args);
30153041
}
30163042

30173043
void sev_hardware_unsetup(void)

0 commit comments

Comments
 (0)