Message ID | 20220113011453.3892612-4-jmattson@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | KVM: x86/pmu: Use binary search to check filtered events | expand |
Jim, On Wed, Jan 12, 2022 at 5:15 PM Jim Mattson <jmattson@google.com> wrote: > +bool is_amd_cpu(void) > +{ > + return cpu_vendor_string_is("AuthenticAMD") || > + cpu_vendor_string_is("AMDisbetter!"); > +} > + The original code only checked for AuthenticAMD. I don't think it is necessary or wise to add the check for early K5 samples. Do we know whether they even need this KVM logic? Dave Dunn
On Thu, Jan 13, 2022 at 8:51 AM David Dunn <daviddunn@google.com> wrote: > > Jim, > > On Wed, Jan 12, 2022 at 5:15 PM Jim Mattson <jmattson@google.com> wrote: > > > +bool is_amd_cpu(void) > > +{ > > + return cpu_vendor_string_is("AuthenticAMD") || > > + cpu_vendor_string_is("AMDisbetter!"); > > +} > > + > > The original code only checked for AuthenticAMD. I don't think it is > necessary or wise to add the check for early K5 samples. Do we know > whether they even need this KVM logic? The original code should handle K5 CPUs in the next block: /* On parts with <40 physical address bits, the area is fully hidden */ if (vm->pa_bits < 40) return max_gfn; But, you're right. K5 predates AMD support for SVM, so we don't need to test kvm functionality on early K5 samples. I'll remove the second disjunct in v2. Thanks!
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 05e65ca1c30c..69eaf9a69bb7 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -347,6 +347,7 @@ static inline unsigned long get_xmm(int n) } bool is_intel_cpu(void); +bool is_amd_cpu(void); struct kvm_x86_state; struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, uint32_t vcpuid); diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 355a3f6f1970..fdd259c1ab49 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1218,6 +1218,12 @@ bool is_intel_cpu(void) return cpu_vendor_string_is("GenuineIntel"); } +bool is_amd_cpu(void) +{ + return cpu_vendor_string_is("AuthenticAMD") || + cpu_vendor_string_is("AMDisbetter!"); +} + uint32_t kvm_get_cpuid_max_basic(void) { return kvm_get_supported_cpuid_entry(0)->eax; @@ -1436,10 +1442,6 @@ struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vm *vm, uint32_t vcpui return cpuid; } -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx 0x68747541 -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163 -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_edx 0x69746e65 - static inline unsigned x86_family(unsigned int eax) { unsigned int x86; @@ -1463,9 +1465,7 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm) /* Avoid reserved HyperTransport region on AMD processors. */ eax = ecx = 0; cpuid(&eax, &ebx, &ecx, &edx); - if (ebx != X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx || - ecx != X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx || - edx != X86EMUL_CPUID_VENDOR_AuthenticAMD_edx) + if (!is_amd_cpu()) return max_gfn; /* On parts with <40 physical address bits, the area is fully hidden */
Replace the one ad hoc "AuthenticAMD" CPUID vendor string comparison with a new function, is_amd_cpu(). Signed-off-by: Jim Mattson <jmattson@google.com> --- .../selftests/kvm/include/x86_64/processor.h | 1 + tools/testing/selftests/kvm/lib/x86_64/processor.c | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-)