diff options
author | Sean Christopherson <seanjc@google.com> | 2022-06-02 12:24:18 -0700 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2022-06-11 11:46:28 -0400 |
commit | 2128e30b01867a4d5e41bbaba8e35bcca7537f3b (patch) | |
tree | dd3667daba0196b3fd70cd589113de80a8b647df /tools/testing/selftests/kvm/lib/x86_64 | |
parent | 0ce74180f306981534d023199017a90b77a92004 (diff) | |
download | linux-next-2128e30b01867a4d5e41bbaba8e35bcca7537f3b.tar.gz |
KVM: selftests: Dedup MSR index list helpers, simplify dedicated test
Consolidate the helper for retrieving the list of save/restore MSRs and
the list of feature MSRs, and use the common helpers in the related
get_msr_index_features test. Switching to the common helpers eliminates
the testcase that KVM returns the same -E2BIG result if the input number
of MSRs is '1' versus '0', but considered that testcase isn't very
interesting, e.g. '0' and '1' are equally arbitrary, and certainly not
worth the additional code.
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests/kvm/lib/x86_64')
-rw-r--r-- | tools/testing/selftests/kvm/lib/x86_64/processor.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 3f83857009a3..18fce5e8a5e5 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -891,19 +891,20 @@ void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent) sregs_dump(stream, &sregs, indent + 4); } -const struct kvm_msr_list *kvm_get_msr_index_list(void) +static struct kvm_msr_list *__kvm_get_msr_index_list(bool feature_msrs) { - static struct kvm_msr_list *list; + struct kvm_msr_list *list; struct kvm_msr_list nmsrs; int kvm_fd, r; - if (list) - return list; - kvm_fd = open_kvm_dev_path_or_exit(); nmsrs.nmsrs = 0; - r = __kvm_ioctl(kvm_fd, KVM_GET_MSR_INDEX_LIST, &nmsrs); + if (!feature_msrs) + r = __kvm_ioctl(kvm_fd, KVM_GET_MSR_INDEX_LIST, &nmsrs); + else + r = __kvm_ioctl(kvm_fd, KVM_GET_MSR_FEATURE_INDEX_LIST, &nmsrs); + TEST_ASSERT(r == -1 && errno == E2BIG, "Expected -E2BIG, got rc: %i errno: %i (%s)", r, errno, strerror(errno)); @@ -912,15 +913,37 @@ const struct kvm_msr_list *kvm_get_msr_index_list(void) TEST_ASSERT(list, "-ENOMEM when allocating MSR index list"); list->nmsrs = nmsrs.nmsrs; - kvm_ioctl(kvm_fd, KVM_GET_MSR_INDEX_LIST, list); + if (!feature_msrs) + kvm_ioctl(kvm_fd, KVM_GET_MSR_INDEX_LIST, list); + else + kvm_ioctl(kvm_fd, KVM_GET_MSR_FEATURE_INDEX_LIST, list); close(kvm_fd); TEST_ASSERT(list->nmsrs == nmsrs.nmsrs, - "Number of save/restore MSRs changed, was %d, now %d", + "Number of MSRs in list changed, was %d, now %d", nmsrs.nmsrs, list->nmsrs); return list; } +const struct kvm_msr_list *kvm_get_msr_index_list(void) +{ + static const struct kvm_msr_list *list; + + if (!list) + list = __kvm_get_msr_index_list(false); + return list; +} + + +const struct kvm_msr_list *kvm_get_feature_msr_index_list(void) +{ + static const struct kvm_msr_list *list; + + if (!list) + list = __kvm_get_msr_index_list(true); + return list; +} + bool kvm_msr_is_in_save_restore_list(uint32_t msr_index) { const struct kvm_msr_list *list = kvm_get_msr_index_list(); |