x86/fpu: Allow caller to constrain xfeatures when copying to uabi buffer
authorSean Christopherson <seanjc@google.com>
Thu, 28 Sep 2023 00:19:52 +0000 (17:19 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 12 Oct 2023 15:08:58 +0000 (11:08 -0400)
commit18164f66e6c59fda15c198b371fa008431efdb22
tree57589d50477bd6a69f6dffbb2dde1d04ee2fd1c5
parent4bcd9bc629a5d273442fee75a0cc56ea84be08ed
x86/fpu: Allow caller to constrain xfeatures when copying to uabi buffer

Plumb an xfeatures mask into __copy_xstate_to_uabi_buf() so that KVM can
constrain which xfeatures are saved into the userspace buffer without
having to modify the user_xfeatures field in KVM's guest_fpu state.

KVM's ABI for KVM_GET_XSAVE{2} is that features that are not exposed to
guest must not show up in the effective xstate_bv field of the buffer.
Saving only the guest-supported xfeatures allows userspace to load the
saved state on a different host with a fewer xfeatures, so long as the
target host supports the xfeatures that are exposed to the guest.

KVM currently sets user_xfeatures directly to restrict KVM_GET_XSAVE{2} to
the set of guest-supported xfeatures, but doing so broke KVM's historical
ABI for KVM_SET_XSAVE, which allows userspace to load any xfeatures that
are supported by the *host*.

Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20230928001956.924301-2-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/fpu/api.h
arch/x86/kernel/fpu/core.c
arch/x86/kernel/fpu/xstate.c
arch/x86/kernel/fpu/xstate.h
arch/x86/kvm/x86.c