Skip to contentSkip to conversation

AMX KVM selftest

PATCH In review Yang Zhong 2 participants 5 messages Dec 23, 2021

Subsystems (2)
lore
Share & tools
lore

Yang Zhong

author
#0 lore raw

v3 cover AMX KVM selftest

Hi Paolo,

Please help review this patchset, which is rebased on Jing's AMX v3.
https://lore.kernel.org/all/[email protected]/

About this selftest requirement, please check below link:
https://lore.kernel.org/all/[email protected]/

By the way, this amx_test.c file referenced some Chang's older test code:
https://lore.kernel.org/lkml/[email protected]/

Thanks!

Yang

Change history
==============
v2-->v3:
- Removed the skip "regs->rip += 3", enable amx in #NM handler(Paolo).

v1-->v2
- Added more GUEST_SYNC() from guest code(Paolo).
- Added back save/restore code after GUEST_SYNC() handles in the main()(Paolo).

Paolo Bonzini (1):
selftest: kvm: Reorder vcpu_load_state steps for AMX

Yang Zhong (2):
selftest: kvm: Move struct kvm_x86_state to header
selftest: kvm: Support amx selftest

 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/include/x86_64/processor.h  |  16 +-
 .../selftests/kvm/lib/x86_64/processor.c      |  32 +-
 tools/testing/selftests/kvm/x86_64/amx_test.c | 448 ++++++++++++++++++
 4 files changed, 473 insertions(+), 24 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/x86_64/amx_test.c
author
#1 lore raw

PATCH v3 1/3 selftest: kvm: Reorder vcpu_load_state steps for AMX

From: Paolo Bonzini <[email protected]>

For AMX support it is recommended to load XCR0 after XFD, so that KVM does not see XFD=0, XCR=1 for a save state that will eventually be disabled (which would lead to premature allocation of the space required for that save state).

It is also required to load XSAVE data after XCR0 and XFD, so that KVM can trigger allocation of the extra space required to store AMX state.

Adjust vcpu_load_state to obey these new requirements.

---
 .../selftests/kvm/lib/x86_64/processor.c        | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
tools/testing/selftests/kvm/lib/x86_64/processor.c +9 -8
index f19d6d201977..93264424aee5 100644
@@ -1212,24 +1212,25 @@ void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s
 	struct vcpu *vcpu = vcpu_find(vm, vcpuid);
 	int r;
 
-	r = ioctl(vcpu->fd, KVM_SET_XSAVE, state->xsave);
-        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XSAVE, r: %i",
+	r = ioctl(vcpu->fd, KVM_SET_SREGS, &state->sregs);
+	TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_SREGS, r: %i",
                 r);
 
+	r = ioctl(vcpu->fd, KVM_SET_MSRS, &state->msrs);
+	TEST_ASSERT(r == state->msrs.nmsrs,
+		"Unexpected result from KVM_SET_MSRS, r: %i (failed at %x)",
+		r, r == state->msrs.nmsrs ? -1 : state->msrs.entries[r].index);
+
 	if (kvm_check_cap(KVM_CAP_XCRS)) {
 		r = ioctl(vcpu->fd, KVM_SET_XCRS, &state->xcrs);
 		TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XCRS, r: %i",
 			    r);
 	}
 
-	r = ioctl(vcpu->fd, KVM_SET_SREGS, &state->sregs);
-        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_SREGS, r: %i",
+	r = ioctl(vcpu->fd, KVM_SET_XSAVE, state->xsave);
+	TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XSAVE, r: %i",
                 r);
 
-	r = ioctl(vcpu->fd, KVM_SET_MSRS, &state->msrs);
-        TEST_ASSERT(r == state->msrs.nmsrs, "Unexpected result from KVM_SET_MSRS, r: %i (failed at %x)",
-                r, r == state->msrs.nmsrs ? -1 : state->msrs.entries[r].index);
-
 	r = ioctl(vcpu->fd, KVM_SET_VCPU_EVENTS, &state->events);
         TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_VCPU_EVENTS, r: %i",
                 r);
author
#2 lore raw

PATCH v3 2/3 selftest: kvm: Move struct kvm_x86_state to header

In reply to Yang Zhong

Those changes can avoid dereferencing pointer compile issue when amx_test.c reference state->xsave.

Move struct kvm_x86_state definition to processor.h.

---
 .../selftests/kvm/include/x86_64/processor.h     | 16 +++++++++++++++-
 .../testing/selftests/kvm/lib/x86_64/processor.c | 15 ---------------
 2 files changed, 15 insertions(+), 16 deletions(-)
tools/testing/selftests/kvm/include/x86_64/processor.h +15 -1
index 58633e51960f..e94ba0fc67d8 100644
@@ -94,6 +94,21 @@ struct desc_ptr {
 	uint64_t address;
 } __attribute__((packed));
 
