Skip to contentSkip to conversation

KVM: selftests: Add get featured msrs test case

PATCH New Peter Xu 1 participant 1 message Nov 2, 2020

Subsystems (2)
lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH v2 1/1 KVM: selftests: Add get featured msrs test case

Try to fetch any supported featured msr. Currently it won't fail, so at least we can check against valid ones (which should be >0).

This reproduces the issue [1] too by trying to fetch one invalid msr there.

[1] https://bugzilla.kernel.org/show_bug.cgi?id=209845

--
v2:
- rename kvm_vm_get_feature_msrs to be prefixed with "_" [Vitaly, Drew]
- drop the fix patch since queued with a better version

---
 .../testing/selftests/kvm/include/kvm_util.h  |  3 +
 tools/testing/selftests/kvm/lib/kvm_util.c    | 14 +++++
 .../testing/selftests/kvm/x86_64/state_test.c | 58 +++++++++++++++++++
 3 files changed, 75 insertions(+)
tools/testing/selftests/kvm/include/kvm_util.h +3 -0
index 919e161dd289..1199f2003bee 100644
@@ -66,6 +66,9 @@ int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap);
 
 struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm);
 struct kvm_vm *_vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm);
+void kvm_vm_get_msr_feature_index_list(struct kvm_vm *vm,
+				       struct kvm_msr_list *list);
+int _kvm_vm_get_feature_msrs(struct kvm_vm *vm, struct kvm_msrs *msrs);
 void kvm_vm_free(struct kvm_vm *vmp);
 void kvm_vm_restart(struct kvm_vm *vmp, int perm);
 void kvm_vm_release(struct kvm_vm *vmp);
tools/testing/selftests/kvm/lib/kvm_util.c +14 -0
index 74776ee228f2..ad81d51fcf53 100644
@@ -132,6 +132,20 @@ static const struct vm_guest_mode_params vm_guest_mode_params[] = {
 _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
 	       "Missing new mode params?");
 
+void kvm_vm_get_msr_feature_index_list(struct kvm_vm *vm,
+				       struct kvm_msr_list *list)
+{
+	int r = ioctl(vm->kvm_fd, KVM_GET_MSR_FEATURE_INDEX_LIST, list);
+
+	TEST_ASSERT(r == 0, "KVM_GET_MSR_FEATURE_INDEX_LIST failed: %d\n",
+		    -errno);
+}
+
+int _kvm_vm_get_feature_msrs(struct kvm_vm *vm, struct kvm_msrs *msrs)
+{
+	return ioctl(vm->kvm_fd, KVM_GET_MSRS, msrs);
+}
+
 /*
  * VM Create
  *
tools/testing/selftests/kvm/x86_64/state_test.c +58 -0

70 lines not on this page · raw message

Signature · 1 line
2.26.2