Skip to content

Commit 4b3b8a8

Browse files
00xcbonzini
authored andcommitted
KVM: x86: synthesize CPUID bits only if CPU capability is set
KVM incorrectly synthesizes CPUID bits for KVM-only leaves, as the following branch in kvm_cpu_cap_init() is never taken: if (leaf < NCAPINTS) kvm_cpu_caps[leaf] &= kernel_cpu_caps[leaf]; This means that bits set via SYNTHESIZED_F() for KVM-only leaves are unconditionally set. This for example can cause issues for SEV-SNP guests running on Family 19h CPUs, as TSA_SQ_NO and TSA_L1_NO are always enabled by KVM in 80000021[ECX]. When userspace issues a SNP_LAUNCH_UPDATE command to update the CPUID page for the guest, SNP firmware will explicitly reject the command if the page sets sets these bits on vulnerable CPUs. To fix this, check in SYNTHESIZED_F() that the corresponding X86 capability is set before adding it to to kvm_cpu_cap_features. Fixes: 31272ab ("KVM: SVM: Advertise TSA CPUID bits to guests") Link: https://lore.kernel.org/all/20260208164233.30405-1-clopez@suse.de/ Signed-off-by: Carlos López <clopez@suse.de> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com> Link: https://patch.msgid.link/20260209153108.70667-2-clopez@suse.de Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent fe2a08e commit 4b3b8a8

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

arch/x86/kvm/cpuid.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,10 @@ do { \
776776
#define SYNTHESIZED_F(name) \
777777
({ \
778778
kvm_cpu_cap_synthesized |= feature_bit(name); \
779-
F(name); \
779+
\
780+
BUILD_BUG_ON(X86_FEATURE_##name >= MAX_CPU_FEATURES); \
781+
if (boot_cpu_has(X86_FEATURE_##name)) \
782+
F(name); \
780783
})
781784

782785
/*

0 commit comments

Comments
 (0)