[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251224001249.1041934-5-pbonzini@redhat.com>
Date: Wed, 24 Dec 2025 01:12:48 +0100
From: Paolo Bonzini <pbonzini@...hat.com>
To: linux-kernel@...r.kernel.org,
kvm@...r.kernel.org
Cc: seanjc@...gle.com,
x86@...nel.org
Subject: [PATCH 4/5] selftests, kvm: try getting XFD and XSAVE state out of sync
The host is allowed to set FPU state that includes a disabled
xstate component. Check that this does not cause bad effects.
Signed-off-by: Paolo Bonzini <pbonzini@...hat.com>
---
tools/testing/selftests/kvm/x86/amx_test.c | 25 +++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86/amx_test.c b/tools/testing/selftests/kvm/x86/amx_test.c
index dd980cdac5df..5222ec6f71d3 100644
--- a/tools/testing/selftests/kvm/x86/amx_test.c
+++ b/tools/testing/selftests/kvm/x86/amx_test.c
@@ -142,7 +142,16 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg,
GUEST_SYNC(3);
/* Check save/restore when trap to userspace */
__tileloadd(tiledata);
+
GUEST_SYNC(4);
+ /* xfd=0x40000, disable amx tiledata */
+ wrmsr(MSR_IA32_XFD, XFEATURE_MASK_XTILE_DATA);
+
+ GUEST_SYNC(5);
+ /* host tries setting tiledata while guest XFD is set */
+ GUEST_SYNC(6);
+
+ wrmsr(MSR_IA32_XFD, 0);
__tilerelease();
GUEST_SYNC(10);
/*
@@ -202,6 +211,7 @@ int main(int argc, char *argv[])
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
struct kvm_x86_state *state;
+ struct kvm_x86_state *tile_state = NULL;
int xsave_restore_size;
vm_vaddr_t amx_cfg, tiledata, xstate;
struct ucall uc;
@@ -259,6 +269,7 @@ int main(int argc, char *argv[])
case 1:
case 2:
case 3:
+ case 6:
case 10:
case 11:
case 12:
@@ -267,8 +278,7 @@ int main(int argc, char *argv[])
break;
case 4:
case 15:
- fprintf(stderr,
- "GUEST_SYNC(%ld), check save/restore status\n", uc.args[1]);
+ fprintf(stderr, "GUEST_SYNC(%ld), check save/restore status\n", uc.args[1]);
/* Compacted mode, get amx offset by xsave area
* size subtract 8K amx size.
@@ -280,8 +290,17 @@ int main(int argc, char *argv[])
/* Only check TMM0 register, 1 tile */
ret = memcmp(amx_start, tiles_data, TILE_SIZE);
TEST_ASSERT(ret == 0, "memcmp failed, ret=%d", ret);
- kvm_x86_state_cleanup(state);
+ if (uc.args[1] == 4)
+ tile_state = state;
+ else
+ kvm_x86_state_cleanup(state);
break;
+ case 5:
+ fprintf(stderr, "GUEST_SYNC(%ld), before KVM_SET_XSAVE\n", uc.args[1]);
+ vcpu_xsave_set(vcpu, tile_state->xsave);
+ fprintf(stderr, "GUEST_SYNC(%ld), after KVM_SET_XSAVE\n", uc.args[1]);
+ /* do not restore full state */
+ continue;
case 14:
fprintf(stderr,
"GUEST_SYNC(%ld), #NM exception and enable amx\n", uc.args[1]);
--
2.52.0
Powered by blists - more mailing lists