Commit 4d78d0b3 authored by Ben Gardon's avatar Ben Gardon Committed by Paolo Bonzini

KVM: x86/mmu: Remove need for a vcpu from mmu_try_to_unsync_pages

The vCPU argument to mmu_try_to_unsync_pages is now only used to get a
pointer to the associated struct kvm, so pass in the kvm pointer from
the beginning to remove the need for a vCPU when calling the function.
Signed-off-by: default avatarBen Gardon <bgardon@google.com>
Message-Id: <20211115234603.2908381-7-bgardon@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 9d395a0a
...@@ -2565,10 +2565,10 @@ static int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva) ...@@ -2565,10 +2565,10 @@ static int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva)
return r; return r;
} }
static void kvm_unsync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) static void kvm_unsync_page(struct kvm *kvm, struct kvm_mmu_page *sp)
{ {
trace_kvm_mmu_unsync_page(sp); trace_kvm_mmu_unsync_page(sp);
++vcpu->kvm->stat.mmu_unsync; ++kvm->stat.mmu_unsync;
sp->unsync = 1; sp->unsync = 1;
kvm_mmu_mark_parents_unsync(sp); kvm_mmu_mark_parents_unsync(sp);
...@@ -2580,7 +2580,7 @@ static void kvm_unsync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) ...@@ -2580,7 +2580,7 @@ static void kvm_unsync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
* were marked unsync (or if there is no shadow page), -EPERM if the SPTE must * were marked unsync (or if there is no shadow page), -EPERM if the SPTE must
* be write-protected. * be write-protected.
*/ */
int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot, int mmu_try_to_unsync_pages(struct kvm *kvm, struct kvm_memory_slot *slot,
gfn_t gfn, bool can_unsync, bool prefetch) gfn_t gfn, bool can_unsync, bool prefetch)
{ {
struct kvm_mmu_page *sp; struct kvm_mmu_page *sp;
...@@ -2591,7 +2591,7 @@ int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot, ...@@ -2591,7 +2591,7 @@ int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot,
* track machinery is used to write-protect upper-level shadow pages, * track machinery is used to write-protect upper-level shadow pages,
* i.e. this guards the role.level == 4K assertion below! * i.e. this guards the role.level == 4K assertion below!
*/ */
if (kvm_slot_page_track_is_active(vcpu->kvm, slot, gfn, KVM_PAGE_TRACK_WRITE)) if (kvm_slot_page_track_is_active(kvm, slot, gfn, KVM_PAGE_TRACK_WRITE))
return -EPERM; return -EPERM;
/* /*
...@@ -2600,7 +2600,7 @@ int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot, ...@@ -2600,7 +2600,7 @@ int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot,
* that case, KVM must complete emulation of the guest TLB flush before * that case, KVM must complete emulation of the guest TLB flush before
* allowing shadow pages to become unsync (writable by the guest). * allowing shadow pages to become unsync (writable by the guest).
*/ */
for_each_gfn_indirect_valid_sp(vcpu->kvm, sp, gfn) { for_each_gfn_indirect_valid_sp(kvm, sp, gfn) {
if (!can_unsync) if (!can_unsync)
return -EPERM; return -EPERM;
...@@ -2619,7 +2619,7 @@ int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot, ...@@ -2619,7 +2619,7 @@ int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot,
*/ */
if (!locked) { if (!locked) {
locked = true; locked = true;
spin_lock(&vcpu->kvm->arch.mmu_unsync_pages_lock); spin_lock(&kvm->arch.mmu_unsync_pages_lock);
/* /*
* Recheck after taking the spinlock, a different vCPU * Recheck after taking the spinlock, a different vCPU
...@@ -2634,10 +2634,10 @@ int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot, ...@@ -2634,10 +2634,10 @@ int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot,
} }
WARN_ON(sp->role.level != PG_LEVEL_4K); WARN_ON(sp->role.level != PG_LEVEL_4K);
kvm_unsync_page(vcpu, sp); kvm_unsync_page(kvm, sp);
} }
if (locked) if (locked)
spin_unlock(&vcpu->kvm->arch.mmu_unsync_pages_lock); spin_unlock(&kvm->arch.mmu_unsync_pages_lock);
/* /*
* We need to ensure that the marking of unsync pages is visible * We need to ensure that the marking of unsync pages is visible
......
...@@ -117,7 +117,7 @@ static inline bool kvm_mmu_page_ad_need_write_protect(struct kvm_mmu_page *sp) ...@@ -117,7 +117,7 @@ static inline bool kvm_mmu_page_ad_need_write_protect(struct kvm_mmu_page *sp)
return kvm_x86_ops.cpu_dirty_log_size && sp->role.guest_mode; return kvm_x86_ops.cpu_dirty_log_size && sp->role.guest_mode;
} }
int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot, int mmu_try_to_unsync_pages(struct kvm *kvm, struct kvm_memory_slot *slot,
gfn_t gfn, bool can_unsync, bool prefetch); gfn_t gfn, bool can_unsync, bool prefetch);
void kvm_mmu_gfn_disallow_lpage(const struct kvm_memory_slot *slot, gfn_t gfn); void kvm_mmu_gfn_disallow_lpage(const struct kvm_memory_slot *slot, gfn_t gfn);
......
...@@ -161,7 +161,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, ...@@ -161,7 +161,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
* e.g. it's write-tracked (upper-level SPs) or has one or more * e.g. it's write-tracked (upper-level SPs) or has one or more
* shadow pages and unsync'ing pages is not allowed. * shadow pages and unsync'ing pages is not allowed.
*/ */
if (mmu_try_to_unsync_pages(vcpu, slot, gfn, can_unsync, prefetch)) { if (mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, can_unsync, prefetch)) {
pgprintk("%s: found shadow page for %llx, marking ro\n", pgprintk("%s: found shadow page for %llx, marking ro\n",
__func__, gfn); __func__, gfn);
wrprot = true; wrprot = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment