Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4728784pxv; Tue, 6 Jul 2021 07:50:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVTY44gjQA1V90aRC5GhumAshOnWOh1+9p56dBGwiCiuWgkEUWRfQqJCo/i0BZsimyiNWK X-Received: by 2002:a17:907:608d:: with SMTP id ht13mr19010545ejc.399.1625583002388; Tue, 06 Jul 2021 07:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625583002; cv=none; d=google.com; s=arc-20160816; b=jJIA7x/sMmIgIg0tLIwxJR3eHGgiyas7+8C8AqqCqIg49nfwRUOxJRGXk2NmOScweA xo9Xn5916QSBzQNLNXEg5ZRoam+uZVXQ31SOFYno+u3KKdXIJElwkneLTu6VeiiDlTnW 57O1+UjRbPDwQSYG03aIJHlga5oqAm/CeKFWv9EGfXvVPDSPBipKRFnrYxFPoKo1Ma2g YhSTcbmKadFNWiboHOMuCBlvzODOduyhYDzzuT1QHbRIJHsEhVjvZ7mTE3BF43i/HZm6 ZYrqUEWIXwLmQhbDx7v/di37VpP8HPgpeuQIgx4T5QdhmElnxxog4FSNkSIiSZmeLVEH cMMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=+/fNLNqPbpNRl0+W5voAKm17mYQz3ARBBCnEfhzOSa4=; b=sI9xW8JfrEg7dWsKdZMuVUcwYuO09E31UtxZNlmVFdlaGRYwLobN75USur1UNfTpyt ZCoTUILGFh9vUlqEGkzm+98SnbUM+MRmXavXiM93thu5u2oMyyVX3h+78T6h089MmZug SmchFaFcQ5b24wE62FkgRVthRqMRr5JszSXM/fUOA7gXXvvHOy7QTSvkqqgqeNxgYZ2M OCgVgHVcgMpNpe8FGUdPaf91DhtqD0VqR5aGZWpebtkM3MGdi2rRMgDfBg+ZPDstq4ZC n+0mDZGjIazAPykV1XOs3fYJR79hhWbNrQbViSb1krTKJoTlV6DNjt6Ku1Y208bfS8V7 /ivw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=i3iQOdnG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p23si14783801edw.135.2021.07.06.07.49.38; Tue, 06 Jul 2021 07:50:02 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=i3iQOdnG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231779AbhGFOtX (ORCPT + 99 others); Tue, 6 Jul 2021 10:49:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41286 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231426AbhGFOtD (ORCPT ); Tue, 6 Jul 2021 10:49:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625582784; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+/fNLNqPbpNRl0+W5voAKm17mYQz3ARBBCnEfhzOSa4=; b=i3iQOdnGwRoQrDeiH9IhDsBLbtDbjh4LltVOf4iS1PWGb9pWMp2PBazUH+hhVP3/BlLerZ fNN1P6Lw1xtlqozHDM6sdsTxiXKcX+/mFIlDoLalZxS7m/xXjTZSSas86AIsGqvsdllpVn zv9ibXGilrQlFVSI7fT3YAnnm6TyXpY= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-229-Y5nign7YOayGo-hFuZB4Ng-1; Tue, 06 Jul 2021 10:46:23 -0400 X-MC-Unique: Y5nign7YOayGo-hFuZB4Ng-1 Received: by mail-wm1-f70.google.com with SMTP id m5-20020a05600c3b05b029020c34fd31cfso1202784wms.4 for ; Tue, 06 Jul 2021 07:46:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+/fNLNqPbpNRl0+W5voAKm17mYQz3ARBBCnEfhzOSa4=; b=LH+4y/dd1ufgWqTXvbvRYy2GqJyXzVyKhaiu1TdcUVqdJvgI+yNY4DKl+PHGVjEDlu L/pP07gZ2YFP2qlmHYMpIhssmXAF4pm3OM4vbLrfm765PdmwGV83TwpIVF6MwLimbu7P oK1FnWf+F4+vmi7hlokBiuwn8AlQJlrx8q9qDIUy62+nRhjFO9l2oMPCsZyXHVaRmZ19 zz9c/Ss0F0VpCN3Ju7UuK8chcQkh/p01/dLYHzqM/0yyuZqTloKiDA4VUjs0PUjuv19o EbYYi22egk4liaQnevYho9yscDFqYieTxpJ8Px8QsUL0DLtmaWVzqdDmxMRbtMNzLwmY OejA== X-Gm-Message-State: AOAM5325Cz3jZAZb1qzNwFmAFLNqs2jSeTdphTMSn/ThZfe8kjlYSRz4 Jt8J+zobaTk9VB8l/yX9B1LRGfi9kn8NBdUBXhRlfJ/dOw6Re/KN6mCiuI4EjoBEBfv8rQ2fswA akDNqQzL7D1883KFE+PmD05kW X-Received: by 2002:a5d:58f3:: with SMTP id f19mr22339122wrd.15.1625582782043; Tue, 06 Jul 2021 07:46:22 -0700 (PDT) X-Received: by 2002:a5d:58f3:: with SMTP id f19mr22339098wrd.15.1625582781854; Tue, 06 Jul 2021 07:46:21 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id n20sm15439384wmk.12.2021.07.06.07.46.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Jul 2021 07:46:19 -0700 (PDT) Subject: Re: [RFC PATCH v2 60/69] KVM: VMX: Add macro framework to read/write VMCS for VMs and TDs To: isaku.yamahata@intel.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , 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@gmail.com, Sean Christopherson References: <5735bf9268130a70b49bc32ff4b68ffc53ee788c.1625186503.git.isaku.yamahata@intel.com> From: Paolo Bonzini Message-ID: <71ee8575-bd72-f51e-38c5-4e8411b8aedd@redhat.com> Date: Tue, 6 Jul 2021 16:46:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <5735bf9268130a70b49bc32ff4b68ffc53ee788c.1625186503.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/07/21 00:05, isaku.yamahata@intel.com wrote: > 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 Is this #ifdef needed at all if tdx.h properly stubs is_td_vcpu (to return false) and possibly declares a dummy version of td_vmcs_read/td_vmcs_write? Paolo > +#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); >