Skip to content

Commit 9328444

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86/mmu: Don't bounce through page-track mechanism for guest PTEs
Don't use the generic page-track mechanism to handle writes to guest PTEs in KVM's MMU. KVM's MMU needs access to information that should not be exposed to external page-track users, e.g. KVM needs (for some definitions of "need") the vCPU to query the current paging mode, whereas external users, i.e. KVMGT, have no ties to the current vCPU and so should never need the vCPU. Moving away from the page-track mechanism will allow dropping use of the page-track mechanism for KVM's own MMU, and will also allow simplifying and cleaning up the page-track APIs. Reviewed-by: Yan Zhao <[email protected]> Tested-by: Yongwei Ma <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent eeb8727 commit 9328444

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,6 @@ struct kvm_arch {
12651265
* create an NX huge page (without hanging the guest).
12661266
*/
12671267
struct list_head possible_nx_huge_pages;
1268-
struct kvm_page_track_notifier_node mmu_sp_tracker;
12691268
struct kvm_page_track_notifier_head track_notifier_head;
12701269
/*
12711270
* Protects marking pages unsync during page faults, as TDP MMU page

arch/x86/kvm/mmu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ void kvm_mmu_unload(struct kvm_vcpu *vcpu);
121121
void kvm_mmu_free_obsolete_roots(struct kvm_vcpu *vcpu);
122122
void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu);
123123
void kvm_mmu_sync_prev_roots(struct kvm_vcpu *vcpu);
124+
void kvm_mmu_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new,
125+
int bytes);
124126

125127
static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu)
126128
{

arch/x86/kvm/mmu/mmu.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5635,9 +5635,8 @@ static u64 *get_written_sptes(struct kvm_mmu_page *sp, gpa_t gpa, int *nspte)
56355635
return spte;
56365636
}
56375637

5638-
static void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
5639-
const u8 *new, int bytes,
5640-
struct kvm_page_track_notifier_node *node)
5638+
void kvm_mmu_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new,
5639+
int bytes)
56415640
{
56425641
gfn_t gfn = gpa >> PAGE_SHIFT;
56435642
struct kvm_mmu_page *sp;
@@ -6161,7 +6160,6 @@ static bool kvm_has_zapped_obsolete_pages(struct kvm *kvm)
61616160

61626161
int kvm_mmu_init_vm(struct kvm *kvm)
61636162
{
6164-
struct kvm_page_track_notifier_node *node = &kvm->arch.mmu_sp_tracker;
61656163
int r;
61666164

61676165
INIT_LIST_HEAD(&kvm->arch.active_mmu_pages);
@@ -6175,9 +6173,6 @@ int kvm_mmu_init_vm(struct kvm *kvm)
61756173
return r;
61766174
}
61776175

6178-
node->track_write = kvm_mmu_pte_write;
6179-
kvm_page_track_register_notifier(kvm, node);
6180-
61816176
kvm->arch.split_page_header_cache.kmem_cache = mmu_page_header_cache;
61826177
kvm->arch.split_page_header_cache.gfp_zero = __GFP_ZERO;
61836178

@@ -6198,10 +6193,6 @@ static void mmu_free_vm_memory_caches(struct kvm *kvm)
61986193

61996194
void kvm_mmu_uninit_vm(struct kvm *kvm)
62006195
{
6201-
struct kvm_page_track_notifier_node *node = &kvm->arch.mmu_sp_tracker;
6202-
6203-
kvm_page_track_unregister_notifier(kvm, node);
6204-
62056196
if (tdp_mmu_enabled)
62066197
kvm_mmu_uninit_tdp_mmu(kvm);
62076198

arch/x86/kvm/mmu/page_track.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new,
274274
if (n->track_write)
275275
n->track_write(vcpu, gpa, new, bytes, n);
276276
srcu_read_unlock(&head->track_srcu, idx);
277+
278+
kvm_mmu_track_write(vcpu, gpa, new, bytes);
277279
}
278280

279281
/*

0 commit comments

Comments
 (0)