Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1815033rwb; Thu, 8 Dec 2022 15:59:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf7V34Zk59eDJkTRztjz6bC/k2X2OOa/k6xb+r5ulM5IJu2bBPPvmJhB8l29XqHH1GW3aWas X-Received: by 2002:a17:902:e8d7:b0:189:413a:9d76 with SMTP id v23-20020a170902e8d700b00189413a9d76mr3452744plg.47.1670543956373; Thu, 08 Dec 2022 15:59:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670543956; cv=none; d=google.com; s=arc-20160816; b=R9QUgWKPwwqLXpMnWMmGDbbM7oXxxqwYocC/hdi8wetnmeYIftZUrPyVBUdzq92CPv Q89sVETEZSaVCcNl7pW0gJeumf9zpjw6/WJlhoNZv3LichYHaNxlLWb0c0BEAdWK6eA0 mpPt3NVv2utMsLbvdH1D8QOwR5X3O7gr8+BA4fMaVZqjsRVwFGQRt5H+ICTt6ODZYUe0 8S3P6ZaLthkBjVGRuePQcAjq37DkXasSpOMFe7XHnV2LNzIxbHBDGNVTb82qoTPnh14/ EsrtxXjT89TznDnWK7+SDkCeia6+awEL/Ezlz+D+4EyKNSTzuCmdcw+W+ZAqfgV4yDS6 Yt+A== 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=VBZzyTn/dDvXckd52z7AQ9FZdcOeOuYj11CbfQm6pj8=; b=O8w9E6s/jajNxrl1Uq9I/VmbiAFHkX1lN1wvMSG6XHmGztXGkzG/XM2ib4kdO4IJMI BWw3MKAspaWOYvL0G93ZOFUVVxCeb3Y+rKpWVdLc72BMwTjht0+tVHtdQ8wmWvj/Q0od Kw9yaX8eWdL/zx9Y5EFDkRP02eOQCd4QCs01X0rJOznvu7Aj0eqEyKtkyng7Ju2mmL56 Jx0JAIYz1XA4o9DipWLC5A18cMWY5UAR9kePFywHLpUwRUINNtJx9DnC44JUUVFAenKM ojS3xyxkHUV6/5Ix6oKGhHfwjyWdaJjDkKTFpx0/cSAe/fjVxYG7xPIPSAMx1Q3kEilm brCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OJFsnkFc; 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 jb14-20020a170903258e00b0018922404e22si22730415plb.474.2022.12.08.15.59.05; Thu, 08 Dec 2022 15:59:16 -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=OJFsnkFc; 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 S230132AbiLHXgD (ORCPT + 73 others); Thu, 8 Dec 2022 18:36:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbiLHXfy (ORCPT ); Thu, 8 Dec 2022 18:35:54 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E50E6BC9E; Thu, 8 Dec 2022 15:35:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670542553; x=1702078553; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hqWWs96g8j8J+o2BvB4eR8w2w9BH0DQPRuS3KFwmOI0=; b=OJFsnkFcBEWPqqI9NfmohL47IGuhyowHDLgLDBd2cb9RvLBciEEypIOO wx0ahMX2Wl6CGukf5R229FizILWDiwoIzVCo7kIrSwJ8DIeGS8OklDfNy BUUNp2kEHrUNxCpf1eB3Vc//1FRuupwPUXd2BPLNiqHtj9dly/XAhpOBa xJpQsYnBKMZu2Ya42fkTVEuKsr/A3VD+C1nIYXLSwvra8V+n2hEojcBTC vWylfUCXkc/AO59/PBuEl1qDRo4UkPRLBmRhRmferLtM64GXlGd6rWRX4 /QRS+2JFtlfvslpNthEEBuMdoK/F/uhyHmqIcYofhK1lcRbBydWFz3NZq A==; X-IronPort-AV: E=McAfee;i="6500,9779,10555"; a="403586481" X-IronPort-AV: E=Sophos;i="5.96,228,1665471600"; d="scan'208";a="403586481" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2022 15:35:52 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10555"; a="677950888" X-IronPort-AV: E=Sophos;i="5.96,228,1665471600"; d="scan'208";a="677950888" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2022 15:35:52 -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 , Sean Christopherson , David Matlack Subject: [RFC PATCH v2 02/15] KVM: TDX: Pass page level to cache flush before TDX SEAMCALL Date: Thu, 8 Dec 2022 15:35:37 -0800 Message-Id: <6134a82d4a78d5a7aee4d684d7d4dab34f7f1bcf.1670541736.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 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 86330d0e4b22..4db983b1dc94 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 @@ -18,6 +19,11 @@ void pr_tdx_error(u64 op, u64 error_code, const struct tdx_module_output *out); +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 @@ -50,21 +56,21 @@ static inline u64 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 __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 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 seamcall_sept(TDH_MEM_SEPT_ADD, gpa | level, tdr, page, 0, out); } @@ -76,21 +82,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 __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 __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 seamcall_sept(TDH_MEM_PAGE_AUG, gpa, tdr, hpa, 0, out); } @@ -107,13 +113,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 __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 __seamcall(TDH_VP_CREATE, tdvpr, tdr, 0, 0, NULL); } -- 2.25.1