|
@@ -969,8 +969,17 @@ void kvm_mmu_pre_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes)
|
|
|
unsigned page_offset;
|
|
|
unsigned misaligned;
|
|
|
int level;
|
|
|
+ int flooded = 0;
|
|
|
|
|
|
pgprintk("%s: gpa %llx bytes %d\n", __FUNCTION__, gpa, bytes);
|
|
|
+ if (gfn == vcpu->last_pt_write_gfn) {
|
|
|
+ ++vcpu->last_pt_write_count;
|
|
|
+ if (vcpu->last_pt_write_count >= 3)
|
|
|
+ flooded = 1;
|
|
|
+ } else {
|
|
|
+ vcpu->last_pt_write_gfn = gfn;
|
|
|
+ vcpu->last_pt_write_count = 1;
|
|
|
+ }
|
|
|
index = kvm_page_table_hashfn(gfn) % KVM_NUM_MMU_PAGES;
|
|
|
bucket = &vcpu->kvm->mmu_page_hash[index];
|
|
|
hlist_for_each_entry_safe(page, node, n, bucket, hash_link) {
|
|
@@ -978,11 +987,16 @@ void kvm_mmu_pre_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes)
|
|
|
continue;
|
|
|
pte_size = page->role.glevels == PT32_ROOT_LEVEL ? 4 : 8;
|
|
|
misaligned = (offset ^ (offset + bytes - 1)) & ~(pte_size - 1);
|
|
|
- if (misaligned) {
|
|
|
+ if (misaligned || flooded) {
|
|
|
/*
|
|
|
* Misaligned accesses are too much trouble to fix
|
|
|
* up; also, they usually indicate a page is not used
|
|
|
* as a page table.
|
|
|
+ *
|
|
|
+ * If we're seeing too many writes to a page,
|
|
|
+ * it may no longer be a page table, or we may be
|
|
|
+ * forking, in which case it is better to unmap the
|
|
|
+ * page.
|
|
|
*/
|
|
|
pgprintk("misaligned: gpa %llx bytes %d role %x\n",
|
|
|
gpa, bytes, page->role.word);
|