Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2628920rdg; Mon, 16 Oct 2023 09:50:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGASZ73C+7gGUWjYZgD0wWncwFp5ziTPpw4FIwiRKyT9EvbmQRUGVc4xKdDepXFfY0pigDi X-Received: by 2002:a17:902:9b8e:b0:1c6:2780:3adc with SMTP id y14-20020a1709029b8e00b001c627803adcmr26603485plp.24.1697475058937; Mon, 16 Oct 2023 09:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697475058; cv=none; d=google.com; s=arc-20160816; b=c6ftnpyuh31eL2uAIdY4bP8Nc7uG6oDK6UYJRR9LuYak35nF4MjwzA/RgajbC/T9od zBsfwAQ6+pJlNjUDdrBITu+AViTF12L2Tq4U7jLGeb4+xpbzu79wlX6VGQkGGPNqkONB azkbGeJuj5ckYW3oogVTC7Hotvjq9u34YZOh37O3fJQoVhMUYQqKnpGFN+Y4iltwzOja fMEFtxFl37EaXY86pGasAnoyGpCAWMc2JIZzei0F6uBZJbuy6q0Pfp0bOIrUmHus2i9e dIUlPmfe8Zu5bhcrwCCIb3Nc5zOOvjtB2mT1QWwb4aSibwO1K7m7BvhIwNd3NOrJP9Tf vt9w== 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=8aWN9oaTYxtNejX6+1h4IJ3mqHovH+K9EyR95ZZrPVY=; fh=PgPONM/W1VtmLglMgmd5Kb29Va4E/NEsDAvR3ZLGW2Y=; b=UIG2ycOq01jtXXtGc8CxZSQ44YalODCAWuszZoKrQYtA9pln7aLqiuPqzKXz6K8a96 TpS2tpLQKF5Qu6I/ZIXD5W3hqA6W9qTiyOek7375y68cIKlvCcwyUa/gYO5UW2pihJho jfnEUU6O/K9lFkFYsRSiSyZ/lQElBhkyL3RdaJyLAK1058kTWmsSL8emrv6fSkexxeaZ SEEqju5pv7owJpoj4hlaD7zfDWi3CULUkadA6hanxErsbzVpphmSZ2XP6dn0cXUauc1U zoftiEIPsFQ8VWM9co0u7uOtxIR/RxyrSEKrQCz5PpO1dZ4+9QhjXCrZ3XT5nsPyKHVP Dr2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jBLJezOa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id s5-20020a170902988500b001c60d1de681si10481111plp.108.2023.10.16.09.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:50:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jBLJezOa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id D48E18083ACA; Mon, 16 Oct 2023 09:50:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233854AbjJPQtx (ORCPT + 99 others); Mon, 16 Oct 2023 12:49:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234584AbjJPQhv (ORCPT ); Mon, 16 Oct 2023 12:37:51 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C37EA7EF8; Mon, 16 Oct 2023 09:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473391; x=1729009391; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wMYbVvjqR+ZSSbdZopCJtYPSlf9Ohr0kM34J0EtH7+E=; b=jBLJezOa/IOmSlSIQepous1W2qiwz07ZIvrb1Goxft0Ji/lbkMpILkwq /RKZs/R6xckEfVGM9aeDrAV+XTJS+VY7WE6YWNIRAhDO0ZIRjaj3vP+pg bT62FPgOHYzQJbMidDWt33hU71dkcV60DkTIRcFLZ63H3/mDf6GIYs8c5 /wzMPmvSVhFBO3z1ekE76zyEHfXcTbl/7pPnKR3tWPAVW9Hum+D3pcb5e nsOHd7jQF1lmJRpK+1D2HKMwX+W9gEE4SB1hHEx675kBT6MMWQKkhZO5Y kI3j5/W+LxR2gD25gKo9CQJSfQVrUJcxDCz/IS7LDYdvuNzQkXZWMiF9K g==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="471793114" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="471793114" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:21:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="899569215" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="899569215" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:19:12 -0700 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 , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Xiaoyao Li Subject: [RFC PATCH v5 02/16] KVM: TDX: Pass page level to cache flush before TDX SEAMCALL Date: Mon, 16 Oct 2023 09:20:53 -0700 Message-Id: <4c5c2e204b9369d17988a988871b86c7c753cb7b.1697473009.git.isaku.yamahata@intel.com> 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=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:50:03 -0700 (PDT) From: Xiaoyao Li tdh_mem_page_aug() will support 2MB large page in the near future. Cache flush also needs to be 2MB instead of 4KB in such cases. Introduce a helper function to flush cache with page size info in preparation for large pages. Signed-off-by: Xiaoyao Li Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/tdx_ops.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/vmx/tdx_ops.h b/arch/x86/kvm/vmx/tdx_ops.h index c716e54be66a..c9de1b48a022 100644 --- a/arch/x86/kvm/vmx/tdx_ops.h +++ b/arch/x86/kvm/vmx/tdx_ops.h @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -62,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 void tdx_clflush_page(hpa_t addr, enum pg_level level) +{ + clflush_cache_range(__va(addr), KVM_HPAGE_SIZE(level)); +} + /* * TDX module acquires its internal lock for resources. It doesn't spin to get * locks because of its restrictions of allowed execution time. Instead, it @@ -94,21 +100,21 @@ static inline u64 tdx_seamcall_sept(u64 op, u64 rcx, u64 rdx, u64 r8, u64 r9, static inline u64 tdh_mng_addcx(hpa_t tdr, hpa_t addr) { - clflush_cache_range(__va(addr), PAGE_SIZE); + tdx_clflush_page(addr, PG_LEVEL_4K); 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) { - clflush_cache_range(__va(hpa), PAGE_SIZE); + tdx_clflush_page(hpa, PG_LEVEL_4K); return tdx_seamcall_sept(TDH_MEM_PAGE_ADD, gpa, tdr, hpa, source, out); } static inline u64 tdh_mem_sept_add(hpa_t tdr, gpa_t gpa, int level, hpa_t page, struct tdx_module_args *out) { - clflush_cache_range(__va(page), PAGE_SIZE); + tdx_clflush_page(page, PG_LEVEL_4K); return tdx_seamcall_sept(TDH_MEM_SEPT_ADD, gpa | level, tdr, page, 0, out); } @@ -126,21 +132,21 @@ static inline u64 tdh_mem_sept_remove(hpa_t tdr, gpa_t gpa, int level, static inline u64 tdh_vp_addcx(hpa_t tdvpr, hpa_t addr) { - clflush_cache_range(__va(addr), PAGE_SIZE); + tdx_clflush_page(addr, PG_LEVEL_4K); return tdx_seamcall(TDH_VP_ADDCX, addr, tdvpr, 0, 0, NULL); } static inline u64 tdh_mem_page_relocate(hpa_t tdr, gpa_t gpa, hpa_t hpa, struct tdx_module_args *out) { - clflush_cache_range(__va(hpa), PAGE_SIZE); + tdx_clflush_page(hpa, PG_LEVEL_4K); 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, struct tdx_module_args *out) { - clflush_cache_range(__va(hpa), PAGE_SIZE); + tdx_clflush_page(hpa, PG_LEVEL_4K); return tdx_seamcall_sept(TDH_MEM_PAGE_AUG, gpa, tdr, hpa, 0, out); } @@ -157,13 +163,13 @@ static inline u64 tdh_mng_key_config(hpa_t tdr) static inline u64 tdh_mng_create(hpa_t tdr, int hkid) { - clflush_cache_range(__va(tdr), PAGE_SIZE); + tdx_clflush_page(tdr, PG_LEVEL_4K); return tdx_seamcall(TDH_MNG_CREATE, tdr, hkid, 0, 0, NULL); } static inline u64 tdh_vp_create(hpa_t tdr, hpa_t tdvpr) { - clflush_cache_range(__va(tdvpr), PAGE_SIZE); + tdx_clflush_page(tdvpr, PG_LEVEL_4K); return tdx_seamcall(TDH_VP_CREATE, tdvpr, tdr, 0, 0, NULL); } -- 2.25.1