Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4069400imw; Tue, 12 Jul 2022 00:41:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t7caMeSXzWOvI/bFYxEseXh3EUxapctGzrJChBPHj670WxWfr7SemHd7QQZaTTxBbe7c8z X-Received: by 2002:a65:6a0e:0:b0:405:2310:22d0 with SMTP id m14-20020a656a0e000000b00405231022d0mr19744419pgu.290.1657611665369; Tue, 12 Jul 2022 00:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657611665; cv=none; d=google.com; s=arc-20160816; b=KPUXA2P0Fx2bkktOmOF3MPPvmvceWCXw9RuGG7iH8EybkqCky6iwldNC1RBqF97L6z TOd2YKJ4UXSYZRnjV3/exS4h3B5XpEBQ5okUCYL/PBIZU22wldtqH91D0bZW888RNrbN cA3b/0oJOlz7roq+qucZRgZtHhhsVwQ6gd9Yeu4CzXTbgu9uo/eWDQ14KNvlXPT54m7F nM9vp+6BvNOgeCaWoewgWZvPvTwroA+5knS0U5MaUQK9Dd6zlGjll1JRI1SvlRpLVrEQ iWAVLKARvOVWKBzfIBzDQCpUqibdBaMINIJnVTLzi3CYd8Lym/SNdFeF1zCYPrAobCnR 2ZFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=36QpzK/RLMwVL3iIGsDgJ6InsJXS/K/2EfpSQVCK3ng=; b=Zf9yjvik+LbLW8V73tTc+X4yp1hLfVhia7OEoCpiRuWzifT+aDdWB9wRgR6UaPhX5j K7KFu9H557I3jb34ykOKZFdddxTWzGVwdNMeJPcJApO7jfXIwAD5Et+6YBRAO3erjOOo GMMr0AbDWfPOwHPWOwUIV/Qx67VodpCLJF3nCU7ZKEhfP5bogBWJvyl78MSdbWUB5OEn XyzDW1hBn/XwZabnITQ0H4wiXIw4DEpR4fsLE/783fKKSFYc2w3tuC1qX1I4M8zfMa/j xo82yNe+dxmK202a2Kuia5AycSE2H/gKNIbLUbrjuLZc3pWRlZmz6BKVmM7ym2o2Juhj WgbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oRPYwbu4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r131-20020a632b89000000b0041183dd02cesi12372815pgr.621.2022.07.12.00.40.52; Tue, 12 Jul 2022 00:41:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oRPYwbu4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232281AbiGLHLj (ORCPT + 99 others); Tue, 12 Jul 2022 03:11:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiGLHLh (ORCPT ); Tue, 12 Jul 2022 03:11:37 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A67DD275DE; Tue, 12 Jul 2022 00:11:36 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id x184so6753784pfx.2; Tue, 12 Jul 2022 00:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=36QpzK/RLMwVL3iIGsDgJ6InsJXS/K/2EfpSQVCK3ng=; b=oRPYwbu4peS6xoWNYL0Hx5E08NIYXjf5EXhVGKhfsDadMmx7OiDqMhIGbJEqSGi6K6 DKXB/T15o/lVgQPIgoBQnvxoDxzdW29Cd231MgO2kHAc7u1INJVv+nQw+yYAhn9lYSP5 Z+5unLnFAf2Cpr2ju7Nss2hki8p7Txl46fOWcwaOhuF8ChQdMdBD0Os2PCdplKtIpQLD eHzldbZpb5sqeJYUPteRE/Tie3aqISqk69Ry7+zY5+FSc7Q55Lzvb6+yhBNvIffAUfyw CgsVITkmAvroFcE7vRx3gGrx//X8+MJ3jlqCIvfs5VX3XjiepaFHjjx4StQDbtr9rI+P VJAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=36QpzK/RLMwVL3iIGsDgJ6InsJXS/K/2EfpSQVCK3ng=; b=SZLQrk0+5dfap53o/U5odvOCMECXrY18L69vXklmzBp6J5ykgTJI7QMTZqA3AOE9yE dLFkfmbE0+OSJYZvyoso9A1xwYqPOLqtOUDedrkK6ssny21F17yN75KPzdNkpjeNrCvf PLStO9KKwp3hu0WU3YTjorMd7l8WgKFH5TBMGYWELviUi0gTa977hfhvpwdeuPBCkLHf LuuUq0Ks3kW2KYShyqQcFUVUaRMf1qdUFSQ5X1tzT7WlP8NNQMNLH0WBG91Cy3I5ub4z SPwMByMGedYP3yIc3Cw6L2kWaZx/Jc6Qn8Fw643dvScd05x7tjZdABCbrdN0lbcbfYI9 fdug== X-Gm-Message-State: AJIora8piYJIQ6sZd9HOJgR9hLbaP80TxP1YCV1BZl7rmlmneWUK0jZn CcTyp2IWN83f+3ob3eBhTac= X-Received: by 2002:a63:3cd:0:b0:415:f76d:fb4 with SMTP id 196-20020a6303cd000000b00415f76d0fb4mr8821269pgd.587.1657609895912; Tue, 12 Jul 2022 00:11:35 -0700 (PDT) Received: from localhost (fmdmzpr02-ext.fm.intel.com. [192.55.54.37]) by smtp.gmail.com with ESMTPSA id j6-20020a634a46000000b0040cfb5151fcsm5336425pgl.74.2022.07.12.00.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 00:11:35 -0700 (PDT) Date: Tue, 12 Jul 2022 00:11:34 -0700 From: Isaku Yamahata To: Xiaoyao Li Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini Subject: Re: [PATCH v7 025/102] KVM: TDX: initialize VM with TDX specific parameters Message-ID: <20220712071134.GH1379820@ls.amr.corp.intel.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 28, 2022 at 04:30:53PM +0800, Xiaoyao Li wrote: > On 6/28/2022 5:53 AM, isaku.yamahata@intel.com wrote: > > From: Xiaoyao Li > > > > TDX requires additional parameters for TDX VM for confidential execution to > > protect its confidentiality of its memory contents and its CPU state from > > any other software, including VMM. When creating guest TD VM before > > creating vcpu, the number of vcpu, TSC frequency (that is same among > > vcpus. and it can't be changed.) CPUIDs which is emulated by the TDX > > module. It means guest can trust those CPUIDs. and sha384 values for > > measurement. > > > > Add new subcommand, KVM_TDX_INIT_VM, to pass parameters for TDX guest. It > > assigns encryption key to the TDX guest for memory encryption. TDX > > encrypts memory per-guest bases. It assigns device model passes per-VM > > parameters for the TDX guest. The maximum number of vcpus, tsc frequency > > (TDX guest has fised VM-wide TSC frequency. not per-vcpu. The TDX guest > > can not change it.), attributes (production or debug), available extended > > features (which is reflected into guest XCR0, IA32_XSS MSR), cpuids, sha384 > > measurements, and etc. > > > > This subcommand is called before creating vcpu and KVM_SET_CPUID2, i.e. > > cpuids configurations aren't available yet. So CPUIDs configuration values > > needs to be passed in struct kvm_init_vm. It's device model responsibility > > to make this cpuid config for KVM_TDX_INIT_VM and KVM_SET_CPUID2. > > > > Signed-off-by: Xiaoyao Li > > Signed-off-by: Isaku Yamahata > > --- > > arch/x86/include/asm/kvm_host.h | 2 + > > arch/x86/include/asm/tdx.h | 3 + > > arch/x86/include/uapi/asm/kvm.h | 33 +++++ > > arch/x86/kvm/vmx/tdx.c | 206 ++++++++++++++++++++++++++ > > arch/x86/kvm/vmx/tdx.h | 23 +++ > > tools/arch/x86/include/uapi/asm/kvm.h | 33 +++++ > > 6 files changed, 300 insertions(+) > > > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > > index 342decc69649..81638987cdb9 100644 > > --- a/arch/x86/include/asm/kvm_host.h > > +++ b/arch/x86/include/asm/kvm_host.h > > @@ -1338,6 +1338,8 @@ struct kvm_arch { > > * the global KVM_MAX_VCPU_IDS may lead to significant memory waste. > > */ > > u32 max_vcpu_ids; > > + > > + gfn_t gfn_shared_mask; > > I think it's better to put in a seperate patch or the patch that consumes > it. > > > }; > ... > > > diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c > > index 2a9dfd54189f..1273b60a1a00 100644 > > --- a/arch/x86/kvm/vmx/tdx.c > > +++ b/arch/x86/kvm/vmx/tdx.c > > @@ -438,6 +438,209 @@ int tdx_dev_ioctl(void __user *argp) > > return 0; > > } > > +/* > > + * cpuid entry lookup in TDX cpuid config way. > > + * The difference is how to specify index(subleaves). > > + * Specify index to TDX_CPUID_NO_SUBLEAF for CPUID leaf with no-subleaves. > > + */ > > +static const struct kvm_cpuid_entry2 *tdx_find_cpuid_entry( > > + const struct kvm_cpuid2 *cpuid, u32 function, u32 index) > > +{ > > + int i; > > + > > + > > superfluous line > > > + /* In TDX CPU CONFIG, TDX_CPUID_NO_SUBLEAF means index = 0. */ > > + if (index == TDX_CPUID_NO_SUBLEAF) > > + index = 0; > > + > > + for (i = 0; i < cpuid->nent; i++) { > > + const struct kvm_cpuid_entry2 *e = &cpuid->entries[i]; > > + > > + if (e->function == function && > > + (e->index == index || > > + !(e->flags & KVM_CPUID_FLAG_SIGNIFCANT_INDEX))) > > + return e; > > + } > > + return NULL; > > +} > > no need for kvm_tdx->tsc_khz field. We have kvm->arch.default_tsc_khz. > It seems kvm_tdx->tsc_khz is not used in the following patches. > > ... > > > + > > + kvm_tdx->tsc_offset = td_tdcs_exec_read64(kvm_tdx, TD_TDCS_EXEC_TSC_OFFSET); > > + kvm_tdx->attributes = td_params->attributes; > > + kvm_tdx->xfam = td_params->xfam; > > + kvm_tdx->tsc_khz = TDX_TSC_25MHZ_TO_KHZ(td_params->tsc_frequency); > > + kvm->max_vcpus = td_params->max_vcpus; > > + > > + if (td_params->exec_controls & TDX_EXEC_CONTROL_MAX_GPAW) > > + kvm->arch.gfn_shared_mask = gpa_to_gfn(BIT_ULL(51)); > > + else > > + kvm->arch.gfn_shared_mask = gpa_to_gfn(BIT_ULL(47)); > > + > > .... > > > diff --git a/tools/arch/x86/include/uapi/asm/kvm.h b/tools/arch/x86/include/uapi/asm/kvm.h > > index a9ea3573be1b..779dfd683d66 100644 > > --- a/tools/arch/x86/include/uapi/asm/kvm.h > > +++ b/tools/arch/x86/include/uapi/asm/kvm.h > > @@ -531,6 +531,7 @@ struct kvm_pmu_event_filter { > > /* Trust Domain eXtension sub-ioctl() commands. */ > > enum kvm_tdx_cmd_id { > > KVM_TDX_CAPABILITIES = 0, > > + KVM_TDX_INIT_VM, > > KVM_TDX_CMD_NR_MAX, > > }; > > @@ -576,4 +577,36 @@ struct kvm_tdx_capabilities { > > struct kvm_tdx_cpuid_config cpuid_configs[0]; > > }; > > +struct kvm_tdx_init_vm { > > + __u64 attributes; > > + __u32 max_vcpus; > > + __u32 tsc_khz; > > it needs to align with arch/x86/include/uapi/asm/kvm.h that @tsc_khz needs > to be removed. Thanks, I fixed this patch as follows. diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 81638987cdb9..342decc69649 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1338,8 +1338,6 @@ struct kvm_arch { * the global KVM_MAX_VCPU_IDS may lead to significant memory waste. */ u32 max_vcpu_ids; - - gfn_t gfn_shared_mask; }; struct kvm_vm_stat { diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 190b77f9cdd1..570127d4e566 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -441,7 +441,6 @@ static const struct kvm_cpuid_entry2 *tdx_find_cpuid_entry( { int i; - /* In TDX CPU CONFIG, TDX_CPUID_NO_SUBLEAF means index = 0. */ if (index == TDX_CPUID_NO_SUBLEAF) index = 0; @@ -619,7 +618,6 @@ static int tdx_td_init(struct kvm *kvm, struct kvm_tdx_cmd *cmd) kvm_tdx->tsc_offset = td_tdcs_exec_read64(kvm_tdx, TD_TDCS_EXEC_TSC_OFFSET); kvm_tdx->attributes = td_params->attributes; kvm_tdx->xfam = td_params->xfam; - kvm_tdx->tsc_khz = TDX_TSC_25MHZ_TO_KHZ(td_params->tsc_frequency); kvm->max_vcpus = td_params->max_vcpus; if (td_params->exec_controls & TDX_EXEC_CONTROL_MAX_GPAW) diff --git a/arch/x86/kvm/vmx/tdx.h b/arch/x86/kvm/vmx/tdx.h index 8a0793fcc3ab..3e5782438dc9 100644 --- a/arch/x86/kvm/vmx/tdx.h +++ b/arch/x86/kvm/vmx/tdx.h @@ -25,7 +25,6 @@ struct kvm_tdx { int hkid; u64 tsc_offset; - unsigned long tsc_khz; }; struct vcpu_tdx { diff --git a/tools/arch/x86/include/uapi/asm/kvm.h b/tools/arch/x86/include/uapi/asm/kvm.h index 18654ba2ee87..965a1c2e347d 100644 --- a/tools/arch/x86/include/uapi/asm/kvm.h +++ b/tools/arch/x86/include/uapi/asm/kvm.h @@ -581,7 +581,7 @@ struct kvm_tdx_capabilities { struct kvm_tdx_init_vm { __u64 attributes; __u32 max_vcpus; - __u32 tsc_khz; + __u32 padding; __u64 mrconfigid[6]; /* sha384 digest */ __u64 mrowner[6]; /* sha384 digest */ __u64 mrownerconfig[6]; /* sha348 digest */ -- Isaku Yamahata