Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp193961rdb; Mon, 22 Jan 2024 17:14:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbuLf+88WWCvZMs+dtHKyvQPjrXQCowNd3l9k7ZxdjMkzBG+qI7sKX53v5EdjwVt2lHUug X-Received: by 2002:a54:449a:0:b0:3bd:8e96:a0c8 with SMTP id v26-20020a54449a000000b003bd8e96a0c8mr5687730oiv.75.1705972450123; Mon, 22 Jan 2024 17:14:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705972450; cv=pass; d=google.com; s=arc-20160816; b=0VIAaOtM4I2Lbd66D8zayPeNXCVoKtqAf7ekul1LDr6twWPhgYvDW+KNeR13yOc8Fy 2gP2mHOzxSqqJreux/NFjm2OmfTplc/ElptqnmLOdo6knSlLvD0WZ+whFByHK7IFLO2p RTWwWRaHMukJcmLRBc236SiBrxR7jrmuCItjnNGPpq1EUjrR7rqW4uHGw3EcBFjxCBfc ESM8aZ6u+nZ3/74VVLbUakzQClJUnGmOB3DkDLM6X259MSBcpAb3NQ9+qIbYXzCuidIu 6P6D35UQe/CG5n4egNtSPtx+u6h58mvGpCucxzztgf5imiJuSBFqQ6A4urNRFizfFmiB l2zQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fzy3Ky5twyE+Caui4DkpsNQdMqvtNu/kIr40p9pOkbs=; fh=sMdP/xP2j0mAr7mmqXKi/DmIqVqVXObmf3aqGFg9BJU=; b=LdyFh1GnqsjosbZxh5MI4IqunxuIdpgIf4rtY1+syqnLroO8OuAb5H5daKJkdkJDxR l001h4WvkaLlXcrvK8ubfX7cf49Y+yrxnsD7uipj0zcuSC6DVWcezS15GbHWk4AbPqOQ NWGmS09NQrpobmB2Ux9hMli5iknDjoMqmCNPVa3y/bQvvLWk1DaitobvQ7udO+Lfagz3 VRqrz8Ftgyj4lpKvVCcfOLcZLusFifsTAUzAT4c9vOXlj6L/M2j5+KIT3jpczoNRtzaz tebcyoNWNIySe/08GqdCarf0TSpgWO1v4TvNar78YhjWPzd5PhupC56ORUMgYSKD7faK ykkw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GfxJBnDD; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34450-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34450-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t7-20020a62d147000000b006db8855e8b6si11171450pfl.187.2024.01.22.17.14.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 17:14:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34450-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GfxJBnDD; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34450-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34450-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AEF9528BAB7 for ; Tue, 23 Jan 2024 01:02:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA7D614E2D8; Tue, 23 Jan 2024 00:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GfxJBnDD" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F2B614D45E; Tue, 23 Jan 2024 00:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=134.134.136.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969361; cv=none; b=F3KocvEZT1Bv5ya8FP7kw36xmPApThSKm12q4wkPz/aLr1XoYprMmrfZEXrAhSyxIDIxohvXGZrxZzjCWq/pAZOnRBNtlpu9izmIGfeUoQisTe92tN3QWrIN63j64B57mYYGBCUwK5LMqKO/rxhCCx2vhVwVDdgXvilrNg7jKCs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969361; c=relaxed/simple; bh=R8cBMPqil2+5pjGW+al9piEQU44M2m54kdZoD0oUf8w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LwD+YJZ3kmAKBCe3cQq5Creock9LduXAhnmUftqPPkkV/Mv+DnXlVHbI1XUlVX6asNmlbE0b50mW1VaFuBEmJ/FnzPGD+xa27gm+S8j8np4vXxJBDS6MbKycQiTL8F9yL4M+a+1msb4e7SYO+WfdriLqtZ9uw5WGUuLWp65sUjo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=GfxJBnDD; arc=none smtp.client-ip=134.134.136.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705969359; x=1737505359; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R8cBMPqil2+5pjGW+al9piEQU44M2m54kdZoD0oUf8w=; b=GfxJBnDDhfz42jEJPsWkzAqSaPyVDSW/CFp1Rc/tVaK6v37NJICwlbNs CiXbXtnBWBkLrf6wirmw//dgGhGCU3lYwHtP+PIeDCzNWvQtQ+C1HTxNY 9LbMKhDyMq99Fs+WiLkc4Tyd31D5ZAKJw/BgZormfhUfXAWmEz6EalOKv EwgxC2+PcVW3G/F97k2Y4b+IkB37i0R5Q3bg5BbJH70ZviCxKAcsKuEcs a+7jqHPH/miPwuRXtTXwv5RjpV8hXccKPTqi0q8TJGfm5ewnjtYY6AfIU 35cV9JQN1QxJ/K6L4vPt1dL1SSivJJwxQvHr2PEkjWpS2XcHEYm96VHSk g==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="405125645" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="405125645" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 16:22:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="27825624" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 16:22:36 -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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Xiaoyao Li Subject: [PATCH v7 02/13] KVM: TDX: Pass KVM page level to tdh_mem_page_aug() Date: Mon, 22 Jan 2024 16:22:17 -0800 Message-Id: <63c4832507b9b10383e00b33ce2ab6e756ecdf3b.1705965958.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Xiaoyao Li Level info is needed in tdx_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 --- v7: - Don't pass level to tdh_mem_page_add() as it supports only 4K page. - catch up for change of tdx_seamcall() --- arch/x86/kvm/vmx/tdx.c | 2 +- arch/x86/kvm/vmx/tdx_ops.h | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 67bb0c4c73a7..549dec05ccad 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1520,7 +1520,7 @@ static int tdx_mem_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; diff --git a/arch/x86/kvm/vmx/tdx_ops.h b/arch/x86/kvm/vmx/tdx_ops.h index 2afd927eaa45..ce722e917d14 100644 --- a/arch/x86/kvm/vmx/tdx_ops.h +++ b/arch/x86/kvm/vmx/tdx_ops.h @@ -59,6 +59,11 @@ static inline int pg_level_to_tdx_sept_level(enum pg_level level) return level - 1; } +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)); @@ -108,6 +113,7 @@ static inline u64 tdh_mng_addcx(hpa_t tdr, hpa_t addr) static inline u64 tdh_mem_page_add(hpa_t tdr, gpa_t gpa, hpa_t hpa, hpa_t source, struct tdx_module_args *out) { + /* TDH.MEM.PAGE.ADD() suports only 4K page. tdx 4K page level = 0 */ struct tdx_module_args in = { .rcx = gpa, .rdx = tdr, @@ -178,16 +184,16 @@ static inline u64 tdh_mem_page_relocate(hpa_t tdr, gpa_t gpa, hpa_t hpa, return tdx_seamcall_sept(TDH_MEM_PAGE_RELOCATE, &in, 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) { struct tdx_module_args in = { - .rcx = gpa, + .rcx = gpa | level, .rdx = tdr, .r8 = hpa, }; - tdx_clflush_page(hpa, PG_LEVEL_4K); + tdx_clflush_page(hpa, tdx_sept_level_to_pg_level(level)); return tdx_seamcall_sept(TDH_MEM_PAGE_AUG, &in, out); } -- 2.25.1