Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp879535iog; Fri, 24 Jun 2022 16:58:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sMg8/5rmrIkeslwz1buhPVWFEW79OUJ2CyzHHOj6UjXk7yo80HLr2Yz5fEXiix6RqsflqB X-Received: by 2002:a17:907:8c05:b0:726:2a09:c951 with SMTP id ta5-20020a1709078c0500b007262a09c951mr1441118ejc.143.1656115125849; Fri, 24 Jun 2022 16:58:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656115125; cv=none; d=google.com; s=arc-20160816; b=LugoQtujrBqdbjHwaIllVvRkdbAEV5HlMjiLBosHbhxz4kF8wrHNQ44AFMleuPaoB8 yd13pQT9rb11/rA5X/cEoq4Nhf0tvsXUPHJ9G0nnfwNHUhkcjuH9kEjhifyH7knBmrt5 e94bqzPi2BUZHFj4TBcYz/Dd7OcZYWbsJsYP/+k0SIas1g92LUwOBT/QEAPhRpMkdhd3 KRqNB4Mihv4poPYph4VtQAKOs0VLIhzGG1N64QGD9v/fihgSyQaM8P9di5cogIjJcvvk DE6DeQU8yEgpoVUfPvK3P9wWqVbLciCQNHH7IjBjXU9JxUY899jjTay+tMUMhyGQnWhF T+jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=+2sBtkyKsLNu0zC2SazGiR7uBsQuxEV5revLo+Poakg=; b=HCjx1PzOqcdzh/dXs/18QWFLADuzQU0EWFCjeHyhDsp7slPGhKOUP6o8v52ksOjeuh u2UWDhkVbjiHeBEOEAgRu8v1EZYF/DL2aYaKg7NNef8FkfsPTlWxAMuw6GjqOzfwEszx ZydEJEQ/dE2pbyKSUpwRtZhlnInxI2fZWShWY2jiaZ/77I9qDmgiNAwwSFWSCpzYh5Ja 2dQC9JM5mSJ0YT+auhYoHHF1WkOmNlVpm9GifJk5Nw+N0IFE6IyQ2pLU3QY1iTm754bV 0P3XTmKePHrTN8d7yz4pJuIYbwWE00B3PfSbZmhCpf/P5FIdBDRIWcZM86ZB7Vr/nHKn GAcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qhERotaB; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w16-20020a1709061f1000b0070f153ebd89si3914256ejj.7.2022.06.24.16.58.20; Fri, 24 Jun 2022 16:58:45 -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=@google.com header.s=20210112 header.b=qhERotaB; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231561AbiFXX2D (ORCPT + 99 others); Fri, 24 Jun 2022 19:28:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231455AbiFXX1p (ORCPT ); Fri, 24 Jun 2022 19:27:45 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E79728858B for ; Fri, 24 Jun 2022 16:27:44 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id u13-20020a170902e5cd00b0016a53274671so1957701plf.15 for ; Fri, 24 Jun 2022 16:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=+2sBtkyKsLNu0zC2SazGiR7uBsQuxEV5revLo+Poakg=; b=qhERotaBVV5h1AOQXBXcOi/awndAEk2PfCFQzLEDw/FsiKdvkeHJnm936S/KUZ6J/F ixxFjwLTALWsLQe/b4gVfrvN1BrB1KMsqCaZMIDtOFAkV6dqmNYAUBGuH8zD3l2JAJzt w+2JqB05tBDTkcJEWVxrRdQ/XuzEDLS2442hbPVyvjdnRKlUxpFqupA5daLunh8U+XzX KUiAJbiZ3M5z2fF7hs74dEDzlXcWCJBi64FpnSPLWGtccipLZqN96ojcxuhshfeOvEAX 4rZTknMfIOZiegutb14+UBbfTYEzQd+Ba+yQJdCZasV5eqS/h3vu5UIePbpjxk0o7IjT ji7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=+2sBtkyKsLNu0zC2SazGiR7uBsQuxEV5revLo+Poakg=; b=WMJRCDZz23Tj3o4rZqjqQ39b+xR+owbqgQlUbPxm9SA3EyEPI012LaRRl5/mjhtTBs zjDYhVdyRgWujKyIjMn9IBOTiHQulLjGxKUGQ9yyyo7N2EhpnxKzq+z3wVkHigO7WbK4 nAJK2ijHQAWsBXYwYdtyBc/fvfxP7ktTdMRPXHs/K/gG5Tx6EnAYgAUeWafQqH34mG9p zmanQ0wz3Xh7T2Q6P+kFip9jc/FpuhfT/020RApPqQ709mrmHumUWCMx+WyuiEQsJiEn aYO6y7J5B0VKlUJEVp6Vy3Fjp1JMK2pWX7odgCL7bUf8Yqsj+nIB6qqeTS2n3jCQCAUj 882g== X-Gm-Message-State: AJIora+2EJfQf9OuPFYXtBW25h70hJrZJHXu0pUEqL1NC3Qjr0h/0SHK sxjGCJ9P9nnkW7/gYPWcu57XQvwLLwY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:428c:b0:1ec:b866:c38e with SMTP id p12-20020a17090a428c00b001ecb866c38emr6751357pjg.117.1656113264499; Fri, 24 Jun 2022 16:27:44 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 24 Jun 2022 23:27:35 +0000 In-Reply-To: <20220624232735.3090056-1-seanjc@google.com> Message-Id: <20220624232735.3090056-5-seanjc@google.com> Mime-Version: 1.0 References: <20220624232735.3090056-1-seanjc@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH 4/4] KVM: x86/mmu: Topup pte_list_desc cache iff VM is using rmaps From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 Topup the per-vCPU pte_list_desc caches if and only if the VM is using rmaps, i.e. KVM is not using the TDP MMU or KVM is shadowing a nested TDP MMU. This avoids wasting 1280 bytes per vCPU when KVM is using the TDP MMU and L1 is not utilizing nested TDP. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 2db328d28b7b..fcbdd780075f 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -646,11 +646,13 @@ static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu, bool maybe_indirect) { int r; - /* 1 rmap, 1 parent PTE per level, and the prefetched rmaps. */ - r = kvm_mmu_topup_memory_cache(&vcpu->arch.mmu_pte_list_desc_cache, - 1 + PT64_ROOT_MAX_LEVEL + PTE_PREFETCH_NUM); - if (r) - return r; + if (kvm_memslots_have_rmaps(vcpu->kvm)) { + /* 1 rmap, 1 parent PTE per level, and the prefetched rmaps. */ + r = kvm_mmu_topup_memory_cache(&vcpu->arch.mmu_pte_list_desc_cache, + 1 + PT64_ROOT_MAX_LEVEL + PTE_PREFETCH_NUM); + if (r) + return r; + } r = kvm_mmu_topup_memory_cache(&vcpu->arch.mmu_shadow_page_cache, PT64_ROOT_MAX_LEVEL); if (r) -- 2.37.0.rc0.161.g10f37bed90-goog