x86/fpu: Bail early from guest XFD update if XFD isn't supported
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20261120193052.GCawCf7LBmUxT2plv6@fat_crate.local
Paolo Bonzini
maintainerQuoted 8 lines · Borislav Petkov
Quoted 4 lines · Sean Christopherson
Ignore KVM-requested guest XFD updates if the kernel doesn't support XFD,
to allow an upcoming fix to modify xsave.header.xfeatures even when the incoming XFD value is '0'.
Drop that. I agree with Dave and the sentiment to "not even go there" and not support non-sensical configurations.
Agreed, the real justification for bailing out early should be "allow XFD == 0 as that is anyway the initial value of fpstate->xfd, but detect XFD != 0 and WARN as that's a clear bug in KVM".
Then subsequent patches are free to do whatever they want.
Quoted 2 lines
I appreciate your musings, Sean, but to me that commit message ended after the first sentence. All is perfectly clear.
:)
Here is my take on both the patch and the commit message:
----------------------- 8< -----------------
From c720a41b6df014f95ef7246777db6f066d6396e3 Mon Sep 17 00:00:00 2001
From: Sean Christopherson <[email protected]>
Date: Wed, 18 Nov 2026 16:15:04 -0800
Subject: [PATCH 1/1] x86/fpu: Bail early from guest XFD update if XFD isn't supported
KVM generally allows userspace to set MSRs to their inactive values even if they aren't supported by the guest, as that simplifies userspace code noticeably, and XFD is no exception. Arguably, it should then not try to update XFD in struct fpu_guest* if the kernel doesn't support XFD or even XSAVE. However, fixing that flaw could potentially impact KVM's uABI; thus, simply ignore KVM-requested guest XFD updates if the kernel doesn't support XFD.
The current code is subtly fine and does not corrupt guest_fpu->fpstate by interpreting it as an xstate structure; xsave.header.xfeatures is modified if and only if xfd != 0, which KVM does reject. Still, returning early is clearer, provides fewer opportunities for bugs, and provides a place for WARNing in the indefensible case of xfd != 0.
--- arch/x86/kernel/fpu/core.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kernel/fpu/core.c +5 -0
@@ -334,6 +334,11 @@ void fpu_update_guest_xfd(struct fpu_guest *guest_fpu, u64 xfd) {struct fpstate *fpstate = guest_fpu->fpstate; +if (!cpu_feature_enabled (X86_FEATURE_XFD )) { +WARN_ON_ONCE (xfd); +return ; + } +fpregs_lock ();/*
Signature · 1 line
2.56.1