Commit b99db1d3 authored by Takuya Yoshikawa's avatar Takuya Yoshikawa Committed by Gleb Natapov

KVM: MMU: Make kvm_mmu_slot_remove_write_access() rmap based

This makes it possible to release mmu_lock and reschedule conditionally
in a later patch.  Although this may increase the time needed to protect
the whole slot when we start dirty logging, the kernel should not allow
the userspace to trigger something that will hold a spinlock for such a
long time as tens of milliseconds: actually there is no limit since it
is roughly proportional to the number of guest pages.

Another point to note is that this patch removes the only user of
slot_bitmap which will cause some problems when we increase the number
of slots further.
Reviewed-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarTakuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
Signed-off-by: default avatarGleb Natapov <gleb@redhat.com>
parent 245c3912
...@@ -4172,25 +4172,27 @@ int kvm_mmu_setup(struct kvm_vcpu *vcpu) ...@@ -4172,25 +4172,27 @@ int kvm_mmu_setup(struct kvm_vcpu *vcpu)
void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot) void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot)
{ {
struct kvm_mmu_page *sp; struct kvm_memory_slot *memslot;
bool flush = false; gfn_t last_gfn;
list_for_each_entry(sp, &kvm->arch.active_mmu_pages, link) {
int i; int i;
u64 *pt;
if (!test_bit(slot, sp->slot_bitmap)) memslot = id_to_memslot(kvm->memslots, slot);
continue; last_gfn = memslot->base_gfn + memslot->npages - 1;
pt = sp->spt; for (i = PT_PAGE_TABLE_LEVEL;
for (i = 0; i < PT64_ENT_PER_PAGE; ++i) { i < PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES; ++i) {
if (!is_shadow_present_pte(pt[i]) || unsigned long *rmapp;
!is_last_spte(pt[i], sp->role.level)) unsigned long last_index, index;
continue;
spte_write_protect(kvm, &pt[i], &flush, false); rmapp = memslot->arch.rmap[i - PT_PAGE_TABLE_LEVEL];
last_index = gfn_to_index(last_gfn, memslot->base_gfn, i);
for (index = 0; index <= last_index; ++index, ++rmapp) {
if (*rmapp)
__rmap_write_protect(kvm, rmapp, false);
} }
} }
kvm_flush_remote_tlbs(kvm); kvm_flush_remote_tlbs(kvm);
} }
......
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