On 25/11/2022 12:06 pm, Yang Weijiang wrote:
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 85e3df6217af..60b3c591d462 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -134,6 +134,19 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu, if (vaddr_bits != 48 && vaddr_bits != 57 && vaddr_bits != 0) return -EINVAL; } + if (kvm_cpu_cap_has(X86_FEATURE_ARCH_LBR)) { + best = cpuid_entry2_find(entries, nent, 0x1c, 0); + if (best) { + unsigned int eax, ebx, ecx, edx; + + /* Reject user-space CPUID if depth is different from host's.*/
Try to verify this in the KVM selftest, as this behavior is different from the host.
+ cpuid_count(0x1c, 0, &eax, &ebx, &ecx, &edx); > + + if ((eax & 0xff) && + (best->eax & 0xff) != BIT(fls(eax & 0xff) - 1)) + return -EINVAL; + } + }