Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp309009rwb; Tue, 25 Jul 2023 16:27:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlGGSMPGKtN3HwsZV8lXddKvfOsHqNeEjlF5N/RGLdDSJdWod1oe95PH66u0uVba3i4HOWcl X-Received: by 2002:a17:906:10a:b0:998:de72:4c8c with SMTP id 10-20020a170906010a00b00998de724c8cmr496508eje.35.1690327661627; Tue, 25 Jul 2023 16:27:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690327661; cv=none; d=google.com; s=arc-20160816; b=rkvj7KdDu0TO9xn1pJHqfkfgvN7CMxfwL9R61Y+pJD2JXjkt02u+gks08q/8rYIp0H BX2PotyTthnRigVghdPHLkU/URnHmvritxUX1XBAJW1rf8Ajud3RdV/CdZf6xTmGedI4 SXYQUUwmN3yxFX/ixuzGpOzGOqjVPO2It0vQF2ZXBN2l4tkmZV/8BXWwljm3bFPPRa7Y Tlxp5mP8q8PCCTQb8NF5uXDIN3Spi+An2QoVExzqb0o8He7221nPS8OCAB9HKOlI0Nz8 egOhPV87IbD5/plA4WefP/wa6/x1mDHAuNnk22q6PEQ7MGkBwc0XdQX3/wBWr82zvONu PC0Q== 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=AQGBcUvpsKt0s9F9pu9mYyjWlv0AOcnEGDdACWvlOpw=; fh=E1bxw31VVcEBr76WIqXfdV5vG/YqvWMYjFMgvHDq2Zc=; b=JAFojpn677/rliV+gotCc8uYlYjXoJFhx0Rfhvu8yhh/sfgqhb7PQhBuuo2K3VFXfw g5+ayfbReTo/yCXQ2uy2PkyuO1mawqRfJVqDroMYo2ViAaPsRb1kOR2+PrFqUuB2qxpj EZbnIyoA1/1fJWc1kfmUMs5qAy3JIFyvIKDjXGpi+tJMdn0mgqfMrD1LUeaabryZyRrt ICB/oVfFN6XwZ1KsIjb34WR5X6wrC90wvPdg7owSEitBsJ9IFSeZZA+R1adJTYCPJeod uBB5slQiFd1x/RBTPe/Sh3kcYBBbj/inSBzXTpBDAeIo7FksmC330tgJQzVFV5ipjPfG f8kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VICMcIlV; 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 q17-20020a170906a09100b0098e1263aadbsi8277694ejy.100.2023.07.25.16.27.16; Tue, 25 Jul 2023 16:27:41 -0700 (PDT) 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=VICMcIlV; 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 S232921AbjGYWgH (ORCPT + 99 others); Tue, 25 Jul 2023 18:36:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231776AbjGYWft (ORCPT ); Tue, 25 Jul 2023 18:35:49 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EEC12724; Tue, 25 Jul 2023 15:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690324154; x=1721860154; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X+p12lCWArQXSZdWvADFh/bi0AKS5YpYYgheHTnDG/w=; b=VICMcIlVPZqmDA6v87/Q+sRMLfcamwXBBeOopv6+URFzt4w0mF9guNJ4 invUEOg47vNYnI+JirBqANDr6pYOGChq+px4LRHJ1Y9p2tfPnGRHFzobQ L+rgP5JqPLpYQ4T46+CrAYaMPO6BR18D1EeiLCjBxOVVBwbndIDd0rzj2 q8SrD3pSGBafpZhp/eeMFCRrBHn84uHcRX2+bQnw/m7EwOgrN5+pLJxqd NxBEAyccIjE+58oth883PlM4YdB+sZITPtcX+wYTFvOndPZJIy8ilZZ1N 1r6wZ8h36eIdXSa+Dg/RBSDcziru29Sxv7pUb6RGKF6I7VNADPduTGc55 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="371467101" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="371467101" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:24:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="972855786" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="972855786" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:24:08 -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 v4 02/16] KVM: TDX: Pass page level to cache flush before TDX SEAMCALL Date: Tue, 25 Jul 2023 15:23:48 -0700 Message-Id: <5b5db3ced13d94f129cb14e484d7873898efbfc5.1690323516.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=-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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 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 c7819abd61b0..3d0968c98437 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 @@ -46,6 +47,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_output *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 @@ -78,21 +84,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_output *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_output *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); } @@ -104,21 +110,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_output *out) { - clflush_cache_range(__va(hpa), PAGE_SIZE); + tdx_clflush_page(hpa, PG_LEVEL_4K); return tdx_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, struct tdx_module_output *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); } @@ -135,13 +141,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