[PATCH v1 0/2] x86/kvm/fpu: Fix guest migration bugs that can crash guest

From: Leonardo Bras
Date: Sat Feb 05 2022 - 03:17:36 EST


This patchset comes from a bug I found during qemu guest migration from a
host with newer CPU to a host with an older version of this CPU, and thus
having less FPU features.

When the guests were created, the one with less features is used as
config, so migration is possible.

Patch 1 fix a bug that always happens during this migration, and is
related to the fact that xsave saves all feature flags, but xrstor does
not touch the PKRU flag.

Patch 2 comes from a concearn I have of the same bug as above hapenning
through different means, such as a future bug in qemu, and rendering
a lot of VMs unmigratable. Also, I think it makes sense to limit the
fatures to what the vcpu supports, as if it were baremetal it would crash.

Please let me know of anything to improve!

Best regards,
Leo


Leonardo Bras (2):
x86/kvm/fpu: Mask guest fpstate->xfeatures with guest_supported_xcr0
x86/kvm/fpu: Limit setting guest fpu features based on
guest_supported_xcr0

arch/x86/kvm/cpuid.c | 3 +++
arch/x86/kvm/x86.c | 3 ++-
2 files changed, 5 insertions(+), 1 deletion(-)

--
2.35.1