From: Yang Weijiang <weijiang.yang@intel.com>
To: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: like.xu.linux@gmail.com, Yang Weijiang <weijiang.yang@intel.com>
Subject: [PATCH] KVM: x86: Bypass cpuid check for empty arch-lbr leaf
Date: Mon, 30 May 2022 10:48:29 -0400 [thread overview]
Message-ID: <20220530144829.39714-1-weijiang.yang@intel.com> (raw)
On arch-lbr capable platforms, cpuid(0x1c,0) returns meaningful
arch-lbr supported values, in this case, eax[7:0] = lbr depth mask.
Whereas on legacy platforms(non-arch-lbr), cpuid(0x1c,0) returns
with eax/ebx/ecx/edx zeroed out.
On legacy platforms, during selftests app startup, it first gets
supported cpuids by KVM_GET_SUPPORTED_CPUID then sets the returned
data with KVM_SET_CPUID2, this leads to empty cpuid leaf(0x1c,0)
written to KVM and makes the check fail, app finally ends up with
below error message when run selftest:
KVM_SET_CPUID2 failed, rc: -1 errno: 22
So check the validity of the leaf(0x1c,0) before validate lbr
depth value.
QEMU filters out empty CPUID leaves before calls KVM_SET_CPUID2,
so this is not a problem.
Fixes: 4b73207592: ("KVM: x86/cpuid: Advertise Arch LBR feature in CPUID")
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
---
arch/x86/kvm/cpuid.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 9c107b5cc88f..c2eab1a73aab 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -103,13 +103,14 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu,
return -EINVAL;
}
best = cpuid_entry2_find(entries, nent, 0x1c, 0);
- if (best) {
+ if (best && best->eax) {
unsigned int eax, ebx, ecx, edx;
/* Reject user-space CPUID if depth is different from host's.*/
cpuid_count(0x1c, 0, &eax, &ebx, &ecx, &edx);
- if ((best->eax & 0xff) != BIT(fls(eax & 0xff) - 1))
+ if ((eax & 0xff) &&
+ (best->eax & 0xff) != BIT(fls(eax & 0xff) - 1))
return -EINVAL;
}
--
2.27.0
next reply other threads:[~2022-05-30 15:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-30 14:48 Yang Weijiang [this message]
2022-05-31 17:15 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220530144829.39714-1-weijiang.yang@intel.com \
--to=weijiang.yang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®