Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp704866pxu; Wed, 14 Oct 2020 11:29:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcb+eyYDU+F+PyIVDrjZqCPk+7eyuwWcXu0pGLVtwkQMcfoLofyuRTTYc0+aEXtsBFSAC4 X-Received: by 2002:a05:6402:3184:: with SMTP id di4mr251739edb.362.1602700150485; Wed, 14 Oct 2020 11:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602700150; cv=none; d=google.com; s=arc-20160816; b=CKLehF63DDsrErg45NS4CeHFSoCYUHgtSU/S4QrtwQQkQ9UjLSlUn6U3FRguIZRXFs WdWCa8jsea1buRh/UtSYqSjN3SdlzlL9AZMPE2S/jxaCWaDUTzJ4VnWHfaV0/wkj4NXt 5BSkqEixjELnclCZHE7g7RNWnVOByh6e+LCZNHtFHgNWZfVGzemu1PKbvOITyKMdZozn lmEu/vRXrUTvBFuNh7PNvX1mizNVKac2T/ueSlq/lNVI7+OWJZnVyr5KO1hxBz4UQ4BB vFirn6f2BsGWxgLCTA8LXwESFQE4EhLVV8fpPeQtxp63aSMNAPsCaAMTy9zC8Yqr9qlq LL/w== 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:sender:dkim-signature; bh=XE3TlFzPB074DCulw3ZKAATgb2BIibEai56f3kal+II=; b=FQFD6/LizAj4guhnDrs7856MwwHntZlU4BezmdooWIxleuym47D4iepN+oTF0NvqmT Sel7xAq9AgFepl6jO+40QhA1TfG0gTkEbe9dyKw0jv/c4bZlqROFT91n4Gh2flMTTNyF LGYG+Nv3gj53jjGhkxksBP/s7f4XReayonPyY54pqxelgKesNYtUulA+Dh2PJFnUR1iZ S+4g1Bd92w1aYF4nbuN8I7XT9OcQDEacF4IMNwtQCfcbywZbwv5zpQ0l0bS3r5MsH1kx n0nupVUXcAz3928mXF6OceVSYtfPn9sv7GqxKJJcoewbDVGPDugH6DCo7sBwFVsHU3tt bFwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oWJ8N4+o; 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 v1si394004ejd.624.2020.10.14.11.28.47; Wed, 14 Oct 2020 11:29:10 -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=oWJ8N4+o; 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 S2389109AbgJNS13 (ORCPT + 99 others); Wed, 14 Oct 2020 14:27:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388680AbgJNS1Z (ORCPT ); Wed, 14 Oct 2020 14:27:25 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B47F7C0613E6 for ; Wed, 14 Oct 2020 11:27:24 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id t40so274111qtc.19 for ; Wed, 14 Oct 2020 11:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=XE3TlFzPB074DCulw3ZKAATgb2BIibEai56f3kal+II=; b=oWJ8N4+og/FhbMEIhzH50l+ThvY+HucabBowIojdpkR3aSqw6s5d2lAhtkzAunqP25 NtUwx36AprsPytZcLL7fhxigSF/lBPNTAhKeQDX43LzJ4MjLv8iU1V3XYnuKfY8nSL91 DXKs078mOYbgurWZEvzuf0WMM2Vj5Hoe43xnVjW6sprBIwrRzUmudwoHwRJMZ1mcmgo4 ya7RApj4mZD6uSQxyb+sIz2gp78C5mXuhKUnnPnvSGWdo8F2kxwX1aA+Wgr7YYQKyZym BOtxB9AhLsBC4V0AhyJM0Tzt/augj4K1yLQgYo1smetdiDqbnH/iBh8cBk/tivBycfLs cMKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XE3TlFzPB074DCulw3ZKAATgb2BIibEai56f3kal+II=; b=WkdSCpPQsrK0KQro10Vdtj1dVy/YkmiSUFqHWNXYTeRqk1s0pRGkyNyiBzmA3YQP50 w09H3AibdOWx2p3Y2fhlBw0xs9Mtm+iL+XwO7Lxcrl7gs4AJiWhr6738T7KBTkqxOlyy f7z4l31oEtuxbPnCKwTXhPh3zreAo0npgVOUUcAJ02SUkie3hCHRaRvSlH5BTD5YvuY0 VV6YR/aX4CGwcknncTw0wBS5/TB/JW24TJ8knhstu6BGU8E5qV4UWkCTlqGxJv8eSMbr Mu1SNq4stuWiavS5+2WZKH4KJzN5ZAiy48HW5xw6HE0wiUq3uDOxdJYUeyLAQUi/FBHt 3AyQ== X-Gm-Message-State: AOAM531biSSs3Ijpyj9B8ppVLLUHDE8A/LK210pYAtBnTjQUGktIw7ai /JpBmHOE8i36bXs4srwqJrxdzIznw2XsyKVC/ZtKDnAhlE82VzH6uS2JMdJwAACJegbOFhs308n 4rNDZPArcy+6jZG1sYeMi3+3HhtIjG3/pkMyDQPdMOSwrAFD03033Z8SmsjyjoFu0YZh3TM2X Sender: "bgardon via sendgmr" X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:f693:9fff:fef4:a293]) (user=bgardon job=sendgmr) by 2002:a0c:bb83:: with SMTP id i3mr824901qvg.15.1602700043714; Wed, 14 Oct 2020 11:27:23 -0700 (PDT) Date: Wed, 14 Oct 2020 11:26:51 -0700 In-Reply-To: <20201014182700.2888246-1-bgardon@google.com> Message-Id: <20201014182700.2888246-12-bgardon@google.com> Mime-Version: 1.0 References: <20201014182700.2888246-1-bgardon@google.com> X-Mailer: git-send-email 2.28.0.1011.ga647a8990f-goog Subject: [PATCH v2 11/20] kvm: x86/mmu: Allocate struct kvm_mmu_pages for all pages in TDP MMU From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Cannon Matthews , Paolo Bonzini , Peter Xu , Sean Christopherson , Peter Shier , Peter Feiner , 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 Attach struct kvm_mmu_pages to every page in the TDP MMU to track metadata, facilitate NX reclaim, and enable inproved parallelism of MMU operations in future patches. Tested by running kvm-unit-tests and KVM selftests on an Intel Haswell machine. This series introduced no new failures. This series can be viewed in Gerrit at: https://linux-review.googlesource.com/c/virt/kvm/kvm/+/2538 Signed-off-by: Ben Gardon --- arch/x86/include/asm/kvm_host.h | 4 ++++ arch/x86/kvm/mmu/tdp_mmu.c | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index e0ec1dd271a32..2568dcd134156 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -989,7 +989,11 @@ struct kvm_arch { * operations. */ bool tdp_mmu_enabled; + + /* List of struct tdp_mmu_pages being used as roots */ struct list_head tdp_mmu_roots; + /* List of struct tdp_mmu_pages not being used as roots */ + struct list_head tdp_mmu_pages; }; struct kvm_vm_stat { diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index f92c12c4ce31a..78d41a1949651 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -34,6 +34,7 @@ void kvm_mmu_init_tdp_mmu(struct kvm *kvm) kvm->arch.tdp_mmu_enabled = true; INIT_LIST_HEAD(&kvm->arch.tdp_mmu_roots); + INIT_LIST_HEAD(&kvm->arch.tdp_mmu_pages); } void kvm_mmu_uninit_tdp_mmu(struct kvm *kvm) @@ -188,6 +189,7 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn, bool is_leaf = is_present && is_last_spte(new_spte, level); bool pfn_changed = spte_to_pfn(old_spte) != spte_to_pfn(new_spte); u64 *pt; + struct kvm_mmu_page *sp; u64 old_child_spte; int i; @@ -253,6 +255,9 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn, */ if (was_present && !was_leaf && (pfn_changed || !is_present)) { pt = spte_to_child_pt(old_spte, level); + sp = sptep_to_sp(pt); + + list_del(&sp->link); for (i = 0; i < PT64_ENT_PER_PAGE; i++) { old_child_spte = *(pt + i); @@ -266,6 +271,7 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn, KVM_PAGES_PER_HPAGE(level)); free_page((unsigned long)pt); + kmem_cache_free(mmu_page_header_cache, sp); } } @@ -434,8 +440,7 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, bool huge_page_disallowed = exec && nx_huge_page_workaround_enabled; struct kvm_mmu *mmu = vcpu->arch.mmu; struct tdp_iter iter; - struct kvm_mmu_memory_cache *pf_pt_cache = - &vcpu->arch.mmu_shadow_page_cache; + struct kvm_mmu_page *sp; u64 *child_pt; u64 new_spte; int ret; @@ -479,7 +484,9 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, } if (!is_shadow_present_pte(iter.old_spte)) { - child_pt = kvm_mmu_memory_cache_alloc(pf_pt_cache); + sp = alloc_tdp_mmu_page(vcpu, iter.gfn, iter.level); + list_add(&sp->link, &vcpu->kvm->arch.tdp_mmu_pages); + child_pt = sp->spt; clear_page(child_pt); new_spte = make_nonleaf_spte(child_pt, !shadow_accessed_mask); -- 2.28.0.1011.ga647a8990f-goog