Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30014596rwd; Wed, 5 Jul 2023 22:51:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlGfnsaGOctIWsfm59NNymng0oyjphKmBBswEU/XXi4N3FE0PXHD0vMYRre2Y587AL68h3Fu X-Received: by 2002:a81:6184:0:b0:570:6fbd:2daf with SMTP id v126-20020a816184000000b005706fbd2dafmr1992981ywb.37.1688622667545; Wed, 05 Jul 2023 22:51:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688622667; cv=none; d=google.com; s=arc-20160816; b=CKmLX+e8k4VKLEQgKk9gcXOIjYtxYPNTWlTaUC91j+Nt73LvhfK7IrRxgmknIdQOu5 rlX8yfI4tx9FZBOgDHyvntPRe3ymV63Q2pfGLw0W2fkAnczhYX6YCoarB+IJsJ32yrcg WH7ek6PPTSgdwEHQd97G/cLK+nNFxtM2v8f68lY95hZPsn8xn6pargk+EsyM2wo+BVOF bSogXw55ne1LSv2hEvCM60IbI5koMK9KbkZZXOLghLZQyrGgcregthheLxW133aVd/re Di3mae2wtumoWz5pkLs3FfSFJ11rma+uUL/0Kty5mWjgn0LpUfgFbN5RNkbw/hcbUcqa jLIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ig7167W3LV6LpRLIUtP1+sSOf4eeNbNUA0HTsOx6mdg=; fh=UsMbGkySWIf+V1iIcowwYfzB/9P9iwgPklMNQSCV2+o=; b=VqBLMx7PzIYw2VHA31ObmYNjijPsAEhah68LWCU1cLSevkJ10/D889+CbBvwBom+Jr 8GCedgmsO8aTXLtrYRVPmstg69fKkl1sqR5P3EMT4BLuIrca9AoOZKoTaqJX8xcYl7aG tvXwxIHXTFkKESjRbM8tIY6b9mC5hMmrxiIH3XL9RyGib2oHm9NX951DgK4V5CBLgPiE JINovZnPW338FAJpwRVGMd3BekSOb/gJVLs4jsFCZvpnmhRGWCkQrFg7e2bNRd7LB0ev cjPkcYXT9yOJhKKw5E9eC1mmwsd5nwVBLD4eZsrHtwl3ckPbnWFRWQf6+P4owxdbjUdt zBWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aBdYe7U2; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x64-20020a638643000000b0055acc7f8085si853315pgd.367.2023.07.05.22.50.51; Wed, 05 Jul 2023 22:51:07 -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=@intel.com header.s=Intel header.b=aBdYe7U2; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233210AbjGFFcJ (ORCPT + 99 others); Thu, 6 Jul 2023 01:32:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233158AbjGFFcI (ORCPT ); Thu, 6 Jul 2023 01:32:08 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40D561BC7; Wed, 5 Jul 2023 22:32:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688621527; x=1720157527; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=KVUs4bhGOt3/uYXQH2AZkEfvp9H4c7HOkrp0u7M/8fQ=; b=aBdYe7U2BT31atEpq1sLqj5cmXWPRU+YYYcMNeVEs10BUrivbvDXa3mM zFe26kG550XNcFn9M6yCx/kSLovZrWCik7dZIMvpwlfjJQcFgkG11QO6K uVymlm0cdrRg1RaqzLR0eV6Rfz+4DBhQqVy67DnNRaxOh1GWj/4j9Ysym kVFYzYwLDqMARNDe+nK0ZqGJKrn5U3VGPgGDYvWxMdR685DunLUTC/+D8 c3lzABYNy2/5XQuA786582ipSz125qmGK1g3nVQtBmOfZiUVjp99iJcFw w89lxcUjmq6Ly2x1GMoGhbkCSxFZzN8k0h4Ig1kZmCa2uZz7Om5L4XVOM Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10762"; a="362379815" X-IronPort-AV: E=Sophos;i="6.01,184,1684825200"; d="scan'208";a="362379815" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2023 22:32:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10762"; a="719477423" X-IronPort-AV: E=Sophos;i="6.01,184,1684825200"; d="scan'208";a="719477423" Received: from yy-desk-7060.sh.intel.com (HELO localhost) ([10.239.159.76]) by orsmga002.jf.intel.com with ESMTP; 05 Jul 2023 22:31:59 -0700 Date: Thu, 6 Jul 2023 13:31:58 +0800 From: Yuan Yao To: Kai Huang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, tony.luck@intel.com, peterz@infradead.org, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, david@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, ashok.raj@intel.com, reinette.chatre@intel.com, len.brown@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, ying.huang@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, nik.borisov@suse.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com Subject: Re: [PATCH v12 16/22] x86/virt/tdx: Initialize all TDMRs Message-ID: <20230706053158.73plfugwqvwwkdeo@yy-desk-7060> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171215 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 27, 2023 at 02:12:46AM +1200, Kai Huang wrote: > After the global KeyID has been configured on all packages, initialize > all TDMRs to make all TDX-usable memory regions that are passed to the > TDX module become usable. > > This is the last step of initializing the TDX module. > > Initializing TDMRs can be time consuming on large memory systems as it > involves initializing all metadata entries for all pages that can be > used by TDX guests. Initializing different TDMRs can be parallelized. > For now to keep it simple, just initialize all TDMRs one by one. It can > be enhanced in the future. Reviewed-by: Yuan Yao > > Signed-off-by: Kai Huang > Reviewed-by: Isaku Yamahata > Reviewed-by: Kirill A. Shutemov > --- > > v11 -> v12: > - Added Kirill's tag > > v10 -> v11: > - No update > > v9 -> v10: > - Code change due to change static 'tdx_tdmr_list' to local 'tdmr_list'. > > v8 -> v9: > - Improved changlog to explain why initializing TDMRs can take long > time (Dave). > - Improved comments around 'next-to-initialize' address (Dave). > > v7 -> v8: (Dave) > - Changelog: > - explicitly call out this is the last step of TDX module initialization. > - Trimed down changelog by removing SEAMCALL name and details. > - Removed/trimmed down unnecessary comments. > - Other changes due to 'struct tdmr_info_list'. > > v6 -> v7: > - Removed need_resched() check. -- Andi. > > > --- > arch/x86/virt/vmx/tdx/tdx.c | 60 ++++++++++++++++++++++++++++++++----- > arch/x86/virt/vmx/tdx/tdx.h | 1 + > 2 files changed, 53 insertions(+), 8 deletions(-) > > diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c > index f5d4dbc11aee..52b7267ea226 100644 > --- a/arch/x86/virt/vmx/tdx/tdx.c > +++ b/arch/x86/virt/vmx/tdx/tdx.c > @@ -994,6 +994,56 @@ static int config_global_keyid(void) > return ret; > } > > +static int init_tdmr(struct tdmr_info *tdmr) > +{ > + u64 next; > + > + /* > + * Initializing a TDMR can be time consuming. To avoid long > + * SEAMCALLs, the TDX module may only initialize a part of the > + * TDMR in each call. > + */ > + do { > + struct tdx_module_output out; > + int ret; > + > + /* All 0's are unused parameters, they mean nothing. */ > + ret = seamcall(TDH_SYS_TDMR_INIT, tdmr->base, 0, 0, 0, NULL, > + &out); > + if (ret) > + return ret; > + /* > + * RDX contains 'next-to-initialize' address if > + * TDH.SYS.TDMR.INIT did not fully complete and > + * should be retried. > + */ > + next = out.rdx; > + cond_resched(); > + /* Keep making SEAMCALLs until the TDMR is done */ > + } while (next < tdmr->base + tdmr->size); > + > + return 0; > +} > + > +static int init_tdmrs(struct tdmr_info_list *tdmr_list) > +{ > + int i; > + > + /* > + * This operation is costly. It can be parallelized, > + * but keep it simple for now. > + */ > + for (i = 0; i < tdmr_list->nr_consumed_tdmrs; i++) { > + int ret; > + > + ret = init_tdmr(tdmr_entry(tdmr_list, i)); > + if (ret) > + return ret; > + } > + > + return 0; > +} > + > static int init_tdx_module(void) > { > struct tdsysinfo_struct *sysinfo; > @@ -1067,14 +1117,8 @@ static int init_tdx_module(void) > if (ret) > goto out_reset_pamts; > > - /* > - * TODO: > - * > - * - Initialize all TDMRs. > - * > - * Return error before all steps are done. > - */ > - ret = -EINVAL; > + /* Initialize TDMRs to complete the TDX module initialization */ > + ret = init_tdmrs(&tdmr_list); > out_reset_pamts: > if (ret) { > /* > diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h > index a0438513bec0..f6b4e153890d 100644 > --- a/arch/x86/virt/vmx/tdx/tdx.h > +++ b/arch/x86/virt/vmx/tdx/tdx.h > @@ -25,6 +25,7 @@ > #define TDH_SYS_INFO 32 > #define TDH_SYS_INIT 33 > #define TDH_SYS_LP_INIT 35 > +#define TDH_SYS_TDMR_INIT 36 > #define TDH_SYS_CONFIG 45 > > struct cmr_info { > -- > 2.40.1 >