Skip to contentSkip to conversation

AMX KVM selftest

PATCH Superseded Yang Zhong 3 participants 9 messages Dec 22, 2021 – Jan 13, 2022

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yang Zhong

author
#0 lore raw

v2 cover AMX KVM selftest

Hi Paolo,

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

Since Jing's v3 was justly sent out, I will rebase this patchest on it and send my separate v3.

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
==============
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      |  44 +-
 tools/testing/selftests/kvm/x86_64/amx_test.c | 451 ++++++++++++++++++
 4 files changed, 482 insertions(+), 30 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/x86_64/amx_test.c
author
#1 lore raw

PATCH v2 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      | 29 ++++++++++---------
 1 file changed, 15 insertions(+), 14 deletions(-)
tools/testing/selftests/kvm/lib/x86_64/processor.c +15 -14
index 00324d73c687..9b5abf488211 100644
@@ -1192,9 +1192,14 @@ 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);
+	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);
@@ -1202,17 +1207,13 @@ void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s
 			    r);
 	}
 
-	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);
+	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_VCPU_EVENTS, &state->events);
-        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_VCPU_EVENTS, r: %i",
-                r);
+	TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_VCPU_EVENTS, r: %i",
+		r);
 
 	r = ioctl(vcpu->fd, KVM_SET_MP_STATE, &state->mp_state);
         TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_MP_STATE, r: %i",
@@ -1223,8 +1224,8 @@ void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s
                 r);
 
 	r = ioctl(vcpu->fd, KVM_SET_REGS, &state->regs);
-        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_REGS, r: %i",
-                r);
+	TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_REGS, r: %i",
+		r);
 
 	if (state->nested.size) {
 		r = ioctl(vcpu->fd, KVM_SET_NESTED_STATE, &state->nested);
#2 lore raw

Re: [WARNING: UNSCANNABLE EXTRACTION FAILED][PATCH v2 1/3] selftest: kvm: Reorder vcpu_load_state steps for AMX

Quoted 6 lines · Yang Zhong

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 would be very helpful to clarify that XFD is loaded via KVM_SET_MSRS. It took me longer than it should have to understand what was going on. The large amount of whitespace noise in this patch certainly didn't help. E.g. just a simple tweak:

For AMX support it is recommended to load XCR0 after XFD, i.e. after MSRs, so

Quoted 17 lines

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      | 29 ++++++++++---------
 1 file changed, 15 insertions(+), 14 deletions(-)
tools/testing/selftests/kvm/lib/x86_64/processor.c +0 -0
index 00324d73c687..9b5abf488211 100644

tools/testing/selftests/kvm/lib/x86_64/processor.c void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s · line 1197

Quoted 9 lines
tools/testing/selftests/kvm/lib/x86_64/processor.c +3 -3
@@ -1192,9 +1192,14 @@ 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);
+	r = ioctl(vcpu->fd, KVM_SET_SREGS, &state->sregs);
+	TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_SREGS, r: %i",
+		r);

If we're going to bother replacing spaces with tabs, might as well get rid of all the gratuituous newlines as well.

tools/testing/selftests/kvm/lib/x86_64/processor.c void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s · line 1202

Quoted 5 lines
tools/testing/selftests/kvm/lib/x86_64/processor.c +5 -0
+
+	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);

Most people not named "Paolo" prefer to align this with the opening "(" :-)

E.g.

tools/testing/selftests/kvm/lib/x86_64/processor.c +10 -18
index 97f8c2f2df36..971f41afa689 100644
@@ -1158,44 +1158,36 @@ void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s
        int r;
 
        r = ioctl(vcpu->fd, KVM_SET_SREGS, &state->sregs);
-       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_SREGS, r: %i",
-               r);
+       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);
+                   "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);
+               TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XCRS, r: %i", r);
        }
 
        r = ioctl(vcpu->fd, KVM_SET_XSAVE, &state->xsave);
-       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XSAVE, r: %i",
-               r);
+       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XSAVE, r: %i", r);
 
        r = ioctl(vcpu->fd, KVM_SET_VCPU_EVENTS, &state->events);
-       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_VCPU_EVENTS, r: %i",
-               r);
+       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_VCPU_EVENTS, r: %i", r);
 
        r = ioctl(vcpu->fd, KVM_SET_MP_STATE, &state->mp_state);
