Derived from kvm-unit-tests. Reviewed-by: Jim Mattson <jmattson@xxxxxxxxxx> Reviewed-by: Peter Shier <pshier@xxxxxxxxxx> Signed-off-by: Oliver Upton <oupton@xxxxxxxxxx> --- .../selftests/kvm/include/x86_64/processor.h | 15 +++++++++++++++ .../selftests/kvm/include/x86_64/svm_util.h | 7 ++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 82b7fe16a824..316fbd4700ef 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -338,6 +338,21 @@ uint32_t kvm_get_cpuid_max_basic(void); uint32_t kvm_get_cpuid_max_extended(void); void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits); +struct cpuid { + u32 a, b, c, d; +}; + +static inline struct cpuid raw_cpuid(u32 function, u32 index) +{ + struct cpuid r; + + asm volatile("cpuid" + : "=a"(r.a), "=b"(r.b), "=c"(r.c), "=d"(r.d) + : "0"(function), "2"(index)); + + return r; +} + /* * Basic CPU control in CR0 */ diff --git a/tools/testing/selftests/kvm/include/x86_64/svm_util.h b/tools/testing/selftests/kvm/include/x86_64/svm_util.h index b7531c83b8ae..47a13aaee460 100644 --- a/tools/testing/selftests/kvm/include/x86_64/svm_util.h +++ b/tools/testing/selftests/kvm/include/x86_64/svm_util.h @@ -38,12 +38,9 @@ void nested_svm_check_supported(void); static inline bool cpu_has_svm(void) { - u32 eax = 0x80000001, ecx; + struct cpuid r = raw_cpuid(0x80000001, 0); - asm("cpuid" : - "=a" (eax), "=c" (ecx) : "0" (eax) : "ebx", "edx"); - - return ecx & CPUID_SVM; + return r.c & CPUID_SVM; } #endif /* SELFTEST_KVM_SVM_UTILS_H */ -- 2.28.0.rc0.142.g3c755180ce-goog