diff options
author | Avi Kivity <avi@qumranet.com> | 2007-05-01 09:53:31 -0400 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2007-07-16 05:05:39 -0400 |
commit | 0028425f647b6b78a0de8810d6b782fc3ce6c272 (patch) | |
tree | 8afece215ec531f993c28cc3dee17b0c2c1dd3b1 /drivers/kvm/mmu.c | |
parent | fce0657ff9f14f6b1f147b5fcd6db2f54c06424e (diff) |
KVM: Update shadow pte on write to guest pte
A typical demand page/copy on write pattern is:
- page fault on vaddr
- kvm propagates fault to guest
- guest handles fault, updates pte
- kvm traps write, clears shadow pte, resumes guest
- guest returns to userspace, re-faults on same vaddr
- kvm installs shadow pte, resumes guest
- guest continues
So, three vmexits for a single guest page fault. But if instead of clearing
the page table entry, we update to correspond to the value that the guest
has just written, we eliminate the third vmexit.
This patch does exactly that, reducing kbuild time by about 10%.
Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/mmu.c')
-rw-r--r-- | drivers/kvm/mmu.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c index 23dc4612026b..9ec3df90dbb8 100644 --- a/drivers/kvm/mmu.c +++ b/drivers/kvm/mmu.c | |||
@@ -1137,6 +1137,20 @@ static void mmu_pte_write_zap_pte(struct kvm_vcpu *vcpu, | |||
1137 | *spte = 0; | 1137 | *spte = 0; |
1138 | } | 1138 | } |
1139 | 1139 | ||
1140 | static void mmu_pte_write_new_pte(struct kvm_vcpu *vcpu, | ||
1141 | struct kvm_mmu_page *page, | ||
1142 | u64 *spte, | ||
1143 | const void *new, int bytes) | ||
1144 | { | ||
1145 | if (page->role.level != PT_PAGE_TABLE_LEVEL) | ||
1146 | return; | ||
1147 | |||
1148 | if (page->role.glevels == PT32_ROOT_LEVEL) | ||
1149 | paging32_update_pte(vcpu, page, spte, new, bytes); | ||
1150 | else | ||
1151 | paging64_update_pte(vcpu, page, spte, new, bytes); | ||
1152 | } | ||
1153 | |||
1140 | void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, | 1154 | void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, |
1141 | const u8 *old, const u8 *new, int bytes) | 1155 | const u8 *old, const u8 *new, int bytes) |
1142 | { | 1156 | { |
@@ -1212,6 +1226,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, | |||
1212 | spte += page_offset / sizeof(*spte); | 1226 | spte += page_offset / sizeof(*spte); |
1213 | while (npte--) { | 1227 | while (npte--) { |
1214 | mmu_pte_write_zap_pte(vcpu, page, spte); | 1228 | mmu_pte_write_zap_pte(vcpu, page, spte); |
1229 | mmu_pte_write_new_pte(vcpu, page, spte, new, bytes); | ||
1215 | ++spte; | 1230 | ++spte; |
1216 | } | 1231 | } |
1217 | } | 1232 | } |