From: yulei.kernel@gmail.com
To: pbonzini@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
sean.j.christopherson@intel.com, jmattson@google.com,
junaids@google.com, bgardon@google.com, vkuznets@redhat.com,
xiaoguangrong.eric@gmail.com, kernellwp@gmail.com,
lihaiwei.kernel@gmail.com, Yulei Zhang <yulei.kernel@gmail.com>,
Yulei Zhang <yuleixzhang@tencent.com>
Subject: [RFC V2 4/9] Add release function for direct build ept when guest VM exit
Date: Tue, 1 Sep 2020 19:55:42 +0800 [thread overview]
Message-ID: <6023066803ff748b73080fe3bad7aee45ce3f9fa.1598868204.git.yulei.kernel@gmail.com> (raw)
In-Reply-To: <cover.1598868203.git.yulei.kernel@gmail.com>
From: Yulei Zhang <yulei.kernel@gmail.com>
Release the pre-pinned memory in direct build ept when guest VM
exit.
Signed-off-by: Yulei Zhang <yuleixzhang@tencent.com>
---
arch/x86/kvm/mmu/mmu.c | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 03c5e73b96cb..f2124f52b286 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -4309,8 +4309,11 @@ static void __kvm_mmu_new_pgd(struct kvm_vcpu *vcpu, gpa_t new_pgd,
void kvm_mmu_new_pgd(struct kvm_vcpu *vcpu, gpa_t new_pgd, bool skip_tlb_flush,
bool skip_mmu_sync)
{
- __kvm_mmu_new_pgd(vcpu, new_pgd, kvm_mmu_calc_root_page_role(vcpu),
- skip_tlb_flush, skip_mmu_sync);
+ if (!vcpu->arch.direct_build_tdp)
+ __kvm_mmu_new_pgd(vcpu, new_pgd, kvm_mmu_calc_root_page_role(vcpu),
+ skip_tlb_flush, skip_mmu_sync);
+ else
+ vcpu->arch.mmu->root_hpa = INVALID_PAGE;
}
EXPORT_SYMBOL_GPL(kvm_mmu_new_pgd);
@@ -5207,10 +5210,14 @@ EXPORT_SYMBOL_GPL(kvm_mmu_load);
void kvm_mmu_unload(struct kvm_vcpu *vcpu)
{
- kvm_mmu_free_roots(vcpu, &vcpu->arch.root_mmu, KVM_MMU_ROOTS_ALL);
- WARN_ON(VALID_PAGE(vcpu->arch.root_mmu.root_hpa));
- kvm_mmu_free_roots(vcpu, &vcpu->arch.guest_mmu, KVM_MMU_ROOTS_ALL);
- WARN_ON(VALID_PAGE(vcpu->arch.guest_mmu.root_hpa));
+ if (!vcpu->arch.direct_build_tdp) {
+ kvm_mmu_free_roots(vcpu, &vcpu->arch.root_mmu, KVM_MMU_ROOTS_ALL);
+ WARN_ON(VALID_PAGE(vcpu->arch.root_mmu.root_hpa));
+ kvm_mmu_free_roots(vcpu, &vcpu->arch.guest_mmu, KVM_MMU_ROOTS_ALL);
+ WARN_ON(VALID_PAGE(vcpu->arch.guest_mmu.root_hpa));
+ }
+ vcpu->arch.direct_build_tdp = false;
+ vcpu->arch.mmu->root_hpa = INVALID_PAGE;
}
EXPORT_SYMBOL_GPL(kvm_mmu_unload);
@@ -6538,6 +6545,14 @@ void kvm_direct_tdp_remove_page_table(struct kvm *kvm, struct kvm_memory_slot *s
kvm_flush_remote_tlbs(kvm);
}
+void kvm_direct_tdp_release_global_root(struct kvm *kvm)
+{
+ if (kvm->arch.global_root_hpa)
+ __kvm_walk_global_page(kvm, kvm->arch.global_root_hpa, max_tdp_level);
+
+ return;
+}
+
/*
* Calculate mmu pages needed for kvm.
*/
@@ -6564,9 +6579,13 @@ unsigned long kvm_mmu_calculate_default_mmu_pages(struct kvm *kvm)
void kvm_mmu_destroy(struct kvm_vcpu *vcpu)
{
- kvm_mmu_unload(vcpu);
- free_mmu_pages(&vcpu->arch.root_mmu);
- free_mmu_pages(&vcpu->arch.guest_mmu);
+ if (vcpu->arch.direct_build_tdp) {
+ vcpu->arch.mmu->root_hpa = INVALID_PAGE;
+ } else {
+ kvm_mmu_unload(vcpu);
+ free_mmu_pages(&vcpu->arch.root_mmu);
+ free_mmu_pages(&vcpu->arch.guest_mmu);
+ }
mmu_free_memory_caches(vcpu);
}
--
2.17.1
next prev parent reply other threads:[~2020-09-01 12:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-01 11:52 [RFC V2 0/9] x86/mmu:Introduce parallel memory virtualization to boost performance yulei.kernel
2020-09-01 11:54 ` [RFC V2 1/9] Introduce new fields in kvm_arch/vcpu_arch struct for direct build EPT support yulei.kernel
2020-09-01 11:55 ` [RFC V2 2/9] Introduce page table population function for direct build EPT feature yulei.kernel
2020-09-01 11:55 ` [RFC V2 3/9] Introduce page table remove " yulei.kernel
2020-09-01 11:55 ` yulei.kernel [this message]
2020-09-01 11:56 ` [RFC V2 5/9] Modify the page fault path to meet the direct build EPT requirement yulei.kernel
2020-09-01 11:56 ` [RFC V2 6/9] Apply the direct build EPT according to the memory slots change yulei.kernel
2020-09-01 11:56 ` [RFC V2 7/9] Add migration support when using direct build EPT yulei.kernel
2020-09-01 11:57 ` [RFC V2 8/9] Introduce kvm module parameter global_tdp to turn on the direct build EPT mode yulei.kernel
2020-09-01 11:57 ` [RFC V2 9/9] Handle certain mmu exposed functions properly while turn on " yulei.kernel
2020-09-09 3:04 ` [RFC V2 0/9] x86/mmu:Introduce parallel memory virtualization to boost performance Wanpeng Li
2020-09-24 6:28 ` Wanpeng Li
2020-09-24 17:14 ` Ben Gardon
2020-09-25 12:04 ` yulei zhang
2020-09-25 17:30 ` Ben Gardon
2020-09-25 20:50 ` Paolo Bonzini
2020-09-28 11:52 ` yulei zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6023066803ff748b73080fe3bad7aee45ce3f9fa.1598868204.git.yulei.kernel@gmail.com \
--to=yulei.kernel@gmail.com \
--cc=bgardon@google.com \
--cc=jmattson@google.com \
--cc=junaids@google.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=lihaiwei.kernel@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=vkuznets@redhat.com \
--cc=xiaoguangrong.eric@gmail.com \
--cc=yuleixzhang@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).