Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1887014pxv; Fri, 2 Jul 2021 15:11:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7TfBNCUrgevfMDgRvGwMRQKlj2l1D7Tzq34kQI5lq4xhmWnYU2UzCc/eo8Z5Nap/jX0aj X-Received: by 2002:a17:907:9872:: with SMTP id ko18mr1849278ejc.505.1625263881552; Fri, 02 Jul 2021 15:11:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263881; cv=none; d=google.com; s=arc-20160816; b=URy2GCHTJT+bSLsGkezvwbDvCnG6nV8i8fjKlToWg5vUN6VL2UaOk55CDfbtbUV7ox eH0KOl1PZ0Wggl5i8GOXjyZZVb1jeXmHebSpu0N0rjKVrd6QYnaV+nSt45Kaq7zWMdXi zjjlsBogvU1amfHvjdkM/egtS/zUN2Uxbhd0rjOPh09ErNsbbJ2TXdObaRv0f0Jub1w0 gw2vKPlsAwHvyej9tbYqsIWDutKgVAhj37Q4J6LQL1Ko0v5RWENuv37W9rVAyMNYkErG IdSy+DoX+m7gznqRY+q1AMVeuNJ7Rc4TmLuaYZmfmBLuAhpdJ8eTxTTbIep/ogsWyVkL uZsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=J286JKTHRNWZ2wIzvj+Jv40c3fqgJBvU1BCazT2OgAY=; b=NnKTxH6p3mqX52UE4mO+vvG0bF2L6Es4VI1FF5tIIp6iSjdJr+fDr8DKw3SymLSTHg jzQfLyR2KXiYXZJYSekltqDU1XncdkqTPVl0shNamD4GmORNr186oS8D6hZymOctiSAL kw2zu8OJ9F3YnPfa8xguXYa9KTzTu2wPDG4EAOUhXSlZwAZ/XsbmQesZSqGsSEh7n2pC ydcT4CAKem9LTlfBrAcglKDZCxP3Bln2L2V5tuXmgzk94qcuRAZLHv6kvQv8pYnHgFDB 3K6ySBb1H16EvU4s4BEkBD7bDUMIoAn24M7yky8hOzSCK7ry2O5rdULK7eYAnrFx5bYj koBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y1si4363726edc.292.2021.07.02.15.10.58; Fri, 02 Jul 2021 15:11:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233482AbhGBWJx (ORCPT + 99 others); Fri, 2 Jul 2021 18:09:53 -0400 Received: from mga17.intel.com ([192.55.52.151]:15270 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233819AbhGBWIh (ORCPT ); Fri, 2 Jul 2021 18:08:37 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="189168403" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="189168403" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:31 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814880" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:31 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson Subject: [RFC PATCH v2 60/69] KVM: VMX: Add macro framework to read/write VMCS for VMs and TDs Date: Fri, 2 Jul 2021 15:05:06 -0700 Message-Id: <5735bf9268130a70b49bc32ff4b68ffc53ee788c.1625186503.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Add a macro framework to hide VMX vs. TDX details of VMREAD and VMWRITE so the VMX and TDX can shared common flows, e.g. accessing DTs. Note, the TDX paths are dead code at this time. There is no great way to deal with the chicken-and-egg scenario of having things in place for TDX without first having TDX. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/common.h | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h index 9e5865b05d47..aa6a569b87d1 100644 --- a/arch/x86/kvm/vmx/common.h +++ b/arch/x86/kvm/vmx/common.h @@ -11,6 +11,47 @@ #include "vmcs.h" #include "vmx.h" #include "x86.h" +#include "tdx.h" + +#ifdef CONFIG_KVM_INTEL_TDX +#define VT_BUILD_VMCS_HELPERS(type, bits, tdbits) \ +static __always_inline type vmread##bits(struct kvm_vcpu *vcpu, \ + unsigned long field) \ +{ \ + if (unlikely(is_td_vcpu(vcpu))) { \ + if (KVM_BUG_ON(!is_debug_td(vcpu), vcpu->kvm)) \ + return 0; \ + return td_vmcs_read##tdbits(to_tdx(vcpu), field); \ + } \ + return vmcs_read##bits(field); \ +} \ +static __always_inline void vmwrite##bits(struct kvm_vcpu *vcpu, \ + unsigned long field, type value) \ +{ \ + if (unlikely(is_td_vcpu(vcpu))) { \ + if (KVM_BUG_ON(!is_debug_td(vcpu), vcpu->kvm)) \ + return; \ + return td_vmcs_write##tdbits(to_tdx(vcpu), field, value); \ + } \ + vmcs_write##bits(field, value); \ +} +#else +#define VT_BUILD_VMCS_HELPERS(type, bits, tdbits) \ +static __always_inline type vmread##bits(struct kvm_vcpu *vcpu, \ + unsigned long field) \ +{ \ + return vmcs_read##bits(field); \ +} \ +static __always_inline void vmwrite##bits(struct kvm_vcpu *vcpu, \ + unsigned long field, type value) \ +{ \ + vmcs_write##bits(field, value); \ +} +#endif /* CONFIG_KVM_INTEL_TDX */ +VT_BUILD_VMCS_HELPERS(u16, 16, 16); +VT_BUILD_VMCS_HELPERS(u32, 32, 32); +VT_BUILD_VMCS_HELPERS(u64, 64, 64); +VT_BUILD_VMCS_HELPERS(unsigned long, l, 64); extern unsigned long vmx_host_idt_base; void vmx_do_interrupt_nmi_irqoff(unsigned long entry); -- 2.25.1