-        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_MP_STATE, r: %i",
-                r);
+        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_MP_STATE, r: %i", r);
 
        r = ioctl(vcpu->fd, KVM_SET_DEBUGREGS, &state->debugregs);
-        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_DEBUGREGS, r: %i",
-                r);
+        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_DEBUGREGS, r: %i", r);
 
        r = ioctl(vcpu->fd, KVM_SET_REGS, &state->regs);
-       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_REGS, r: %i",
-               r);
+       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_REGS, r: %i", r);
 
        if (state->nested.size) {
                r = ioctl(vcpu->fd, KVM_SET_NESTED_STATE, &state->nested);
-               TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_NESTED_STATE, r: %i",
-                       r);
+               TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_NESTED_STATE, r: %i", r);
        }
 }
 
author
#3 lore raw

Re: [WARNING: UNSCANNABLE EXTRACTION FAILED][PATCH v2 1/3] selftest: kvm: Reorder vcpu_load_state steps for AMX

Hi Sean,

Quoted 8 lines · Sean Christopherson
Quoted 6 lines · Yang Zhong

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).

Quoted 6 lines

It would be very helpful to clarify that XFD is loaded via KVM_SET_MSRS. It took me longer than it should have to understand what was going on. The large amount of whitespace noise in this patch certainly didn't help. E.g. just a simple tweak:

For AMX support it is recommended to load XCR0 after XFD, i.e. after MSRs, so

Thanks, this is clearer.

Quoted 88 lines
Quoted 17 lines

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      | 29 ++++++++++---------
 1 file changed, 15 insertions(+), 14 deletions(-)
tools/testing/selftests/kvm/lib/x86_64/processor.c +0 -0
index 00324d73c687..9b5abf488211 100644

tools/testing/selftests/kvm/lib/x86_64/processor.c void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s · line 1197

Quoted 9 lines
tools/testing/selftests/kvm/lib/x86_64/processor.c +3 -3
@@ -1192,9 +1192,14 @@ 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);
+	r = ioctl(vcpu->fd, KVM_SET_SREGS, &state->sregs);
+	TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_SREGS, r: %i",
+		r);

If we're going to bother replacing spaces with tabs, might as well get rid of all the gratuituous newlines as well.

tools/testing/selftests/kvm/lib/x86_64/processor.c void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s · line 1202

Quoted 5 lines
tools/testing/selftests/kvm/lib/x86_64/processor.c +5 -0
+
+	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);

Most people not named "Paolo" prefer to align this with the opening "(" :-)

E.g.

tools/testing/selftests/kvm/lib/x86_64/processor.c +8 -15
index 97f8c2f2df36..971f41afa689 100644
@@ -1158,44 +1158,36 @@ void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s
        int r;
 
        r = ioctl(vcpu->fd, KVM_SET_SREGS, &state->sregs);
-       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_SREGS, r: %i",
-               r);
+       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);
+                   "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);
+               TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XCRS, r: %i", r);
        }
 
        r = ioctl(vcpu->fd, KVM_SET_XSAVE, &state->xsave);
-       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XSAVE, r: %i",
-               r);
+       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XSAVE, r: %i", r);
 
        r = ioctl(vcpu->fd, KVM_SET_VCPU_EVENTS, &state->events);
-       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_VCPU_EVENTS, r: %i",
-               r);
+       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_VCPU_EVENTS, r: %i", r);
 
        r = ioctl(vcpu->fd, KVM_SET_MP_STATE, &state->mp_state);
-        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_MP_STATE, r: %i",
-                r);
+        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_MP_STATE, r: %i", r);
 
        r = ioctl(vcpu->fd, KVM_SET_DEBUGREGS, &state->debugregs);
-        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_DEBUGREGS, r: %i",
-                r);
+        TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_DEBUGREGS, r: %i", r);
 
        r = ioctl(vcpu->fd, KVM_SET_REGS, &state->regs);
-       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_REGS, r: %i",

tools/testing/selftests/kvm/lib/x86_64/processor.c void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s · line 1192

