Skip to content

Commit 332b207

Browse files
Xiao Guangrongavikivity
authored andcommitted
KVM: MMU: optimize pte write path if don't have protected sp
Simply return from kvm_mmu_pte_write path if no shadow page is write-protected, then we can avoid to walk all shadow pages and hold mmu-lock Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
1 parent 9630421 commit 332b207

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎arch/x86/include/asm/kvm_host.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ struct kvm_arch {
441441
unsigned int n_used_mmu_pages;
442442
unsigned int n_requested_mmu_pages;
443443
unsigned int n_max_mmu_pages;
444+
unsigned int indirect_shadow_pages;
444445
atomic_t invlpg_counter;
445446
struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
446447
/*

‎arch/x86/kvm/mmu.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ static void account_shadowed(struct kvm *kvm, gfn_t gfn)
498498
linfo = lpage_info_slot(gfn, slot, i);
499499
linfo->write_count += 1;
500500
}
501+
kvm->arch.indirect_shadow_pages++;
501502
}
502503

503504
static void unaccount_shadowed(struct kvm *kvm, gfn_t gfn)
@@ -513,6 +514,7 @@ static void unaccount_shadowed(struct kvm *kvm, gfn_t gfn)
513514
linfo->write_count -= 1;
514515
WARN_ON(linfo->write_count < 0);
515516
}
517+
kvm->arch.indirect_shadow_pages--;
516518
}
517519

518520
static int has_wrprotected_page(struct kvm *kvm,
@@ -3233,6 +3235,13 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
32333235
int level, npte, invlpg_counter, r, flooded = 0;
32343236
bool remote_flush, local_flush, zap_page;
32353237

3238+
/*
3239+
* If we don't have indirect shadow pages, it means no page is
3240+
* write-protected, so we can exit simply.
3241+
*/
3242+
if (!ACCESS_ONCE(vcpu->kvm->arch.indirect_shadow_pages))
3243+
return;
3244+
32363245
zap_page = remote_flush = local_flush = false;
32373246
offset = offset_in_page(gpa);
32383247

0 commit comments

Comments
 (0)