+struct kvm_x86_state {
+	struct kvm_xsave *xsave;
+	struct kvm_vcpu_events events;
+	struct kvm_mp_state mp_state;
+	struct kvm_regs regs;
+	struct kvm_xcrs xcrs;
+	struct kvm_sregs sregs;
+	struct kvm_debugregs debugregs;
+	union {
+		struct kvm_nested_state nested;
+		char nested_[16384];
+	};
+	struct kvm_msrs msrs;
+};
+
 static inline uint64_t get_desc64_base(const struct desc64 *desc)
 {
 	return ((uint64_t)desc->base3 << 32) |
@@ -350,7 +365,6 @@ static inline unsigned long get_xmm(int n)
 
 bool is_intel_cpu(void);
 
-struct kvm_x86_state;
 struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, uint32_t vcpuid);
 void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid,
 		     struct kvm_x86_state *state);
tools/testing/selftests/kvm/lib/x86_64/processor.c +0 -15
index 93264424aee5..babb0f28575c 100644
@@ -1056,21 +1056,6 @@ void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent)
 	sregs_dump(stream, &sregs, indent + 4);
 }
 
-struct kvm_x86_state {
-	struct kvm_xsave *xsave;
-	struct kvm_vcpu_events events;
-	struct kvm_mp_state mp_state;
-	struct kvm_regs regs;
-	struct kvm_xcrs xcrs;
-	struct kvm_sregs sregs;
-	struct kvm_debugregs debugregs;
-	union {
-		struct kvm_nested_state nested;
-		char nested_[16384];
-	};
-	struct kvm_msrs msrs;
-};
-
 static int kvm_get_num_msrs_fd(int kvm_fd)
 {
 	struct kvm_msr_list nmsrs;
author
#3 lore raw

PATCH v3 3/3 selftest: kvm: Support amx selftest

In reply to Yang Zhong

This selftest do two test cases, one is to trigger #NM exception and check MSR XFD_ERR value. Another case is guest load tile data into tmm0 registers and trap to host side to check memory data after save/restore.

---
 tools/testing/selftests/kvm/Makefile          |   1 +
 tools/testing/selftests/kvm/x86_64/amx_test.c | 448 ++++++++++++++++++
 2 files changed, 449 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/x86_64/amx_test.c
tools/testing/selftests/kvm/Makefile +1 -0
index 17342b575e85..57369580749f 100644
@@ -77,6 +77,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/xen_shinfo_test
 TEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test
 TEST_GEN_PROGS_x86_64 += x86_64/vmx_pi_mmio_test
 TEST_GEN_PROGS_x86_64 += x86_64/sev_migrate_tests
+TEST_GEN_PROGS_x86_64 += x86_64/amx_test
 TEST_GEN_PROGS_x86_64 += demand_paging_test
 TEST_GEN_PROGS_x86_64 += dirty_log_test
 TEST_GEN_PROGS_x86_64 += dirty_log_perf_test
tools/testing/selftests/kvm/x86_64/amx_test.c new file +448 -0

448 lines not on this page · raw message

maintainer Reviewed-by on the v3 series
#4 lore raw
In reply to Yang Zhong
Quoted 10 lines · Yang Zhong

Hi Paolo,

Please help review this patchset, which is rebased on Jing's AMX v3.
https://lore.kernel.org/all/[email protected]/

About this selftest requirement, please check below link:
https://lore.kernel.org/all/[email protected]/

By the way, this amx_test.c file referenced some Chang's older test code:
https://lore.kernel.org/lkml/[email protected]/

Paolo

Quoted 31 lines

Thanks!

Yang

Change history
==============
v2-->v3:
- Removed the skip "regs->rip += 3", enable amx in #NM handler(Paolo).

v1-->v2
- Added more GUEST_SYNC() from guest code(Paolo).
- Added back save/restore code after GUEST_SYNC() handles in the main()(Paolo).

Paolo Bonzini (1):
selftest: kvm: Reorder vcpu_load_state steps for AMX

Yang Zhong (2):
selftest: kvm: Move struct kvm_x86_state to header
selftest: kvm: Support amx selftest

  tools/testing/selftests/kvm/Makefile          |   1 +
  .../selftests/kvm/include/x86_64/processor.h  |  16 +-
  .../selftests/kvm/lib/x86_64/processor.c      |  32 +-
  tools/testing/selftests/kvm/x86_64/amx_test.c | 448 ++++++++++++++++++
  4 files changed, 473 insertions(+), 24 deletions(-)

create mode 100644 tools/testing/selftests/kvm/x86_64/amx_test.c