Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp296213rdb; Thu, 16 Nov 2023 21:26:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/mFLzMBhwiQmvG2MBrs+Dk9MGSIRz2xoAHwKEqWaPR4zk3FWxDGhuTbHk6m6O8WJFyBWQ X-Received: by 2002:a17:902:f683:b0:1ca:b820:74ed with SMTP id l3-20020a170902f68300b001cab82074edmr12431479plg.14.1700198789287; Thu, 16 Nov 2023 21:26:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700198789; cv=none; d=google.com; s=arc-20160816; b=BRc3l6mq89FDQSgYFnsO6JbXoV5CKwWE9iv7q/pNVBZZyLgPjtvPM1G+FZWxNq3REC VvOV7WXxOG93zkHsipC7PZde7bbbEaedX25iJBd3Yb5nCptiS1NENF9WcAUAjMsH2xcR Zwdtqwk7sBEoFslNR3wmTwEWE04MRJXOfIyW5Xag+p7arad9fZdCzaqxkdZX1JJEcOu9 edyzck+45O5OOLsEJDjrJZzGIjg0MPLm5fjpS+N8xVmQUPV4Q2F7BGi2DEi34M32qHdI SafpXtGFLS2uznKThhJA5M/XOffp+Fk0SAclp8OAkKSxqci6MJ/RxH850SW8AQ2HFrzS 3aNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=FFoc1IH7baCoTiRdLm3Mjp+1krYXj4D4g6RIdmEOBy8=; fh=JG9L47Y1iXtACaBOet2e3COioV3qGH2vBQJMdUd1zpk=; b=hMB7DzlBgnPJqWDkXTTJf73HL+5pMMmI/dPO8iK0RgZxdotih0mmW+/18cML0acMU2 8xU7oOgsYfQ+gekrstGdSXDADqVyvjUv3ToE9sBVT1TgukVn2DYqMvlcEqiNeoRna6eb XMxf6bkyi8Iq5G+ikThYZ0pvUGHrHq3QgBKIiiEChz48lC5MRsfcP2gaogy0ie9zKhl6 BfeHr3Wn8fQoESaDZasGV6J9nge1ReKBI5miJR3L1d6tYPfkdKWhWNgiQQNDvqTqFJE8 XF1+AC6pdHnzbJhN7rqpfKvk6NX5mHBFROGd5ZiXzAJciKNmwOgSspAzN6jEbcCu+0bc DqWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QFYOBjul; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id v1-20020a170902b7c100b001ca81fa0661si999327plz.508.2023.11.16.21.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 21:26:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QFYOBjul; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 995AD801B98A; Thu, 16 Nov 2023 21:26:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229995AbjKQF0N (ORCPT + 99 others); Fri, 17 Nov 2023 00:26:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjKQF0L (ORCPT ); Fri, 17 Nov 2023 00:26:11 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9D50D4A; Thu, 16 Nov 2023 21:26:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700198768; x=1731734768; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=RV8fvqjrUV0BSx8JFW/NdoI1Bmp5l5A2r3kiF0HPx54=; b=QFYOBjul2qc/QbLeLs7Gv2lZoKw/dJmrzE0YWTV8pvDiEZpCDciTMrDF jZOZYBGKJL4h/ZvlFFeZ7EcAuGTBkzvlrOa/fisD4e0gg4T1rnTPeJkSJ +b+3gZvlbJ30ygT1xyBX2w4cgnvcjRlP12Xu+otDIxGqo1mrQBO1SkQ8w UoL731OM9GUlSttZTgnEgGi8I4jaleocfFfvodjasTNdNyuOXAIUjHetk LxOLQTa0GTkDP2r0Pjbh1lwOIAEHbIADnkGyD0cQXb3UlvOANiCFAnJl8 YzOw0ndi7Y7SqnusE82ok6w2MHSekqZ15Zj89w0CW5xu4dju5Kv870dy4 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10896"; a="395163698" X-IronPort-AV: E=Sophos;i="6.04,206,1695711600"; d="scan'208";a="395163698" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2023 21:26:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10896"; a="769127386" X-IronPort-AV: E=Sophos;i="6.04,206,1695711600"; d="scan'208";a="769127386" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.238.10.126]) ([10.238.10.126]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2023 21:25:59 -0800 Message-ID: Date: Fri, 17 Nov 2023 13:25:57 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v17 059/116] KVM: TDX: Create initial guest memory To: Isaku Yamahata Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, gkirkpatrick@google.com References: <20231117000458.GB1277973@ls.amr.corp.intel.com> From: Binbin Wu In-Reply-To: <20231117000458.GB1277973@ls.amr.corp.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 16 Nov 2023 21:26:26 -0800 (PST) On 11/17/2023 8:04 AM, Isaku Yamahata wrote: > On Thu, Nov 16, 2023 at 02:35:33PM +0800, > Binbin Wu wrote: > >> >> On 11/7/2023 10:56 PM, isaku.yamahata@intel.com wrote: >>> From: Isaku Yamahata >>> >>> Because the guest memory is protected in TDX, the creation of the initial >>> guest memory requires a dedicated TDX module API, tdh_mem_page_add, instead >>> of directly copying the memory contents into the guest memory in the case >>> of the default VM type. KVM MMU page fault handler callback, >>> private_page_add, handles it. >>> >>> Define new subcommand, KVM_TDX_INIT_MEM_REGION, of VM-scoped >>> KVM_MEMORY_ENCRYPT_OP. It assigns the guest page, copies the initial >>> memory contents into the guest memory, encrypts the guest memory. At the >>> same time, optionally it extends memory measurement of the TDX guest. It >>> calls the KVM MMU page fault(EPT-violation) handler to trigger the >>> callbacks for it. >>> >>> Reported-by: gkirkpatrick@google.com >>> Signed-off-by: Isaku Yamahata >>> >>> --- >>> v15 -> v16: >>> - add check if nr_pages isn't large with >>> (nr_page << PAGE_SHIFT) >> PAGE_SHIFT >>> >>> v14 -> v15: >>> - add a check if TD is finalized or not to tdx_init_mem_region() >>> - return -EAGAIN when partial population >>> --- >>> arch/x86/include/uapi/asm/kvm.h | 9 ++ >>> arch/x86/kvm/mmu/mmu.c | 1 + >>> arch/x86/kvm/vmx/tdx.c | 167 +++++++++++++++++++++++++- >>> arch/x86/kvm/vmx/tdx.h | 2 + >>> tools/arch/x86/include/uapi/asm/kvm.h | 9 ++ >>> 5 files changed, 185 insertions(+), 3 deletions(-) >>> >> [...] >>> +static int tdx_sept_page_add(struct kvm *kvm, gfn_t gfn, >>> + enum pg_level level, kvm_pfn_t pfn) >> For me, the function name is a bit confusing. >> I would relate it to a SEPT table page instead of a normal private page if >> only by the function name. >> >> Similar to tdx_sept_page_aug(), though it's less confusing due to there is >> no seam call to aug a sept table page. > How about tdx_mem_page_{add, aug}()? It looks good to me.