Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2243415pxm; Fri, 4 Mar 2022 12:10:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJwj9dkvyMTjtfqZwnZaJ62GBRU+jPCfGp4zgnczaELEjGI+gyLK3+gk9bbpbas36JNxNfK+ X-Received: by 2002:a05:6402:22a3:b0:415:ce95:7eb8 with SMTP id cx3-20020a05640222a300b00415ce957eb8mr211531edb.388.1646424650931; Fri, 04 Mar 2022 12:10:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646424650; cv=none; d=google.com; s=arc-20160816; b=r7CIxBNgvZQHLZkLQlAg6BtrYaNyVAES17kv5fGPhxWc6JlTrxUvB4soTuKgxieNhS UdX+JAlJSYfoeLQwXnO7bwbJK+WHJ8ad0IThDODWloMyisum+EIa/s9NPQpoXm9CXiiI Vz1wUxzZb33SrF0qUPYZElz+D1Q1Yw4tMM/wg2zFf7ZL2l7gw4QREFxWyQurYgpYGCNg qJTS5f2yCEpK064XKy0aev0SckiB2kpc8lQEiKy5+2QMoWnm8VLbAkz1WQDvH/IiFi1X E35lHBzzI4CozAY7pKS0yPbKEfWSqCJNdwVJEQtHrvAjgYaIDjnFz14/PiMxZ7Dk7Dnq PXXQ== 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=fmbo+1R+genIYFgusG6JhpkPealtn2vOdarUe0/WtrM=; b=peR7fJ5F75It30tIuahjue6I/0eOtnE5sJSyn7OWYy4oV4lNHzYZ3bY985Os78/KHh 7VL4za+H8pykPqW02GCPfrou7SlyYCTy2V6AYgcJhrji4BnINCb3g0XMIBB/rg6ourzY eMnDICDif0iKzufen82gEN0v9iOvKd94HRyHY21xx2PGt69xtH0+O5fkd/g+ENuhZ4hX NlSihJ7ImCoCxjfLBqOYYpMvNUt8mD5DON8zkxPdEHuxlowUzPsaE/3vJJAWrhMZ/aY+ rN9h2YfHa5+b7xfPSmo/vVZhp5osrlqgZaOwgWTB7aPvslNJAIGDymQfmloXiQjXXE3c xxTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MI62oF7i; 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 el6-20020a056402360600b0041614eca4e2si852742edb.42.2022.03.04.12.10.21; Fri, 04 Mar 2022 12:10:50 -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=MI62oF7i; 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 S230365AbiCDUKY (ORCPT + 99 others); Fri, 4 Mar 2022 15:10:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230413AbiCDUHm (ORCPT ); Fri, 4 Mar 2022 15:07:42 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B1B0276EEE; Fri, 4 Mar 2022 12:02:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646424130; x=1677960130; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WHzoUnjROzTRUfJ+1U+xlOj5PEkMbeG0NcodTuSWA0U=; b=MI62oF7itDBeg23veum6A25PdW4O/2guxqBuxJrazV1Tjz4sKftqOB50 a7ZFzMpdnR/Og8iCIO8s2mrJWv1qffmVs7oxtc1Mo4NJg3Y8BZPRXDPOo UB/2u+a3Rh3sFNZOEU31PBJMUW6579HWgUUySo4L4RAS3jiY2Yi5y7JDe ZnyZihKFAiakZ6ZmrrN6kUEDo8dHt2RD/vQPzlScg5gXiR0z9ZRuCr7hM JdEjxoS6hYijAN5/kv1Qku1FsCbNeVi/F9EUkCKBY6PzDunNY6spXMtwY T5HHN2RDC3tgtuT8XTnvlM77EjpLsl8D5vC4vFs/+cxoI+GtfjlC0XMTj Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10276"; a="253983467" X-IronPort-AV: E=Sophos;i="5.90,156,1643702400"; d="scan'208";a="253983467" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2022 11:50:20 -0800 X-IronPort-AV: E=Sophos;i="5.90,156,1643702400"; d="scan'208";a="552344315" 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; 04 Mar 2022 11:50:20 -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 , Jim Mattson , erdemaktas@google.com, Connor Kuehl , Sean Christopherson Subject: [RFC PATCH v5 038/104] KVM: x86/mmu: Allow per-VM override of the TDP max page level Date: Fri, 4 Mar 2022 11:48:54 -0800 Message-Id: <5cc4b1c90d929b7f4f9829a42c0b63b52af0c1ed.1646422845.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.8 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: Sean Christopherson In the existing x86 KVM MMU code, there is already max_level member in struct kvm_page_fault with KVM_MAX_HUGEPAGE_LEVEL initial value. The KVM page fault handler denies page size larger than max_level. Add per-VM member to indicate the allowed maximum page size with KVM_MAX_HUGEPAGE_LEVEL as default value and initialize max_level in struct kvm_page_fault with it. For the guest TD, the set per-VM value for allows maximum page size to 4K page size. Then only allowed page size is 4K. It means large page is disabled. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/mmu.h | 2 +- arch/x86/kvm/mmu/mmu.c | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index d8b78d6abc10..d33d79f2af2d 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1053,6 +1053,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.h b/arch/x86/kvm/mmu.h index 0ae91b8b25df..650989c37f2e 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -192,7 +192,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, .is_tdp = likely(vcpu->arch.mmu->page_fault == kvm_tdp_page_fault), .nx_huge_page_workaround_enabled = is_nx_huge_page_enabled(), - .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, }; diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index a474f2e76d78..e9212394a530 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5782,6 +5782,8 @@ void kvm_mmu_init_vm(struct kvm *kvm) node->track_write = kvm_mmu_pte_write; node->track_flush_slot = kvm_mmu_invalidate_zap_pages_in_memslot; kvm_page_track_register_notifier(kvm, node); + + kvm->arch.tdp_max_page_level = KVM_MAX_HUGEPAGE_LEVEL; } void kvm_mmu_uninit_vm(struct kvm *kvm) -- 2.25.1