[PATCH 4/5] kvm/sev: mask off firmware unsupported vm types

Tycho Andersen posted 5 patches 1 month ago
There is a newer version of this series
[PATCH 4/5] kvm/sev: mask off firmware unsupported vm types
Posted by Tycho Andersen 1 month ago
From: "Tycho Andersen (AMD)" <tycho@kernel.org>

In some configurations not all VM types are supported by the firmware.
Reflect this information in the supported_vm_types that KVM exports.

Link: https://lore.kernel.org/all/aZyLIWtffvEnmtYh@google.com/
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
---
 arch/x86/kvm/svm/sev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index f941d48626d3..eeae39af63a9 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -2976,6 +2976,8 @@ void __init sev_set_cpu_caps(void)
 		supported_vm_types |= BIT(KVM_X86_SNP_VM);
 	}
 
+	supported_vm_types &= sev_firmware_supported_vm_types();
+
 	kvm_caps.supported_vm_types |= supported_vm_types;
 }
 
-- 
2.53.0
Re: [PATCH 4/5] kvm/sev: mask off firmware unsupported vm types
Posted by Sean Christopherson 3 weeks, 6 days ago
KVM: SEV:

On Tue, Mar 03, 2026, Tycho Andersen wrote:
> From: "Tycho Andersen (AMD)" <tycho@kernel.org>
> 
> In some configurations not all VM types are supported by the firmware.
> Reflect this information in the supported_vm_types that KVM exports.
> 
> Link: https://lore.kernel.org/all/aZyLIWtffvEnmtYh@google.com/
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
> ---
>  arch/x86/kvm/svm/sev.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index f941d48626d3..eeae39af63a9 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2976,6 +2976,8 @@ void __init sev_set_cpu_caps(void)
>  		supported_vm_types |= BIT(KVM_X86_SNP_VM);
>  	}
>  
> +	supported_vm_types &= sev_firmware_supported_vm_types();
> +
>  	kvm_caps.supported_vm_types |= supported_vm_types;

To save one whole line (two, counting whitespace!), and to guard against future
changes, I vote for:

	kvm_caps.supported_vm_types |= supported_vm_types &
				       sev_firmware_supported_vm_types();

or if parentheses would make it clearer:

	kvm_caps.supported_vm_types |= (supported_vm_types &
				        sev_firmware_supported_vm_types());

I spent a silly amount of time fiddling with the code to try and avoid the local
variable, and failed.