Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2622118rdg; Mon, 16 Oct 2023 09:38:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMMdz3Zulq/wyVEGrIKEw5aFqTofQGgu/n1cY9eVR4CV9PIMANoSC92NrxVhavqx+Inu55 X-Received: by 2002:a05:6358:290b:b0:134:ded4:294 with SMTP id y11-20020a056358290b00b00134ded40294mr42681651rwb.17.1697474307682; Mon, 16 Oct 2023 09:38:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697474307; cv=none; d=google.com; s=arc-20160816; b=sg84emuf/CaoZgMN3SJtfI6NVHJU/9D5qKrOZSMgUAhf3zQY0CKuVo+sYIG+XBO7HM vtWDPUiF2DcQp4Tg0ybf/RzLAgpmB5Ws4n+YRjJIh3+E1fFIvCIfaf576goZPk38kbrO NjEij4/sTkQ/HPfHbl7hAi+x3Lw+AEGOUDXj4DwhjNIWWaLaj8Nej8gMKcfMdMCoJhK2 wXVdKBLPQcRjcrSQtTukxckEal9ZEYmXDUVdqcr09tSW5HuwTp+EQvzsX1aDG3i2iCI6 4wr+6rEWhfLjIqG/hwcjZPZfESrljJith2KAQ2QzHb5jl3c7EkRTxc2tzluwAcJpmOY/ yYAw== 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=h49M8s476XQIBgad+BG/2+wBCpSDv8mHBWa3wAMBbxI=; fh=4OEEkzWp/q+dELKxtVy/jK+pEs8VYY1pIiC6FIGYmPg=; b=CqeJgQEMwbBaHUQs/ZeRnG+SP0bXYj0a2DX3HB22WMpldAe7sEN3E0HMtPAE0IsR/S Qf+0ACgOQ4DdO6fY+z3HdoBfdISe9qh11xVwEtw6BOi38VD2Hso+xfcrRPqziJ33hMjb 2wQN476QbCPFl7g54EHvHgfRGVrf2NT9nBF67ggPFaLddRW2preRTqB1x2/0BhoPrEvx qEpVAc6PDcgBvvXMmnobS5Ikf1yuoXTqA+jfqgYll2ppSaBoP/27gO98vo6T8Y8meso6 dKKmtYGu/1BN/3Y+gNcrCy/HJWQ9khX6xrcJfqh0cOa5rVitac5Pa59jX1kAEPJCgQmX PmKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=f8Ol1Nix; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bv2-20020a632e02000000b005aca8ed90c3si7137750pgb.271.2023.10.16.09.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:38:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=f8Ol1Nix; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 7DEF0802C691; Mon, 16 Oct 2023 09:38:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234331AbjJPQiT (ORCPT + 99 others); Mon, 16 Oct 2023 12:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234397AbjJPQgL (ORCPT ); Mon, 16 Oct 2023 12:36:11 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9417A7ECB; Mon, 16 Oct 2023 09:23:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473387; x=1729009387; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cjMq75q7UmGnUAjIbVD4r7kBUT01kp6Ux/qm7MjljOM=; b=f8Ol1NixoFF5ZW0kzfza6yHdfqiJPjZmTWAm9mhwpccBaawoqmjOefP/ 9VXBbJ5h9Tb+abbZQ6WdOvhDsRTLcuywVUOC7Xj4gZ/XEgBYyZO3UkwxV SUMewkpqWejHtOK5+KW97H4cAxHBTF7xTrAQGEEuY3PpD/vp+dsUtf/qW nfGH35JYTjjT6mNquoHN+/crXZsMZc6OSoykLYp3Dt/pTvnhgTVP3iha3 SLdiB9gLLMbZm11qf+1ZkJS1NdlyXtinoUJ7UFpbWQdu3kXCPRMJJfREp atEC6mgyOPSB1WxXuGMMAdxpqnqLReRdMh5sQNrWecPLr5hJzi/n37OAn w==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="365826068" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="365826068" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:15:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="1087126126" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1087126126" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:15:38 -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, Sean Christopherson Subject: [PATCH v16 037/116] KVM: x86/mmu: Allow per-VM override of the TDP max page level Date: Mon, 16 Oct 2023 09:13:49 -0700 Message-Id: <73d708054372d613a9b5c7d17faae0af5ff6a101.1697471314.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=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:38:26 -0700 (PDT) From: Sean Christopherson TDX requires special handling to support large private page. For simplicity, only support 4K page for TD guest for now. Add per-VM maximum page level support to support different maximum page sizes for TD guest and conventional VMX guest. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata Acked-by: Kai Huang --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/mmu/mmu.c | 1 + arch/x86/kvm/mmu/mmu_internal.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index a2fd25fb2f9c..3970473d1807 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1253,6 +1253,7 @@ struct kvm_arch { unsigned long n_requested_mmu_pages; unsigned long n_max_mmu_pages; unsigned int indirect_shadow_pages; + int tdp_max_page_level; u8 mmu_valid_gen; struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES]; struct list_head active_mmu_pages; diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 1e3ddf2e7dbf..eee5a46f5ce3 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -6301,6 +6301,7 @@ int kvm_mmu_init_vm(struct kvm *kvm) kvm->arch.split_desc_cache.kmem_cache = pte_list_desc_cache; kvm->arch.split_desc_cache.gfp_zero = __GFP_ZERO; + kvm->arch.tdp_max_page_level = KVM_MAX_HUGEPAGE_LEVEL; return 0; } diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index 83dbe8245ebf..8de1192b1cca 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -296,7 +296,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, .nx_huge_page_workaround_enabled = is_nx_huge_page_enabled(vcpu->kvm), - .max_level = KVM_MAX_HUGEPAGE_LEVEL, + .max_level = vcpu->kvm->arch.tdp_max_page_level, .req_level = PG_LEVEL_4K, .goal_level = PG_LEVEL_4K, }; -- 2.25.1