diff options
author | Sean Christopherson <seanjc@google.com> | 2022-10-06 03:51:18 +0300 |
---|---|---|
committer | Sean Christopherson <seanjc@google.com> | 2022-11-17 03:59:04 +0300 |
commit | a29e6e383b0d0d59a93ebbf6e93d3d41b905d336 (patch) | |
tree | b5424cfb3449d056c67b70a137f04d0eb9741f9b | |
parent | d80ddad2a8e042e6499d69d5a45a17051092e161 (diff) | |
download | linux-a29e6e383b0d0d59a93ebbf6e93d3d41b905d336.tar.xz |
KVM: selftests: Refactor kvm_cpuid_has() to prep for X86_PROPERTY_* support
Refactor kvm_cpuid_has() to prepare for extending X86_PROPERTY_* support
to KVM as well as "this CPU".
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/r/20221006005125.680782-6-seanjc@google.com
-rw-r--r-- | tools/testing/selftests/kvm/lib/x86_64/processor.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 23321c1d0631..710e5851a863 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -652,8 +652,9 @@ const struct kvm_cpuid2 *kvm_get_supported_cpuid(void) return cpuid; } -bool kvm_cpuid_has(const struct kvm_cpuid2 *cpuid, - struct kvm_x86_cpu_feature feature) +static uint32_t __kvm_cpu_has(const struct kvm_cpuid2 *cpuid, + uint32_t function, uint32_t index, + uint8_t reg, uint8_t lo, uint8_t hi) { const struct kvm_cpuid_entry2 *entry; int i; @@ -666,12 +667,18 @@ bool kvm_cpuid_has(const struct kvm_cpuid2 *cpuid, * order, but kvm_x86_cpu_feature matches that mess, so yay * pointer shenanigans! */ - if (entry->function == feature.function && - entry->index == feature.index) - return (&entry->eax)[feature.reg] & BIT(feature.bit); + if (entry->function == function && entry->index == index) + return ((&entry->eax)[reg] & GENMASK(hi, lo)) >> lo; } - return false; + return 0; +} + +bool kvm_cpuid_has(const struct kvm_cpuid2 *cpuid, + struct kvm_x86_cpu_feature feature) +{ + return __kvm_cpu_has(cpuid, feature.function, feature.index, + feature.reg, feature.bit, feature.bit); } uint64_t kvm_get_feature_msr(uint64_t msr_index) |