Skip to content

Commit 3611ca7

Browse files
sean-jcbonzini
authored andcommitted
selftests: kvm: Verify TILELOADD actually #NM faults when XFD[18]=1
Rework the AMX test's #NM handling to use kvm_asm_safe() to verify an #NM actually occurs. As is, a completely missing #NM could go unnoticed. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 0383a8e commit 3611ca7

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

tools/testing/selftests/kvm/x86/amx_test.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ static inline void __tileloadd(void *tile)
6969
: : "a"(tile), "d"(0));
7070
}
7171

72+
static inline int tileloadd_safe(void *tile)
73+
{
74+
return kvm_asm_safe(".byte 0xc4,0xe2,0x7b,0x4b,0x04,0x10",
75+
"a"(tile), "d"(0));
76+
}
77+
7278
static inline void __tilerelease(void)
7379
{
7480
asm volatile(".byte 0xc4, 0xe2, 0x78, 0x49, 0xc0" ::);
@@ -142,6 +148,8 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg,
142148
struct tile_data *tiledata,
143149
struct xstate *xstate)
144150
{
151+
int vector;
152+
145153
GUEST_ASSERT(this_cpu_has(X86_FEATURE_XSAVE) &&
146154
this_cpu_has(X86_FEATURE_OSXSAVE));
147155
check_xtile_info();
@@ -195,17 +203,13 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg,
195203
GUEST_ASSERT(rdmsr(MSR_IA32_XFD) == XFEATURE_MASK_XTILE_DATA);
196204
set_tilecfg(amx_cfg);
197205
__ldtilecfg(amx_cfg);
198-
/* Trigger #NM exception */
199-
__tileloadd(tiledata);
200-
GUEST_SYNC(TEST_COMPARE_TILEDATA | TEST_SAVE_RESTORE);
201206

202-
GUEST_DONE();
203-
}
207+
/* Trigger #NM exception */
208+
vector = tileloadd_safe(tiledata);
209+
__GUEST_ASSERT(vector == NM_VECTOR,
210+
"Wanted #NM on tileloadd with XFD[18]=1, got %s",
211+
ex_str(vector));
204212

205-
void guest_nm_handler(struct ex_regs *regs)
206-
{
207-
/* Check if #NM is triggered by XFEATURE_MASK_XTILE_DATA */
208-
GUEST_SYNC(TEST_SAVE_RESTORE);
209213
GUEST_ASSERT(!(get_cr0() & X86_CR0_TS));
210214
GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILE_DATA);
211215
GUEST_ASSERT(rdmsr(MSR_IA32_XFD) == XFEATURE_MASK_XTILE_DATA);
@@ -217,6 +221,11 @@ void guest_nm_handler(struct ex_regs *regs)
217221
/* xfd=0, enable amx */
218222
wrmsr(MSR_IA32_XFD, 0);
219223
GUEST_SYNC(TEST_SAVE_RESTORE);
224+
225+
__tileloadd(tiledata);
226+
GUEST_SYNC(TEST_COMPARE_TILEDATA | TEST_SAVE_RESTORE);
227+
228+
GUEST_DONE();
220229
}
221230

222231
int main(int argc, char *argv[])
@@ -253,9 +262,6 @@ int main(int argc, char *argv[])
253262

254263
vcpu_regs_get(vcpu, &regs1);
255264

256-
/* Register #NM handler */
257-
vm_install_exception_handler(vm, NM_VECTOR, guest_nm_handler);
258-
259265
/* amx cfg for guest_code */
260266
amx_cfg = vm_vaddr_alloc_page(vm);
261267
memset(addr_gva2hva(vm, amx_cfg), 0x0, getpagesize());

0 commit comments

Comments
 (0)