* Re: [PATCH v3] KVM: SEV: Disable SEV-SNP support on initialization failure
2025-05-12 22:16 [PATCH v3] KVM: SEV: Disable SEV-SNP support on initialization failure Ashish Kalra
@ 2025-05-12 23:07 ` Paluri, PavanKumar
2025-05-13 4:46 ` Gupta, Pankaj
2025-06-11 18:27 ` Paolo Bonzini
2 siblings, 0 replies; 5+ messages in thread
From: Paluri, PavanKumar @ 2025-05-12 23:07 UTC (permalink / raw)
To: Ashish Kalra, seanjc, pbonzini, tglx, mingo, bp, dave.hansen,
thomas.lendacky, shuah, prsampat
Cc: pgonda, nikunj, pankaj.gupta, michael.roth, sraithal,
linux-kernel, x86, kvm, linux-kselftest, linux-coco,
Paluri, PavanKumar (Pavan Kumar)
On 5/12/2025 5:16 PM, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
>
> 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: Pavan Kumar Paluri <papaluri@amd.com>
Thanks,
Pavan
> ---
> arch/x86/kvm/svm/sev.c | 44 +++++++++++++++++++++++++++++++++---------
> 1 file changed, 35 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index dea9480b9ff6..8c3b12e3de8c 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2935,6 +2935,33 @@ void __init sev_set_cpu_caps(void)
> }
> }
>
> +static bool is_sev_snp_initialized(void)
> +{
> + struct sev_user_data_snp_status *status;
> + struct sev_data_snp_addr buf;
> + bool initialized = false;
> + int ret, error = 0;
> +
> + status = snp_alloc_firmware_page(GFP_KERNEL | __GFP_ZERO);
> + if (!status)
> + return false;
> +
> + buf.address = __psp_pa(status);
> + ret = sev_do_cmd(SEV_CMD_SNP_PLATFORM_STATUS, &buf, &error);
> + if (ret) {
> + pr_err("SEV: SNP_PLATFORM_STATUS failed ret=%d, fw_error=%d (%#x)\n",
> + ret, error, error);
> + goto out;
> + }
> +
> + initialized = !!status->state;
> +
> +out:
> + snp_free_firmware_page(status);
> +
> + return initialized;
> +}
> +
> void __init sev_hardware_setup(void)
> {
> unsigned int eax, ebx, ecx, edx, sev_asid_count, sev_es_asid_count;
> @@ -3039,6 +3066,14 @@ void __init sev_hardware_setup(void)
> sev_snp_supported = sev_snp_enabled && cc_platform_has(CC_ATTR_HOST_SEV_SNP);
>
> out:
> + if (sev_enabled) {
> + init_args.probe = true;
> + if (sev_platform_init(&init_args))
> + sev_supported = sev_es_supported = sev_snp_supported = false;
> + else if (sev_snp_supported)
> + sev_snp_supported = is_sev_snp_initialized();
> + }
> +
> if (boot_cpu_has(X86_FEATURE_SEV))
> pr_info("SEV %s (ASIDs %u - %u)\n",
> sev_supported ? min_sev_asid <= max_sev_asid ? "enabled" :
> @@ -3065,15 +3100,6 @@ void __init sev_hardware_setup(void)
> sev_supported_vmsa_features = 0;
> if (sev_es_debug_swap_enabled)
> sev_supported_vmsa_features |= SVM_SEV_FEAT_DEBUG_SWAP;
> -
> - if (!sev_enabled)
> - return;
> -
> - /*
> - * Do both SNP and SEV initialization at KVM module load.
> - */
> - init_args.probe = true;
> - sev_platform_init(&init_args);
> }
>
> void sev_hardware_unsetup(void)
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v3] KVM: SEV: Disable SEV-SNP support on initialization failure
2025-05-12 22:16 [PATCH v3] KVM: SEV: Disable SEV-SNP support on initialization failure Ashish Kalra
2025-05-12 23:07 ` Paluri, PavanKumar
@ 2025-05-13 4:46 ` Gupta, Pankaj
2025-05-19 19:10 ` Kalra, Ashish
2025-06-11 18:27 ` Paolo Bonzini
2 siblings, 1 reply; 5+ messages in thread
From: Gupta, Pankaj @ 2025-05-13 4:46 UTC (permalink / raw)
To: Ashish Kalra, seanjc, pbonzini, tglx, mingo, bp, dave.hansen,
thomas.lendacky, shuah, prsampat
Cc: pgonda, nikunj, michael.roth, sraithal, linux-kernel, x86, kvm,
linux-kselftest, linux-coco
On 5/13/2025 12:16 AM, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
>
> 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>
LGTM
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
> ---
> arch/x86/kvm/svm/sev.c | 44 +++++++++++++++++++++++++++++++++---------
> 1 file changed, 35 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index dea9480b9ff6..8c3b12e3de8c 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2935,6 +2935,33 @@ void __init sev_set_cpu_caps(void)
> }
> }
>
> +static bool is_sev_snp_initialized(void)
> +{
> + struct sev_user_data_snp_status *status;
> + struct sev_data_snp_addr buf;
> + bool initialized = false;
> + int ret, error = 0;
> +
> + status = snp_alloc_firmware_page(GFP_KERNEL | __GFP_ZERO);
> + if (!status)
> + return false;
> +
> + buf.address = __psp_pa(status);
> + ret = sev_do_cmd(SEV_CMD_SNP_PLATFORM_STATUS, &buf, &error);
> + if (ret) {
> + pr_err("SEV: SNP_PLATFORM_STATUS failed ret=%d, fw_error=%d (%#x)\n",
> + ret, error, error);
> + goto out;
> + }
> +
> + initialized = !!status->state;
> +
> +out:
> + snp_free_firmware_page(status);
> +
> + return initialized;
> +}
> +
> void __init sev_hardware_setup(void)
> {
> unsigned int eax, ebx, ecx, edx, sev_asid_count, sev_es_asid_count;
> @@ -3039,6 +3066,14 @@ void __init sev_hardware_setup(void)
> sev_snp_supported = sev_snp_enabled && cc_platform_has(CC_ATTR_HOST_SEV_SNP);
>
> out:
> + if (sev_enabled) {
> + init_args.probe = true;
> + if (sev_platform_init(&init_args))
> + sev_supported = sev_es_supported = sev_snp_supported = false;
> + else if (sev_snp_supported)
> + sev_snp_supported = is_sev_snp_initialized();
> + }
> +
> if (boot_cpu_has(X86_FEATURE_SEV))
> pr_info("SEV %s (ASIDs %u - %u)\n",
> sev_supported ? min_sev_asid <= max_sev_asid ? "enabled" :
> @@ -3065,15 +3100,6 @@ void __init sev_hardware_setup(void)
> sev_supported_vmsa_features = 0;
> if (sev_es_debug_swap_enabled)
> sev_supported_vmsa_features |= SVM_SEV_FEAT_DEBUG_SWAP;
> -
> - if (!sev_enabled)
> - return;
> -
> - /*
> - * Do both SNP and SEV initialization at KVM module load.
> - */
> - init_args.probe = true;
> - sev_platform_init(&init_args);
> }
>
> void sev_hardware_unsetup(void)
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v3] KVM: SEV: Disable SEV-SNP support on initialization failure
2025-05-13 4:46 ` Gupta, Pankaj
@ 2025-05-19 19:10 ` Kalra, Ashish
0 siblings, 0 replies; 5+ messages in thread
From: Kalra, Ashish @ 2025-05-19 19:10 UTC (permalink / raw)
To: Gupta, Pankaj, seanjc, pbonzini, tglx, mingo, bp, dave.hansen,
thomas.lendacky, shuah, prsampat
Cc: pgonda, nikunj, michael.roth, sraithal, linux-kernel, x86, kvm,
linux-kselftest, linux-coco
Hello Sean/Paolo,
On 5/12/2025 11:46 PM, Gupta, Pankaj wrote:
> On 5/13/2025 12:16 AM, Ashish Kalra wrote:
>> From: Ashish Kalra <ashish.kalra@amd.com>
>>
>> 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>
>
> LGTM
>
> Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
>
Can you please pull in this patch.
Thanks,
Ashish
>> ---
>> arch/x86/kvm/svm/sev.c | 44 +++++++++++++++++++++++++++++++++---------
>> 1 file changed, 35 insertions(+), 9 deletions(-)
>>
>> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
>> index dea9480b9ff6..8c3b12e3de8c 100644
>> --- a/arch/x86/kvm/svm/sev.c
>> +++ b/arch/x86/kvm/svm/sev.c
>> @@ -2935,6 +2935,33 @@ void __init sev_set_cpu_caps(void)
>> }
>> }
>> +static bool is_sev_snp_initialized(void)
>> +{
>> + struct sev_user_data_snp_status *status;
>> + struct sev_data_snp_addr buf;
>> + bool initialized = false;
>> + int ret, error = 0;
>> +
>> + status = snp_alloc_firmware_page(GFP_KERNEL | __GFP_ZERO);
>> + if (!status)
>> + return false;
>> +
>> + buf.address = __psp_pa(status);
>> + ret = sev_do_cmd(SEV_CMD_SNP_PLATFORM_STATUS, &buf, &error);
>> + if (ret) {
>> + pr_err("SEV: SNP_PLATFORM_STATUS failed ret=%d, fw_error=%d (%#x)\n",
>> + ret, error, error);
>> + goto out;
>> + }
>> +
>> + initialized = !!status->state;
>> +
>> +out:
>> + snp_free_firmware_page(status);
>> +
>> + return initialized;
>> +}
>> +
>> void __init sev_hardware_setup(void)
>> {
>> unsigned int eax, ebx, ecx, edx, sev_asid_count, sev_es_asid_count;
>> @@ -3039,6 +3066,14 @@ void __init sev_hardware_setup(void)
>> sev_snp_supported = sev_snp_enabled && cc_platform_has(CC_ATTR_HOST_SEV_SNP);
>> out:
>> + if (sev_enabled) {
>> + init_args.probe = true;
>> + if (sev_platform_init(&init_args))
>> + sev_supported = sev_es_supported = sev_snp_supported = false;
>> + else if (sev_snp_supported)
>> + sev_snp_supported = is_sev_snp_initialized();
>> + }
>> +
>> if (boot_cpu_has(X86_FEATURE_SEV))
>> pr_info("SEV %s (ASIDs %u - %u)\n",
>> sev_supported ? min_sev_asid <= max_sev_asid ? "enabled" :
>> @@ -3065,15 +3100,6 @@ void __init sev_hardware_setup(void)
>> sev_supported_vmsa_features = 0;
>> if (sev_es_debug_swap_enabled)
>> sev_supported_vmsa_features |= SVM_SEV_FEAT_DEBUG_SWAP;
>> -
>> - if (!sev_enabled)
>> - return;
>> -
>> - /*
>> - * Do both SNP and SEV initialization at KVM module load.
>> - */
>> - init_args.probe = true;
>> - sev_platform_init(&init_args);
>> }
>> void sev_hardware_unsetup(void)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] KVM: SEV: Disable SEV-SNP support on initialization failure
2025-05-12 22:16 [PATCH v3] KVM: SEV: Disable SEV-SNP support on initialization failure Ashish Kalra
2025-05-12 23:07 ` Paluri, PavanKumar
2025-05-13 4:46 ` Gupta, Pankaj
@ 2025-06-11 18:27 ` Paolo Bonzini
2 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2025-06-11 18:27 UTC (permalink / raw)
To: Ashish Kalra
Cc: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, thomas.lendacky,
shuah, prsampat, pgonda, nikunj, pankaj.gupta, michael.roth,
sraithal, linux-kernel, x86, kvm, linux-kselftest, linux-coco
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread