• Paolo Bonzini's avatar
    KVM: VMX: Move out vmx_x86_ops to 'main.c' to dispatch VMX and TDX · 5f18c642
    Paolo Bonzini authored
    KVM accesses Virtual Machine Control Structure (VMCS) with VMX instructions
    to operate on VM.  TDX doesn't allow VMM to operate VMCS directly.
    Instead, TDX has its own data structures, and TDX SEAMCALL APIs for VMM to
    indirectly operate those data structures.  This means we must have a TDX
    version of kvm_x86_ops.
    
    The existing global struct kvm_x86_ops already defines an interface which
    can be adapted to TDX, but kvm_x86_ops is a system-wide, not per-VM
    structure.  To allow VMX to coexist with TDs, the kvm_x86_ops callbacks
    will have wrappers "if (tdx) tdx_op() else vmx_op()" to pick VMX or
    TDX at run time.
    
    To split the runtime switch, the VMX implementation, and the TDX
    implementation, add main.c, and move out the vmx_x86_ops hooks in
    preparation for adding TDX.  Use 'vt' for the naming scheme as a nod to
    VT-x and as a concatenation of VmxTdx.
    
    The eventually converted code will look like this:
    
    vmx.c:
      vmx_op() { ... }
      VMX initialization
    tdx.c:
      tdx_op() { ... }
      TDX initialization
    x86_ops.h:
      vmx_op();
      tdx_op();
    main.c:
      static vt_op() { if (tdx) tdx_op() else vmx_op() }
      static struct kvm_x86_ops vt_x86_ops = {
            .op = vt_op,
      initialization functions call both VMX and TDX initialization
    
    Opportunistically, fix the name inconsistency from vmx_create_vcpu() and
    vmx_free_vcpu() to vmx_vcpu_create() and vmx_vcpu_free().
    Co-developed-by: default avatarXiaoyao Li <xiaoyao.li@intel.com>
    Signed-off-by: default avatarXiaoyao Li <xiaoyao.li@intel.com>
    Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    Signed-off-by: default avatarIsaku Yamahata <isaku.yamahata@intel.com>
    Reviewed-by: default avatarBinbin Wu <binbin.wu@linux.intel.com>
    Reviewed-by: default avatarXiaoyao Li <xiaoyao.li@intel.com>
    Reviewed-by: default avatarYuan Yao <yuan.yao@intel.com>
    Message-Id: <e603c317587f933a9d1bee8728c84e4935849c16.1705965634.git.isaku.yamahata@intel.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    5f18c642
x86_ops.h 6.04 KB