Re: [PATCH] kvm: x86: Make traced and returned value of kvm_cpuid consistent again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/1/2020 6:47 PM, 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. This is currently harmless for the return
value because the only caller evaluating it passes leaf 0x80000008.

Nice catch!

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.

BTW, the trace lacks subleaf(ECX) info, it's meaning for the the leaf does have a subleaf, maybe we'd better add it?

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;
  	bool found;

  	entry = kvm_find_cpuid_entry(vcpu, function, index);
-	found = entry;
  	/*
  	 * Intel CPUID semantics treats any query for an out-of-range
  	 * leaf as if the highest basic leaf (i.e. CPUID.0H:EAX) were
@@ -1049,7 +1048,8 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
  			}
  		}
  	}
-	trace_kvm_cpuid(function, *eax, *ebx, *ecx, *edx, found);
+	found = entry;
+	trace_kvm_cpuid(orig_function, *eax, *ebx, *ecx, *edx, found);
  	return found;
  }
  EXPORT_SYMBOL_GPL(kvm_cpuid);
--
2.16.4





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux