On 02.03.20 17:38, Sean Christopherson wrote:
On Mon, Mar 02, 2020 at 05:11:57PM +0100, Paolo Bonzini wrote:
Queued, thanks.
Too fast, too fast!
On Sun, Mar 01, 2020 at 11:47:20AM +0100, Jan Kiszka wrote:
From: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
After 43561123ab37, found is not set correctly in case of leaves 0BH,
1FH, or anything out-of-range.
No, found is set correctly, kvm_cpuid() should return true if and only if
an exact match for the requested function is found, and that's the original
tracing behavior of "found" (pre-43561123ab37).
This is currently harmless for the return value because the only caller
evaluating it passes leaf 0x80000008.
No, it's 100% correct. Well, technically it's irrelevant because the only
caller, check_cr_write(), passes %false for check_limit, i.e. found will be
true if and only if entry 0x80000008 exists. But, in a purely hypothetical
scenario where the emulator passed check_limit=%true, the intent of "found"
is to report that the exact leaf was found, not if some random entry was
found.
Nicely non-intuitive semantics. Should definitely be documented.
And then it's questionable to me what value tracing such a return code
has. At the bare minimum, "found" should be renamed to something like
"exact_match".
However, the trace entry is now misleading due to this inaccuracy. It is
furthermore misleading because it reports the effective function, not
the originally passed one. Fix that as well.
Fixes: 43561123ab37 ("kvm: x86: Improve emulation of CPUID leaves 0BH and 1FH")
Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
arch/x86/kvm/cpuid.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index b1c469446b07..79a738f313f8 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1000,13 +1000,12 @@ static bool cpuid_function_in_range(struct kvm_vcpu *vcpu, u32 function)
bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
u32 *ecx, u32 *edx, bool check_limit)
{
- u32 function = *eax, index = *ecx;
+ u32 orig_function = *eax, function = *eax, index = *ecx;
struct kvm_cpuid_entry2 *entry;
struct kvm_cpuid_entry2 *max;
Rather than add another variable, this can be cleaned up to remove "max".
cpuid_function_in_range() also has a bug. I've got patches, in the process
of whipping up a unit test.
Fine with me.
Jan
--
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux