• Liran Alon's avatar
    KVM: nVMX: Change KVM_STATE_NESTED_EVMCS to signal vmcs12 is copied from eVMCS · 323d73a8
    Liran Alon authored
    Currently KVM_STATE_NESTED_EVMCS is used to signal that eVMCS
    capability is enabled on vCPU.
    As indicated by vmx->nested.enlightened_vmcs_enabled.
    
    This is quite bizarre as userspace VMM should make sure to expose
    same vCPU with same CPUID values in both source and destination.
    In case vCPU is exposed with eVMCS support on CPUID, it is also
    expected to enable KVM_CAP_HYPERV_ENLIGHTENED_VMCS capability.
    Therefore, KVM_STATE_NESTED_EVMCS is redundant.
    
    KVM_STATE_NESTED_EVMCS is currently used on restore path
    (vmx_set_nested_state()) only to enable eVMCS capability in KVM
    and to signal need_vmcs12_sync such that on next VMEntry to guest
    nested_sync_from_vmcs12() will be called to sync vmcs12 content
    into eVMCS in guest memory.
    However, because restore nested-state is rare enough, we could
    have just modified vmx_set_nested_state() to always signal
    need_vmcs12_sync.
    
    From all the above, it seems that we could have just removed
    the usage of KVM_STATE_NESTED_EVMCS. However, in order to preserve
    backwards migration compatibility, we cannot do that.
    (vmx_get_nested_state() needs to signal flag when migrating from
    new kernel to old kernel).
    
    Returning KVM_STATE_NESTED_EVMCS when just vCPU have eVMCS enabled
    have a bad side-effect of userspace VMM having to send nested-state
    from source to destination as part of migration stream. Even if
    guest have never used eVMCS as it doesn't even run a nested
    hypervisor workload. This requires destination userspace VMM and
    KVM to support setting nested-state. Which make it more difficult
    to migrate from new host to older host.
    To avoid this, change KVM_STATE_NESTED_EVMCS to signal eVMCS is
    not only enabled but also active. i.e. Guest have made some
    eVMCS active via an enlightened VMEntry. i.e. vmcs12 is copied
    from eVMCS and therefore should be restored into eVMCS resident
    in memory (by copy_vmcs12_to_enlightened()).
    Reviewed-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
    Reviewed-by: default avatarMaran Wilson <maran.wilson@oracle.com>
    Reviewed-by: default avatarKrish Sadhukhan <krish.sadhukhan@oracle.com>
    Signed-off-by: default avatarLiran Alon <liran.alon@oracle.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    323d73a8
evmcs_test.c 4.01 KB