Commit a3c870bd authored by Luca Tettamanti's avatar Luca Tettamanti Committed by Avi Kivity

KVM: Avoid useless memory write when possible

When writing to normal memory and the memory area is unchanged the write
can be safely skipped, avoiding the costly kvm_mmu_pte_write.
Signed-Off-By: default avatarLuca Tettamanti <kronos.it@gmail.com>
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent 02c03a32
...@@ -1170,8 +1170,10 @@ static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, ...@@ -1170,8 +1170,10 @@ static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
return 0; return 0;
mark_page_dirty(vcpu->kvm, gpa >> PAGE_SHIFT); mark_page_dirty(vcpu->kvm, gpa >> PAGE_SHIFT);
virt = kmap_atomic(page, KM_USER0); virt = kmap_atomic(page, KM_USER0);
kvm_mmu_pte_write(vcpu, gpa, virt + offset, val, bytes); if (memcmp(virt + offset_in_page(gpa), val, bytes)) {
memcpy(virt + offset_in_page(gpa), val, bytes); kvm_mmu_pte_write(vcpu, gpa, virt + offset, val, bytes);
memcpy(virt + offset_in_page(gpa), val, bytes);
}
kunmap_atomic(virt, KM_USER0); kunmap_atomic(virt, KM_USER0);
return 1; return 1;
} }
......
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