History

kvm: x86: Add support for getting/setting expanded xstate buffer

With KVM_CAP_XSAVE, userspace uses a hardcoded 4KB buffer to get/set xstate data from/to KVM. This doesn't work when dynamic xfeatures (e.g. AMX) are exposed to the guest as they require a larger buffer size. Introduce a new capability (KVM_CAP_XSAVE2). Userspace VMM gets the required xstate buffer size via KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2). KVM_SET_XSAVE is extended to work with both legacy and new capabilities by doing properly-sized memdup_user() based on the guest fpu container. KVM_GET_XSAVE is kept for backward-compatible reason. Instead, KVM_GET_XSAVE2 is introduced under KVM_CAP_XSAVE2 as the preferred interface for getting xstate buffer (4KB or larger size) from KVM (Link: https://lkml.org/lkml/2021/12/15/510) Also, update the api doc with the new KVM_GET_XSAVE2 ioctl.

Guang Zeng committed 4 years ago

Commit be50b201 parent c60427d6 files · +106 −5Browse files

Showing the changes to include/uapi (1 of 6 files). Show all

Unified · Split

include/uapi/linux/kvm.h+4−0
@@ -1132,6 +1132,7 @@ struct kvm_ppc_resize_hpt { · 1131 unmodified lines
1132#define KVM_CAP_ARM_MTE 2051132#define KVM_CAP_ARM_MTE 205
1133#define KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM 2061133#define KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM 206
1134#define KVM_CAP_VM_GPA_BITS 2071134#define KVM_CAP_VM_GPA_BITS 207
1135#define KVM_CAP_XSAVE2 208
1135 1136
1136#ifdef KVM_CAP_IRQ_ROUTING1137#ifdef KVM_CAP_IRQ_ROUTING
1137 1138
@@ -1622,6 +1623,9 @@ struct kvm_enc_region { · 484 unmodified lines
1622#define KVM_S390_NORMAL_RESET _IO(KVMIO, 0xc3)1623#define KVM_S390_NORMAL_RESET _IO(KVMIO, 0xc3)
1623#define KVM_S390_CLEAR_RESET _IO(KVMIO, 0xc4)1624#define KVM_S390_CLEAR_RESET _IO(KVMIO, 0xc4)
1624 1625
1626/* Available with KVM_CAP_XSAVE2 */
1627#define KVM_GET_XSAVE2 _IOR(KVMIO, 0xcf, struct kvm_xsave)
1628
1625struct kvm_s390_pv_sec_parm {1629struct kvm_s390_pv_sec_parm {
1626 __u64 origin;1630 __u64 origin;
1627 __u64 length;1631 __u64 length;