Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4904359pxy; Tue, 27 Apr 2021 15:38:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMQZ3F0LdK0Lv9ucWBpQsGXGdw/v7BzXbIgsbuq3cjt86hni5Djk/LzdwyB4t+H4J8wCIj X-Received: by 2002:a17:902:8548:b029:ed:5334:40c2 with SMTP id d8-20020a1709028548b02900ed533440c2mr7293586plo.36.1619563118933; Tue, 27 Apr 2021 15:38:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619563118; cv=none; d=google.com; s=arc-20160816; b=IIIVWnyzsPjsxg35y4z4qFb2yjl3EQ1gSeZQJV+Gwk58tjSenSGaaE8O10MfLZty5C WAl/5+C9RTJtEZVjrW34z8zua/63o5nhtieON80NMGRNX4C3YlNwYGazLZdz6ngJWtvb Nya4RuRzJU0U3TSD2oRssiNltyfsPr2lCrbG5hiB+guHz4vMnfdTReEiZZ15Hjk6Ojqr jSgA+J6trIa5IydxpNu1puHoxtbCrTvJ46qAnUtZm+y9d2M0aKaCNF/m9CaMdIi312Mc MgDapgsyVRCvsayDe3YJamDSVY3id2h9fFSE3DyNZQm59javcXZ7ipnwAiEmtjAYX+M3 9k6g== 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:mime-version:message-id:date :dkim-signature; bh=tTxyuPdn4rgY+Ver4IyXpo1lEOrhYEkf7++g5p9MMkg=; b=BfFxJBXr2ld9iPWobbizvqItSqnyp3P8ig0iIysnv8cGPHvKsjr56w7VQAWuvDugH3 gATWwkSKjraI30hrKIko+r4+PYhPNBPQzcM0P2mqDyU6sY1vTBR7S0UjfX2AYzOa3Lkq JuBZiH754wrJie5GWIPyoONxMXCkhRMLgoVeggJ6ku2Dn83JRCPRy61Fq1WePRjjy+tE pXdFKW0DyKbPSxyN6+FYGR/puZXGlxpc2O9kfb3zESD2P4iw1QIj24Sp7j/Z7ZMnG7X0 3qt74CgGMZaApzkNXHPWVixWWUCyHcXeHbu39rQ9ym60ec8BaJTutSd0WNi05hVdWdro zmfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Em3n9hB7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z22si1292367pga.97.2021.04.27.15.38.00; Tue, 27 Apr 2021 15:38:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Em3n9hB7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237009AbhD0Wh0 (ORCPT + 99 others); Tue, 27 Apr 2021 18:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236805AbhD0WhY (ORCPT ); Tue, 27 Apr 2021 18:37:24 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A59E8C06175F for ; Tue, 27 Apr 2021 15:36:39 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id y9-20020ae9f4090000b02902e4caf24229so3495051qkl.4 for ; Tue, 27 Apr 2021 15:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=tTxyuPdn4rgY+Ver4IyXpo1lEOrhYEkf7++g5p9MMkg=; b=Em3n9hB7Hvpo19frVT+W+lf6YpZN5+Lr/0LqsFFv0gNvnZnCBzxm85s0fMMnF+6ztv NKgRvI3OiEknf83jl0j/hk084leCvhzoTUmE9ZrF/gymP1jb4V1UkbftHvSRYXenOpQz 3Xg3YuF6ncGvV2eV2iUfGUECxCAnkHYkMCrmgkfCT81klWMmMVFOzQ+LSDHr9+9E0D4L CYpXFr3jJ9XUcovYwMVuaNobPazmLKJ0LwIbuHRlQ7+LH4yLe5Y8lKXzpd8nbtsTr8hD LRqSj7wVd8no/fUL/noDSo5qeP4INm6gbF8Xr4kp0LuBnnSUr09Jbcik3UTksPFUmrB3 2BLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=tTxyuPdn4rgY+Ver4IyXpo1lEOrhYEkf7++g5p9MMkg=; b=KR48Ld9vLtYGSioAEWIexweeug80NfDv2XrlVei4BG8EdZMfILTBPjpBiTrmPfEI9W s2+nP1vKzwTtQiqEmEHkjb6q7sZeS0qhufRSNogonwP5luXoLvmBHS5Tu8H6y3XbcMz0 8lPr/aGie1F6p+mkLNT4LKYXUftj58QBjFgCh3SxHVenmrnMcAuSYiJ4XgGOV/h4M6Vl oVQjW/k0miLrqvzIpH1aC0AgZAE6/hDoHgGNkBqW37H9poMkhMLiP3d6XKv0zBK73tX/ gXj9Wj8cu/nPlDzdN2om6bUrRigyg1vlgeOr+UMSFQD9UGd7EErIr3xg3QXxYqFKa8db hKaA== X-Gm-Message-State: AOAM533nHwvep1SsdvdnT5zcx0Yzwa38Oy8llwlN4lgIiSozzjgB8zVj IFhcIhfaHpoMsq11CW+RZDkqeBRb6jd5bvoiubug/Vzo9nRLDZqkEeDt628hiM8veXjuW4nFmHG SvpkJJosxQG/QjtPfSZgovWXW8VbC1ZQNFcWNm+dHp0afbWMh7UkbswqWXGGQL81YKHvCa7Jj X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:d0b5:c590:c6b:bd9c]) (user=bgardon job=sendgmr) by 2002:a05:6214:246a:: with SMTP id im10mr25700282qvb.7.1619562998354; Tue, 27 Apr 2021 15:36:38 -0700 (PDT) Date: Tue, 27 Apr 2021 15:36:29 -0700 Message-Id: <20210427223635.2711774-1-bgardon@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH 0/6] Lazily allocate memslot rmaps From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Peter Xu , Sean Christopherson , Peter Shier , Junaid Shahid , Jim Mattson , Yulei Zhang , Wanpeng Li , Vitaly Kuznetsov , Xiao Guangrong , Ben Gardon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series enables KVM to save memory when using the TDP MMU by waiting to allocate memslot rmaps until they are needed. To do this, KVM tracks whether or not a shadow root has been allocated. In order to get away with not allocating the rmaps, KVM must also be sure to skip operations which iterate over the rmaps. If the TDP MMU is in use and we have not allocated a shadow root, these operations would essentially be op-ops anyway. Skipping the rmap operations has a secondary benefit of avoiding acquiring the MMU lock in write mode in many cases, substantially reducing MMU lock contention. This series was tested on an Intel Skylake machine. With the TDP MMU off and on, this introduced no new failures on kvm-unit-tests or KVM selftests. Ben Gardon (6): KVM: x86/mmu: Track if shadow MMU active KVM: x86/mmu: Skip rmap operations if shadow MMU inactive KVM: x86/mmu: Deduplicate rmap freeing in allocate_memslot_rmap KVM: x86/mmu: Factor out allocating memslot rmap KVM: x86/mmu: Protect kvm->memslots with a mutex KVM: x86/mmu: Lazily allocate memslot rmaps arch/x86/include/asm/kvm_host.h | 20 +++++ arch/x86/kvm/mmu/mmu.c | 153 +++++++++++++++++++++----------- arch/x86/kvm/mmu/mmu_internal.h | 2 + arch/x86/kvm/mmu/tdp_mmu.c | 6 +- arch/x86/kvm/mmu/tdp_mmu.h | 4 +- arch/x86/kvm/x86.c | 133 +++++++++++++++++++++++---- include/linux/kvm_host.h | 2 + virt/kvm/kvm_main.c | 48 +++++++--- 8 files changed, 283 insertions(+), 85 deletions(-) -- 2.31.1.498.g6c1eba8ee3d-goog