[PATCH v2 0/4] x86, fpu/kvm: fix crash with AMX
From: Paolo Bonzini
Date: Thu Jan 01 2026 - 04:12:33 EST
Fix a possible host panic, due to an unexpected #NM, when a KVM guest
is using AMX features.
The guest's XFD value, which is stored in fpstate->xfd, is used for both
guest execution and host XSAVE operations. However, the guest-configured
XFD setting can disable features that were enabled when the guest executed
XSAVE, and this causes a #NM when executing XRSTOR on the guest FPU state.
This can happen in two cases: due to a KVM_SET_XSAVE that includes a
disabled component, or if an interrupt causes XSAVE to be executed
before the call to fpu_update_guest_xfd().
The first patch fixes both cases, the rest is improvements to selftests
in order to cover this test and also verify that #NM faults are injected
corectly.
v1 had extra patches to export higher-level functions for KVM in place
of switch_fpu_return() and fpregs_assert_state_consistent(). Those
were part of refactoring how KVM loaded guest state when KVM_RUN is
issued, but are not needed anymore with this v2 fix and I will submit
them separately.
Tested on a Sapphire Rapids machine, reviews and acks are welcome so
that I can submit it to Linus via the KVM tree.
Paolo
Paolo Bonzini (2):
selftests: kvm: replace numbered sync points with actions
selftests: kvm: try getting XFD and XSAVE state out of sync
Sean Christopherson (2):
x86/fpu: Clear XSTATE_BV[i] in save state whenever XFD[i]=1
selftests: kvm: Verify TILELOADD actually #NM faults when XFD[18]=1
arch/x86/kernel/fpu/core.c | 32 ++++-
arch/x86/kvm/x86.c | 9 ++
tools/testing/selftests/kvm/x86/amx_test.c | 144 ++++++++++++---------
3 files changed, 123 insertions(+), 62 deletions(-)
--
2.52.0