KVM: improve definition of KVM_GET/SET_NESTED_STATE structs
Paolo Bonzini
maintainerPATCH 1/1 KVM: improve definition of KVM_GET/SET_NESTED_STATE structs
Liran sent me a patch with a large overhaul of the KVM_GET/SET_NESTED_STATE structs. However, I am wary of changing the userspace ABI in backwards-incompatible ways, so here is the bare minimum that is needed to achieve the same functionality.
Namely, the format of VMX nested state is detailed in a struct, and is accessible through struct kvm_vmx_nested_state. Unfortunately, to avoid changing the size of the structs it has to be accessed as "vmx.data[0]" rather than just "vmx.data".
Also, the values of the "format" field are defined as macros, which is easy and not controversial.
Signed-off-by Paolo Bonzini <[email protected]>
--- arch/x86/include/uapi/asm/kvm.h | 11 +++++++++++ arch/x86/kvm/vmx/nested.c | 3 +++ 2 files changed, 14 insertions(+)
arch/x86/include/uapi/asm/kvm.h +11 -0
@@ -383,6 +383,9 @@ struct kvm_sync_regs {#define KVM_X86_QUIRK_LAPIC_MMIO_HOLE (1 << 2)#define KVM_X86_QUIRK_OUT_7E_INC_RIP (1 << 3) +#define KVM_STATE_NESTED_FORMAT_VMX 0 +#define KVM_STATE_NESTED_FORMAT_SVM 1 +#define KVM_STATE_NESTED_GUEST_MODE 0x00000001#define KVM_STATE_NESTED_RUN_PENDING 0x00000002#define KVM_STATE_NESTED_EVMCS 0x00000004
@@ -390,6 +393,11 @@ struct kvm_sync_regs {#define KVM_STATE_NESTED_SMM_GUEST_MODE 0x00000001#define KVM_STATE_NESTED_SMM_VMXON 0x00000002 +struct kvm_vmx_nested_state_data { +__u8 vmcs12[0x1000 ]; +__u8 shadow_vmcs12[0x1000 ]; +}; +struct kvm_vmx_nested_state {__u64 vmxon_pa;__u64 vmcs_pa;
@@ -397,6 +405,9 @@ struct kvm_vmx_nested_state {struct {__u16 flags; } smm; + +__u8 pad[120 -18 ]; +struct kvm_vmx_nested_state_data data[0 ]; };/* for KVM_CAP_NESTED_STATE */
arch/x86/kvm/vmx/nested.c +3 -0
@@ -5269,6 +5269,9 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu, .vmx.vmcs_pa = -1ull, }; +BUILD_BUG_ON (sizeof (struct kvm_vmx_nested_state ) + != sizeof_field(struct kvm_nested_state, pad)); +if (!vcpu)return kvm_state.size +2 *VMCS12_SIZE ;
Signature · 1 line
2.21.0