Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp584635rwb; Thu, 12 Jan 2023 09:36:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXtA5PssoR6RDThG9lDviJrA6o60N4cdR1HcVv4cFPepEp1NP44+YuFcJJjfEIsVusZUa2mb X-Received: by 2002:aa7:d411:0:b0:492:bf3d:1a1a with SMTP id z17-20020aa7d411000000b00492bf3d1a1amr25756931edq.18.1673545012166; Thu, 12 Jan 2023 09:36:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673545012; cv=none; d=google.com; s=arc-20160816; b=w4Ivoj6uNllHbX4vKOybXa5mxXk2LjmC3r5b/gAWcMxc0Uxf8rYmI+GcuA+sJqnObz vA113yknPF/tfj/X7bgGKyZSD3DZkVLsPPjrce5bAK2tcWQvUsqLGaLAR69UsEReFGeU O3AgSuRqwyE3NFH7fmSXC1VdHCeEj81bBP/R1QIYUrym8Rbg/acGRghy5UZmyPq18KuY HzZHTMkou+RNHQKV8tUauMqs4m9dZJWAH0GB/z/NUQY4x9HqoScqY/JU8dMmeoZWzgW6 /4saKqWCHwcxq+hrkuhtFNCKfbNdb087KCu8wVeLoBy24Ssk9wD5ynK7DRu0Z3HNzmFY T6ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8M0y4JrbngsTUC9d7M4BjMYJKHu1fa3sUtsh/MeZhVI=; b=NQQEiaD2kDew4eOpmsP8RU0AyvDMZEGZZS9mSjW4VKpI7g2UQczKMjTptWdpQe9sx8 xk/USyWmJeRYwaW5zPL5F6iZeSIEx7MJntINypXW9wyB/Kuzpnjz6NTpWeNQSOzP7DMG Ah1WC46QMU7GRSvMLPhNDlkDyk9wm4z18KpSmI6eh0Gxnpzn4xX6P6f1Rm4bJkchKR7S KW77kb/wZosrLuNtZvw4JTUh87/JYqV3yTiRBCVREwue4ANZNKccSuqVYJ40kg0lPuMX tLkXD0/HnydzDnQKaIQQ62ibPuZQpSfHK5+Jja/nWJ2YLe1rnA5nB0rlsJnUGSl/C2/Z 7xbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Fz/e3ayG"; 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 h3-20020a50ed83000000b0048f68044105si17434471edr.478.2023.01.12.09.36.40; Thu, 12 Jan 2023 09:36:52 -0800 (PST) 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="Fz/e3ayG"; 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 S240527AbjALRKz (ORCPT + 50 others); Thu, 12 Jan 2023 12:10:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235333AbjALRKV (ORCPT ); Thu, 12 Jan 2023 12:10:21 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 579AF5D8BF; Thu, 12 Jan 2023 08:47:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673542071; x=1705078071; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cFvN8cXkdxYZpaCwLAKQFI0KDAWdozzMlOc3mI82T5c=; b=Fz/e3ayGP+qoObh6bSDl4a4GpQ1p+a4GII2pMnG988OkNjkl8kVwpVq/ Yh8LNfHmB9LRxyMNrbpgkcDmcVMJc9i17NK/5uDcQ2DMT8WDlqIQW8B1m xnxnej6q84KPiETcv6qTNsF7sTVMn61PNjupTdz1B4rPvHcWCaWN9tXsp glDDEbOeVrPGWprCwdKTcxsd0n7+0lPRNPU+fpL+fe2WgEPdEQbaBeoSe bIugmm3Um1p3R+kvX/JkORlFbXJBN5NMwvG2HaLg6z5M0zh77bPxLhRRU llhBLIHh5PmtCHipQgq0alfPLdK/X1IiHjirz86aL8zKe6q+/hoNUVPqL g==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="323816285" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="323816285" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:44:16 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="986658327" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="986658327" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:44:16 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Xiaoyao Li Subject: [RFC PATCH v3 03/16] KVM: TDX: Pass KVM page level to tdh_mem_page_add() and tdh_mem_page_aug() Date: Thu, 12 Jan 2023 08:43:55 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 From: Xiaoyao Li Level info is needed in tdh_clflush_page() to generate the correct page size. 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 487ba90a0b7c..8959a019b87a 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1324,6 +1324,7 @@ static void tdx_unpin(struct kvm *kvm, kvm_pfn_t pfn) static int tdx_sept_set_private_spte(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); @@ -1348,7 +1349,7 @@ static int tdx_sept_set_private_spte(struct kvm *kvm, gfn_t gfn, if (KVM_BUG_ON(level != PG_LEVEL_4K, kvm)) return -EINVAL; - 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 (err == TDX_ERROR_SEPT_BUSY) { tdx_unpin(kvm, pfn); return -EAGAIN; @@ -1387,8 +1388,8 @@ static int tdx_sept_set_private_spte(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 4db983b1dc94..4b03acce5003 100644 --- a/arch/x86/kvm/vmx/tdx_ops.h +++ b/arch/x86/kvm/vmx/tdx_ops.h @@ -19,6 +19,11 @@ void pr_tdx_error(u64 op, u64 error_code, const struct tdx_module_output *out); +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)); @@ -60,11 +65,11 @@ static inline u64 tdh_mng_addcx(hpa_t tdr, hpa_t addr) return __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_output *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_output *out) { - tdx_clflush_page(hpa, PG_LEVEL_4K); - return seamcall_sept(TDH_MEM_PAGE_ADD, gpa, tdr, hpa, source, out); + tdx_clflush_page(hpa, tdx_sept_level_to_pg_level(level)); + return seamcall_sept(TDH_MEM_PAGE_ADD, gpa | level, tdr, hpa, source, out); } static inline u64 tdh_mem_sept_add(hpa_t tdr, gpa_t gpa, int level, hpa_t page, @@ -93,11 +98,11 @@ static inline u64 tdh_mem_page_relocate(hpa_t tdr, gpa_t gpa, hpa_t hpa, return __seamcall(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_output *out) { - tdx_clflush_page(hpa, PG_LEVEL_4K); - return seamcall_sept(TDH_MEM_PAGE_AUG, gpa, tdr, hpa, 0, out); + tdx_clflush_page(hpa, tdx_sept_level_to_pg_level(level)); + return 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, -- 2.25.1