diff options
author | Avi Kivity <avi@qumranet.com> | 2007-05-01 07:16:52 -0400 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2007-07-16 05:05:38 -0400 |
commit | 09072daf37abbfe8e2d5018dd913f229c76190f7 (patch) | |
tree | dbccbe493a9412cb89bd48b7c0c8ec21f70cf091 /drivers/kvm | |
parent | 621358455ae043ab39bc3481f13b101bd6016c8d (diff) |
KVM: Unify kvm_mmu_pre_write() and kvm_mmu_post_write()
Instead of calling two functions and repeating expensive checks, call one
function and provide it with before/after information.
Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm')
-rw-r--r-- | drivers/kvm/kvm.h | 4 | ||||
-rw-r--r-- | drivers/kvm/kvm_main.c | 4 | ||||
-rw-r--r-- | drivers/kvm/mmu.c | 11 |
3 files changed, 8 insertions, 11 deletions
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h index 7facebd1911d..11c519e8085a 100644 --- a/drivers/kvm/kvm.h +++ b/drivers/kvm/kvm.h | |||
@@ -525,8 +525,8 @@ int kvm_write_guest(struct kvm_vcpu *vcpu, | |||
525 | 525 | ||
526 | unsigned long segment_base(u16 selector); | 526 | unsigned long segment_base(u16 selector); |
527 | 527 | ||
528 | void kvm_mmu_pre_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes); | 528 | void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, |
529 | void kvm_mmu_post_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes); | 529 | const u8 *old, const u8 *new, int bytes); |
530 | int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva); | 530 | int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva); |
531 | void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu); | 531 | void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu); |
532 | 532 | ||
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c index 7d682586423b..b6ad9c6f2efe 100644 --- a/drivers/kvm/kvm_main.c +++ b/drivers/kvm/kvm_main.c | |||
@@ -1071,18 +1071,18 @@ static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, | |||
1071 | { | 1071 | { |
1072 | struct page *page; | 1072 | struct page *page; |
1073 | void *virt; | 1073 | void *virt; |
1074 | unsigned offset = offset_in_page(gpa); | ||
1074 | 1075 | ||
1075 | if (((gpa + bytes - 1) >> PAGE_SHIFT) != (gpa >> PAGE_SHIFT)) | 1076 | if (((gpa + bytes - 1) >> PAGE_SHIFT) != (gpa >> PAGE_SHIFT)) |
1076 | return 0; | 1077 | return 0; |
1077 | page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT); | 1078 | page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT); |
1078 | if (!page) | 1079 | if (!page) |
1079 | return 0; | 1080 | return 0; |
1080 | kvm_mmu_pre_write(vcpu, gpa, bytes); | ||
1081 | mark_page_dirty(vcpu->kvm, gpa >> PAGE_SHIFT); | 1081 | mark_page_dirty(vcpu->kvm, gpa >> PAGE_SHIFT); |
1082 | virt = kmap_atomic(page, KM_USER0); | 1082 | virt = kmap_atomic(page, KM_USER0); |
1083 | kvm_mmu_pte_write(vcpu, gpa, virt + offset, val, bytes); | ||
1083 | memcpy(virt + offset_in_page(gpa), val, bytes); | 1084 | memcpy(virt + offset_in_page(gpa), val, bytes); |
1084 | kunmap_atomic(virt, KM_USER0); | 1085 | kunmap_atomic(virt, KM_USER0); |
1085 | kvm_mmu_post_write(vcpu, gpa, bytes); | ||
1086 | return 1; | 1086 | return 1; |
1087 | } | 1087 | } |
1088 | 1088 | ||
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c index 2277b7cd118c..b3a83ef2cf07 100644 --- a/drivers/kvm/mmu.c +++ b/drivers/kvm/mmu.c | |||
@@ -1118,7 +1118,7 @@ out: | |||
1118 | return r; | 1118 | return r; |
1119 | } | 1119 | } |
1120 | 1120 | ||
1121 | static void mmu_pre_write_zap_pte(struct kvm_vcpu *vcpu, | 1121 | static void mmu_pte_write_zap_pte(struct kvm_vcpu *vcpu, |
1122 | struct kvm_mmu_page *page, | 1122 | struct kvm_mmu_page *page, |
1123 | u64 *spte) | 1123 | u64 *spte) |
1124 | { | 1124 | { |
@@ -1137,7 +1137,8 @@ static void mmu_pre_write_zap_pte(struct kvm_vcpu *vcpu, | |||
1137 | *spte = 0; | 1137 | *spte = 0; |
1138 | } | 1138 | } |
1139 | 1139 | ||
1140 | void kvm_mmu_pre_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes) | 1140 | void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, |
1141 | const u8 *old, const u8 *new, int bytes) | ||
1141 | { | 1142 | { |
1142 | gfn_t gfn = gpa >> PAGE_SHIFT; | 1143 | gfn_t gfn = gpa >> PAGE_SHIFT; |
1143 | struct kvm_mmu_page *page; | 1144 | struct kvm_mmu_page *page; |
@@ -1206,16 +1207,12 @@ void kvm_mmu_pre_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes) | |||
1206 | spte = __va(page->page_hpa); | 1207 | spte = __va(page->page_hpa); |
1207 | spte += page_offset / sizeof(*spte); | 1208 | spte += page_offset / sizeof(*spte); |
1208 | while (npte--) { | 1209 | while (npte--) { |
1209 | mmu_pre_write_zap_pte(vcpu, page, spte); | 1210 | mmu_pte_write_zap_pte(vcpu, page, spte); |
1210 | ++spte; | 1211 | ++spte; |
1211 | } | 1212 | } |
1212 | } | 1213 | } |
1213 | } | 1214 | } |
1214 | 1215 | ||
1215 | void kvm_mmu_post_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes) | ||
1216 | { | ||
1217 | } | ||
1218 | |||
1219 | int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva) | 1216 | int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva) |
1220 | { | 1217 | { |
1221 | gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, gva); | 1218 | gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, gva); |