Skip to content

Commit 89c0fd4

Browse files
Ben Gardonbonzini
authored andcommitted
kvm: x86/mmu: Allocate struct kvm_mmu_pages for all pages in TDP MMU
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 <bgardon@google.com> Message-Id: <20201014182700.2888246-12-bgardon@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent bb18842 commit 89c0fd4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,11 @@ struct kvm_arch {
10041004
* operations.
10051005
*/
10061006
bool tdp_mmu_enabled;
1007+
1008+
/* List of struct tdp_mmu_pages being used as roots */
10071009
struct list_head tdp_mmu_roots;
1010+
/* List of struct tdp_mmu_pages not being used as roots */
1011+
struct list_head tdp_mmu_pages;
10081012
};
10091013

10101014
struct kvm_vm_stat {

arch/x86/kvm/mmu/tdp_mmu.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void kvm_mmu_init_tdp_mmu(struct kvm *kvm)
2828
kvm->arch.tdp_mmu_enabled = true;
2929

3030
INIT_LIST_HEAD(&kvm->arch.tdp_mmu_roots);
31+
INIT_LIST_HEAD(&kvm->arch.tdp_mmu_pages);
3132
}
3233

3334
void kvm_mmu_uninit_tdp_mmu(struct kvm *kvm)
@@ -169,6 +170,7 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
169170
bool is_leaf = is_present && is_last_spte(new_spte, level);
170171
bool pfn_changed = spte_to_pfn(old_spte) != spte_to_pfn(new_spte);
171172
u64 *pt;
173+
struct kvm_mmu_page *sp;
172174
u64 old_child_spte;
173175
int i;
174176

@@ -234,6 +236,9 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
234236
*/
235237
if (was_present && !was_leaf && (pfn_changed || !is_present)) {
236238
pt = spte_to_child_pt(old_spte, level);
239+
sp = sptep_to_sp(pt);
240+
241+
list_del(&sp->link);
237242

238243
for (i = 0; i < PT64_ENT_PER_PAGE; i++) {
239244
old_child_spte = READ_ONCE(*(pt + i));
@@ -247,6 +252,7 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
247252
KVM_PAGES_PER_HPAGE(level));
248253

249254
free_page((unsigned long)pt);
255+
kmem_cache_free(mmu_page_header_cache, sp);
250256
}
251257
}
252258

@@ -424,8 +430,7 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code,
424430
bool huge_page_disallowed = exec && nx_huge_page_workaround_enabled;
425431
struct kvm_mmu *mmu = vcpu->arch.mmu;
426432
struct tdp_iter iter;
427-
struct kvm_mmu_memory_cache *pf_pt_cache =
428-
&vcpu->arch.mmu_shadow_page_cache;
433+
struct kvm_mmu_page *sp;
429434
u64 *child_pt;
430435
u64 new_spte;
431436
int ret;
@@ -471,7 +476,9 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code,
471476
}
472477

473478
if (!is_shadow_present_pte(iter.old_spte)) {
474-
child_pt = kvm_mmu_memory_cache_alloc(pf_pt_cache);
479+
sp = alloc_tdp_mmu_page(vcpu, iter.gfn, iter.level);
480+
list_add(&sp->link, &vcpu->kvm->arch.tdp_mmu_pages);
481+
child_pt = sp->spt;
475482
clear_page(child_pt);
476483
new_spte = make_nonleaf_spte(child_pt,
477484
!shadow_accessed_mask);

0 commit comments

Comments
 (0)