Quoted 10 lines
tools/testing/selftests/kvm/lib/x86_64/processor.c +2 -3
-               r);
+       TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_REGS, r: %i", r);
 
        if (state->nested.size) {
                r = ioctl(vcpu->fd, KVM_SET_NESTED_STATE, &state->nested);
-               TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_NESTED_STATE, r: %i",
-                       r);
+               TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_NESTED_STATE, r: %i", r);
        }
 }

Thanks for pointing out those issues.
In fact, space issues are not only in this function, if we need handle those, we had better cleanup all those space issues.
Since this series has been merged into KVM-Next, we can submit one patch to handle those space issue in the new 5.17-rcx release. thanks!

Yang

author
#4 lore raw

PATCH v2 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 0546173ab628..28f8fa78a47b 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 9b5abf488211..126f8e743bc2 100644
@@ -1036,21 +1036,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
#5 lore raw

PATCH v2 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 | 451 ++++++++++++++++++
 2 files changed, 452 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/x86_64/amx_test.c
tools/testing/selftests/kvm/Makefile +1 -0
index c4e34717826a..ecb1fe022111 100644
@@ -75,6 +75,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 +451 -0

451 lines not on this page · raw message

maintainer
#6 lore raw

Re: [PATCH v2 3/3] selftest: kvm: Support amx selftest

Quoted 9 lines · Yang Zhong
tools/testing/selftests/kvm/x86_64/amx_test.c new file +9 -0
+	/* Trigger #NM exception */
+	__tileloadd(tiledata);
+	GUEST_SYNC(10);
+
+	GUEST_DONE();
+}
+
+void guest_nm_handler(struct ex_regs *regs)
+{

tools/testing/selftests/kvm/x86_64/amx_test.c line 315

Quoted 10 lines
tools/testing/selftests/kvm/x86_64/amx_test.c new file +10 -0
+	/* Check if #NM is triggered by XFEATURE_MASK_XTILEDATA */
+	GUEST_SYNC(7);
+	GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA);
+	GUEST_SYNC(8);
+	GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA);
+	/* Clear xfd_err */
+	wrmsr(MSR_IA32_XFD_ERR, 0);
+	regs->rip += 3;
+	GUEST_SYNC(9);
+}

I don't understand why "regs->rip += 3" is needed though.

My idea was that, after GUEST_SYNC(9) and IRET, the guest would execute __tileloadd again; this time without generating #NM, so that after GUEST_SYNC(10) the host sees the loaded data in TMM0.

Thanks,

Paolo

author
#7 lore raw

Re: [PATCH v2 3/3] selftest: kvm: Support amx selftest

Quoted 23 lines · Paolo Bonzini
Quoted 9 lines · Yang Zhong
tools/testing/selftests/kvm/x86_64/amx_test.c new file +9 -0
+	/* Trigger #NM exception */
+	__tileloadd(tiledata);
+	GUEST_SYNC(10);
+
+	GUEST_DONE();
+}
+
+void guest_nm_handler(struct ex_regs *regs)
+{

tools/testing/selftests/kvm/x86_64/amx_test.c line 315

Quoted 10 lines
tools/testing/selftests/kvm/x86_64/amx_test.c new file +10 -0
+	/* Check if #NM is triggered by XFEATURE_MASK_XTILEDATA */
+	GUEST_SYNC(7);
+	GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA);
+	GUEST_SYNC(8);
+	GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA);
+	/* Clear xfd_err */
+	wrmsr(MSR_IA32_XFD_ERR, 0);
+	regs->rip += 3;
+	GUEST_SYNC(9);
+}

I don't understand why "regs->rip += 3" is needed though.

Quoted 4 lines

My idea was that, after GUEST_SYNC(9) and IRET, the guest would execute __tileloadd again; this time without generating #NM, so that after GUEST_SYNC(10) the host sees the loaded data in TMM0.

Sorry, I didn't capture it before, and in that time, I wanted to skip this load intruction.

Let me enbale amx before GUEST_SYNC(9), and then load tiles again.

The new v3 will address this, thanks!

Yang

Quoted 3 lines

Thanks,

Paolo

maintainer
#8 lore raw
In reply to Yang Zhong
Quoted 8 lines · Yang Zhong

Hi Paolo,

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

Since Jing's v3 was justly sent out, I will rebase this patchest on it and send my separate v3.

Quoted 7 lines

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!

Hi, this looks good to me.

Paolo