Skip to content

Commit a9442f5

Browse files
Ben Gardonbonzini
authored andcommitted
KVM: x86/mmu: Factor out functions to add/remove TDP MMU pages
Move the work of adding and removing TDP MMU pages to/from "secondary" data structures to helper functions. These functions will be built on in future commits to enable MMU operations to proceed (mostly) in parallel. No functional change expected. Signed-off-by: Ben Gardon <bgardon@google.com> Message-Id: <20210202185734.1680553-20-bgardon@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 531810c commit a9442f5

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

arch/x86/kvm/mmu/tdp_mmu.c

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,39 @@ static void handle_changed_spte_dirty_log(struct kvm *kvm, int as_id, gfn_t gfn,
262262
}
263263
}
264264

265+
/**
266+
* tdp_mmu_link_page - Add a new page to the list of pages used by the TDP MMU
267+
*
268+
* @kvm: kvm instance
269+
* @sp: the new page
270+
* @account_nx: This page replaces a NX large page and should be marked for
271+
* eventual reclaim.
272+
*/
273+
static void tdp_mmu_link_page(struct kvm *kvm, struct kvm_mmu_page *sp,
274+
bool account_nx)
275+
{
276+
lockdep_assert_held_write(&kvm->mmu_lock);
277+
278+
list_add(&sp->link, &kvm->arch.tdp_mmu_pages);
279+
if (account_nx)
280+
account_huge_nx_page(kvm, sp);
281+
}
282+
283+
/**
284+
* tdp_mmu_unlink_page - Remove page from the list of pages used by the TDP MMU
285+
*
286+
* @kvm: kvm instance
287+
* @sp: the page to be removed
288+
*/
289+
static void tdp_mmu_unlink_page(struct kvm *kvm, struct kvm_mmu_page *sp)
290+
{
291+
lockdep_assert_held_write(&kvm->mmu_lock);
292+
293+
list_del(&sp->link);
294+
if (sp->lpage_disallowed)
295+
unaccount_huge_nx_page(kvm, sp);
296+
}
297+
265298
/**
266299
* handle_removed_tdp_mmu_page - handle a pt removed from the TDP structure
267300
*
@@ -281,10 +314,7 @@ static void handle_removed_tdp_mmu_page(struct kvm *kvm, u64 *pt)
281314

282315
trace_kvm_mmu_prepare_zap_page(sp);
283316

284-
list_del(&sp->link);
285-
286-
if (sp->lpage_disallowed)
287-
unaccount_huge_nx_page(kvm, sp);
317+
tdp_mmu_unlink_page(kvm, sp);
288318

289319
for (i = 0; i < PT64_ENT_PER_PAGE; i++) {
290320
old_child_spte = READ_ONCE(*(pt + i));
@@ -705,15 +735,16 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code,
705735

706736
if (!is_shadow_present_pte(iter.old_spte)) {
707737
sp = alloc_tdp_mmu_page(vcpu, iter.gfn, iter.level);
708-
list_add(&sp->link, &vcpu->kvm->arch.tdp_mmu_pages);
709738
child_pt = sp->spt;
739+
740+
tdp_mmu_link_page(vcpu->kvm, sp,
741+
huge_page_disallowed &&
742+
req_level >= iter.level);
743+
710744
new_spte = make_nonleaf_spte(child_pt,
711745
!shadow_accessed_mask);
712746

713747
trace_kvm_mmu_get_page(sp, true);
714-
if (huge_page_disallowed && req_level >= iter.level)
715-
account_huge_nx_page(vcpu->kvm, sp);
716-
717748
tdp_mmu_set_spte(vcpu->kvm, &iter, new_spte);
718749
}
719750
}

0 commit comments

Comments
 (0)