Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3126097rdb; Thu, 16 Nov 2023 00:19:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEH0NGsYkKF20LGiW3jKNhPwNUXQfc22RNv/rJyJseUiRVMxPdCqUNcCtl615uGfY0ydUSM X-Received: by 2002:a05:6a00:b4a:b0:6be:5367:2131 with SMTP id p10-20020a056a000b4a00b006be53672131mr15507514pfo.24.1700122751253; Thu, 16 Nov 2023 00:19:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700122751; cv=none; d=google.com; s=arc-20160816; b=QYJDrQ7nB3gyUmFi5ZTeVGQU3vbhi62IPSqKNcdTxJ0jLtJYdAWVhbjhUdAndwYIMM ISDVs08Zm8Z5KFdi3m3mCDsATRWQ+HjAxzP0aA6cEdu/YdyuuQZ6jg3YYwXCFMb+OJF9 H0M0YvxV4y6ae1WEfV9HYiCrsMLD4KiMPtCjEaL7zVeB4myFRLUurxOWXGZQO5fcuIoN C0Wh+ibMg60knUUIUhF9gdkWGX221/LRNZZt4DvhBPnlrWdyVMu2uwpmIKr+EpULv0Gx rx9LZAT+p9DXbSvMFFdCoNeWlLUzA80dK3K2qgAamec9DjKUNhvkvl8BhlaxALgxGohC pfIg== 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=1RG3PF6PU6MwhNSQFWk9fzUeFgNTROOQy2oHLgx0Ti0=; fh=SSl64FBK0Lhy77ytVxLm3gRT6oITPT9jTW5tmAf+4Dk=; b=tSUi7HyjzMSEuiJSC0LLbHCyEdPy6st/Dgc1VxjKw9NmvyB+S1xlkqabCO9Lb6eCsz K3pEvmI1rdb60YPIz1Se28Hmx8CGSFn+Ie7I08LQDTOraGzomaxloev7z2lymqtvnXX+ nM9DHHgfMagBU1Ur8DmNsTXMYgetEQTUUYhKsn0PLgdXwDmtvnGOqCrQH+fYh0cQ75eO pzrpL3bNyEcKVfjBO4MdJAEYb7V8JgXp+KfkCgstYyYFYxDioYuNQD7IuJ0FVMYfHa9u ViZ/dgZDFHuiLRXo7aS0O4Waj0X7mEmLli0BuN9/3CIeb5pqAvx8nuClUp2CJ/wmtozq CA5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kyaZ9NZF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id c21-20020a056a00249500b006c3482c4e4dsi11971984pfv.289.2023.11.16.00.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 00:19:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kyaZ9NZF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 6E2CC80283ED; Thu, 16 Nov 2023 00:19:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229919AbjKPIS5 (ORCPT + 99 others); Thu, 16 Nov 2023 03:18:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229795AbjKPISu (ORCPT ); Thu, 16 Nov 2023 03:18:50 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 511FA196; Thu, 16 Nov 2023 00:18:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700122726; x=1731658726; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=FbushCVIFv+PY/6S/x2mvxLk/35CqPa8wajnY9+0vW4=; b=kyaZ9NZFtCurrk4S7363ZlZlZU0rJgxG6Y3bk8e2V/SOoBdCPwY8zDZ2 KXVnAJty3Ipi2UyPMJhHFzl6WlixeAv4ZeOSLiR8+zz99n0VqxEHXIS/Y 7ATWbOqMJT5fD8IA698XwI5grXp5xDKvbxMkxYUmaTb1f5R2h8SJKNJh+ 6Zoyiz0p5ldzRx+/+qOGTAMXWb1+IScMV2ixy35uen+SL6UesCFW5J/91 D4Gx9zD6wZl6yAG/dD1Ru0vTd52JjHaviENAcU03p/pp3GptHMBKDw07d wsWTeg3OGsiYtBshd/FdIPhtPlijA6BFuhbDL0cYIBO3kFANwg6BkC0Jn w==; X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="389899556" X-IronPort-AV: E=Sophos;i="6.03,307,1694761200"; d="scan'208";a="389899556" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2023 00:18:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10895"; a="768846727" X-IronPort-AV: E=Sophos;i="6.03,307,1694761200"; d="scan'208";a="768846727" 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 00:18:30 -0800 Message-ID: Date: Thu, 16 Nov 2023 16:18:28 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 03/16] KVM: TDX: Pass KVM page level to tdh_mem_page_add() and tdh_mem_page_aug() To: isaku.yamahata@intel.com Cc: 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, Xiaoyao Li References: From: Binbin Wu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Thu, 16 Nov 2023 00:19:08 -0800 (PST) On 11/7/2023 11:00 PM, isaku.yamahata@intel.com wrote: > From: Xiaoyao Li > > Level info is needed in tdh_clflush_page() to generate the correct page > size. tdh_clflush_page() -> tdx_clflush_page() > > Besides, explicitly pass level info to SEAMCALL instead of assuming > it's zero. It works naturally when 2MB support lands. > > Signed-off-by: Xiaoyao Li > Signed-off-by: Isaku Yamahata > --- > arch/x86/kvm/vmx/tdx.c | 7 ++++--- > arch/x86/kvm/vmx/tdx_ops.h | 19 ++++++++++++------- > 2 files changed, 16 insertions(+), 10 deletions(-) > > diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c > index 8b58d91bda4e..2d5c86e06c5f 100644 > --- a/arch/x86/kvm/vmx/tdx.c > +++ b/arch/x86/kvm/vmx/tdx.c > @@ -1468,7 +1468,7 @@ static int tdx_sept_page_aug(struct kvm *kvm, gfn_t gfn, > union tdx_sept_entry entry; > u64 err; > > - err = tdh_mem_page_aug(kvm_tdx->tdr_pa, gpa, hpa, &out); > + err = tdh_mem_page_aug(kvm_tdx->tdr_pa, gpa, tdx_level, hpa, &out); > if (unlikely(err == TDX_ERROR_SEPT_BUSY)) { > tdx_unpin(kvm, pfn); > return -EAGAIN; > @@ -1497,6 +1497,7 @@ static int tdx_sept_page_aug(struct kvm *kvm, gfn_t gfn, > static int tdx_sept_page_add(struct kvm *kvm, gfn_t gfn, > enum pg_level level, kvm_pfn_t pfn) > { > + int tdx_level = pg_level_to_tdx_sept_level(level); > struct kvm_tdx *kvm_tdx = to_kvm_tdx(kvm); > hpa_t hpa = pfn_to_hpa(pfn); > gpa_t gpa = gfn_to_gpa(gfn); > @@ -1531,8 +1532,8 @@ static int tdx_sept_page_add(struct kvm *kvm, gfn_t gfn, > kvm_tdx->source_pa = INVALID_PAGE; > > do { > - err = tdh_mem_page_add(kvm_tdx->tdr_pa, gpa, hpa, source_pa, > - &out); > + err = tdh_mem_page_add(kvm_tdx->tdr_pa, gpa, tdx_level, hpa, > + source_pa, &out); > /* > * This path is executed during populating initial guest memory > * image. i.e. before running any vcpu. Race is rare. > diff --git a/arch/x86/kvm/vmx/tdx_ops.h b/arch/x86/kvm/vmx/tdx_ops.h > index e726102d3523..0f2df7198bde 100644 > --- a/arch/x86/kvm/vmx/tdx_ops.h > +++ b/arch/x86/kvm/vmx/tdx_ops.h > @@ -63,6 +63,11 @@ static inline u64 tdx_seamcall(u64 op, u64 rcx, u64 rdx, u64 r8, u64 r9, > void pr_tdx_error(u64 op, u64 error_code, const struct tdx_module_args *out); > #endif > > +static inline enum pg_level tdx_sept_level_to_pg_level(int tdx_level) > +{ > + return tdx_level + 1; > +} > + > static inline void tdx_clflush_page(hpa_t addr, enum pg_level level) > { > clflush_cache_range(__va(addr), KVM_HPAGE_SIZE(level)); > @@ -104,11 +109,11 @@ static inline u64 tdh_mng_addcx(hpa_t tdr, hpa_t addr) > return tdx_seamcall(TDH_MNG_ADDCX, addr, tdr, 0, 0, NULL); > } > > -static inline u64 tdh_mem_page_add(hpa_t tdr, gpa_t gpa, hpa_t hpa, hpa_t source, > - struct tdx_module_args *out) > +static inline u64 tdh_mem_page_add(hpa_t tdr, gpa_t gpa, int level, hpa_t hpa, > + hpa_t source, struct tdx_module_args *out) > { > - tdx_clflush_page(hpa, PG_LEVEL_4K); > - return tdx_seamcall_sept(TDH_MEM_PAGE_ADD, gpa, tdr, hpa, source, out); > + tdx_clflush_page(hpa, tdx_sept_level_to_pg_level(level)); > + return tdx_seamcall_sept(TDH_MEM_PAGE_ADD, gpa | level, tdr, hpa, source, out); > } For TDH_MEM_PAGE_ADD, only 4K page is supported, is this change necessary? Or maybe huge page can be supported by TDH_MEM_PAGE_ADD in the future? > > static inline u64 tdh_mem_sept_add(hpa_t tdr, gpa_t gpa, int level, hpa_t page, > @@ -143,11 +148,11 @@ static inline u64 tdh_mem_page_relocate(hpa_t tdr, gpa_t gpa, hpa_t hpa, > return tdx_seamcall_sept(TDH_MEM_PAGE_RELOCATE, gpa, tdr, hpa, 0, out); > } > > -static inline u64 tdh_mem_page_aug(hpa_t tdr, gpa_t gpa, hpa_t hpa, > +static inline u64 tdh_mem_page_aug(hpa_t tdr, gpa_t gpa, int level, hpa_t hpa, > struct tdx_module_args *out) > { > - tdx_clflush_page(hpa, PG_LEVEL_4K); > - return tdx_seamcall_sept(TDH_MEM_PAGE_AUG, gpa, tdr, hpa, 0, out); > + tdx_clflush_page(hpa, tdx_sept_level_to_pg_level(level)); > + return tdx_seamcall_sept(TDH_MEM_PAGE_AUG, gpa | level, tdr, hpa, 0, out); > } > > static inline u64 tdh_mem_range_block(hpa_t tdr, gpa_t gpa, int level,