Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4124703rwb; Sun, 7 Aug 2022 15:46:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR6PMIcdKdY00gK4d5VJc+JI7ILb/vIklogjX/TJtORWw5UlU66o2gh0mJLMTCfrVno8y2Jx X-Received: by 2002:a17:903:249:b0:16b:9cf3:596e with SMTP id j9-20020a170903024900b0016b9cf3596emr15709577plh.60.1659912376672; Sun, 07 Aug 2022 15:46:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659912376; cv=none; d=google.com; s=arc-20160816; b=Gt5RBf5/sSgSxjMkaMQwr4y93p1KcR7f1QETeyBCV7fsLt9vfmkqJvBKu24r45oB2c a+KOEBHd1hXs938ulCPk8N8uiaQcbHVrlIEW4bcnwR/D7D/aOMUeBlh8IJiEU+Nq2zE7 hWu2FpsfMa27h5g2xHm2pPg/LIoWHm2Key5pQBngFo6Y68vWNZ0TdkrKQmW0cLhyx5X6 cogPiMlbBoqWkFe1YYz2dY5S5f8DnWPcCQnJettQGxf1QRmrtBgohJlwJ/BEcegI1n21 pM+LdJK8oNw/emb3zt9s+VxNONcI3ESjZTAl1XTgfUUFjckkRao3Zj1zHU0CnP93h3yq 4mog== 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=OIomKfulBlGG42Xa1KjkofEVccork+Wt7NPEIdvYAZ8=; b=TE+uYJ4EDEFmFQLDdHp6mJ2YtijsK06BH/QvRV0sd+aw2OGQKtKnE1UBFAKw8MYsNB sJz7cRN3P8ZE/RfEk5I3UV0noJrGP3AxEq79RyxePEfVMantJY7AXtirWj/liXztm8Ai vjufYMMd2pVBdpQqs6NMIMzKYq3jWgf3NxjD5Ut0+gH4DQmRwjOx79Rl81vzmVUytpW6 Oaz8hvSyS45M/0VudDnz62s/YoiuI9lIl1PwTy04FIDmQ6IPJ9WkI8cCM8YU5omO6y8c zIrXmwzMaCbSLTTCkhkxtckc9FnUf432r5Ild8JMzwIydQk9wiqtS36xPE0aYbV9JAuY OxpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="dD/E8qkJ"; 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 m12-20020a170902f64c00b0016d4e5ca5fbsi3982730plg.308.2022.08.07.15.46.03; Sun, 07 Aug 2022 15:46:16 -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="dD/E8qkJ"; 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 S242329AbiHGWcD (ORCPT + 99 others); Sun, 7 Aug 2022 18:32:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242175AbiHGWbi (ORCPT ); Sun, 7 Aug 2022 18:31:38 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB7C01835A; Sun, 7 Aug 2022 15:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659910729; x=1691446729; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZBCDb+I6x0GETVViSJuThLetZlFQXcMtaaKhL4WaELI=; b=dD/E8qkJfHfiAhlvVdrDnqTk/pnpjV0KaQK2d5rBDrGWxhkLUI5BRnES xumgZiXZNe9Wri6swG82bod6Lp5sgDifpgkv0IF4IBmdTK/HAhB5CaB+t RJIY3IEnxXf8riLX6pP1Ei9mvuQ2/taTNmBxltXM5uxJ8BlTCZExfhm6s FWx9AuWBPei75TzEGFSe4QArbHgn9nZ9GRzsJX2jiXz5jC/mF4W1rmsLN f24TGVYarNlNNKc2rOYgDVf7MJhV1eWrT7HacyuVzh6NHMeCuQocomXDz mBXl4KHS4BWrptFFn3N+O58/ccqaDwVAmsU98WrZORnCkiVyO5Bx+ptEk A==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="270852831" X-IronPort-AV: E=Sophos;i="5.93,221,1654585200"; d="scan'208";a="270852831" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:18:48 -0700 X-IronPort-AV: E=Sophos;i="5.93,221,1654585200"; d="scan'208";a="632642305" 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; 07 Aug 2022 15:18:48 -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 Subject: [RFC PATCH 03/13] KVM: TDX: Pass page level to cache flush before TDX SEAMCALL Date: Sun, 7 Aug 2022 15:18:36 -0700 Message-Id: <01bfd080f85afffcffeba96692be726294faa18d.1659854957.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=-5.0 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 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 a50bc1445cc2..9accf2fe04ae 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)); +} + /* * Although seamcal_lock protects seamcall to avoid contention inside the TDX * module, it doesn't protect TDH.VP.ENTER. With zero-step attack mitigation, @@ -40,21 +46,21 @@ static inline u64 seamcall_sept_retry(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_retry(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_retry(TDH_MEM_SEPT_ADD, gpa | level, tdr, page, 0, out); } @@ -67,21 +73,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_retry(TDH_MEM_PAGE_AUG, gpa, tdr, hpa, 0, out); } @@ -99,13 +105,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