diff options
author | Paul Mackerras <paulus@samba.org> | 2013-04-18 15:51:04 -0400 |
---|---|---|
committer | Alexander Graf <agraf@suse.de> | 2013-04-26 14:27:13 -0400 |
commit | c35635efdc0312e013ebda1c8f3b5dd038c0d0e7 (patch) | |
tree | b4a0f054975b1d7530a9d7de85f8ac1b9fe8c60c /arch/powerpc/kvm/book3s_64_mmu_hv.c | |
parent | a1b4a0f6064aacad0d708105e6f60a06e93fbf37 (diff) |
KVM: PPC: Book3S HV: Report VPA and DTL modifications in dirty map
At present, the KVM_GET_DIRTY_LOG ioctl doesn't report modifications
done by the host to the virtual processor areas (VPAs) and dispatch
trace logs (DTLs) registered by the guest. This is because those
modifications are done either in real mode or in the host kernel
context, and in neither case does the access go through the guest's
HPT, and thus no change (C) bit gets set in the guest's HPT.
However, the changes done by the host do need to be tracked so that
the modified pages get transferred when doing live migration. In
order to track these modifications, this adds a dirty flag to the
struct representing the VPA/DTL areas, and arranges to set the flag
when the VPA/DTL gets modified by the host. Then, when we are
collecting the dirty log, we also check the dirty flags for the
VPA and DTL for each vcpu and set the relevant bit in the dirty log
if necessary. Doing this also means we now need to keep track of
the guest physical address of the VPA/DTL areas.
So as not to lose track of modifications to a VPA/DTL area when it gets
unregistered, or when a new area gets registered in its place, we need
to transfer the dirty state to the rmap chain. This adds code to
kvmppc_unpin_guest_page() to do that if the area was dirty. To simplify
that code, we now require that all VPA, DTL and SLB shadow buffer areas
fit within a single host page. Guests already comply with this
requirement because pHyp requires that these areas not cross a 4k
boundary.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'arch/powerpc/kvm/book3s_64_mmu_hv.c')
-rw-r--r-- | arch/powerpc/kvm/book3s_64_mmu_hv.c | 61 |
1 files changed, 52 insertions, 9 deletions
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index d641a6634b02..69efe0d6cedc 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c | |||
@@ -1099,11 +1099,30 @@ static int kvm_test_clear_dirty(struct kvm *kvm, unsigned long *rmapp) | |||
1099 | return ret; | 1099 | return ret; |
1100 | } | 1100 | } |
1101 | 1101 | ||
1102 | static void harvest_vpa_dirty(struct kvmppc_vpa *vpa, | ||
1103 | struct kvm_memory_slot *memslot, | ||
1104 | unsigned long *map) | ||
1105 | { | ||
1106 | unsigned long gfn; | ||
1107 | |||
1108 | if (!vpa->dirty || !vpa->pinned_addr) | ||
1109 | return; | ||
1110 | gfn = vpa->gpa >> PAGE_SHIFT; | ||
1111 | if (gfn < memslot->base_gfn || | ||
1112 | gfn >= memslot->base_gfn + memslot->npages) | ||
1113 | return; | ||
1114 | |||
1115 | vpa->dirty = false; | ||
1116 | if (map) | ||
1117 | __set_bit_le(gfn - memslot->base_gfn, map); | ||
1118 | } | ||
1119 | |||
1102 | long kvmppc_hv_get_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot, | 1120 | long kvmppc_hv_get_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot, |
1103 | unsigned long *map) | 1121 | unsigned long *map) |
1104 | { | 1122 | { |
1105 | unsigned long i; | 1123 | unsigned long i; |
1106 | unsigned long *rmapp; | 1124 | unsigned long *rmapp; |
1125 | struct kvm_vcpu *vcpu; | ||
1107 | 1126 | ||
1108 | preempt_disable(); | 1127 | preempt_disable(); |
1109 | rmapp = memslot->arch.rmap; | 1128 | rmapp = memslot->arch.rmap; |
@@ -1112,6 +1131,15 @@ long kvmppc_hv_get_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot, | |||
1112 | __set_bit_le(i, map); | 1131 | __set_bit_le(i, map); |
1113 | ++rmapp; | 1132 | ++rmapp; |
1114 | } | 1133 | } |
1134 | |||
1135 | /* Harvest dirty bits from VPA and DTL updates */ | ||
1136 | /* Note: we never modify the SLB shadow buffer areas */ | ||
1137 | kvm_for_each_vcpu(i, vcpu, kvm) { | ||
1138 | spin_lock(&vcpu->arch.vpa_update_lock); | ||
1139 | harvest_vpa_dirty(&vcpu->arch.vpa, memslot, map); | ||
1140 | harvest_vpa_dirty(&vcpu->arch.dtl, memslot, map); | ||
1141 | spin_unlock(&vcpu->arch.vpa_update_lock); | ||
1142 | } | ||
1115 | preempt_enable(); | 1143 | preempt_enable(); |
1116 | return 0; | 1144 | return 0; |
1117 | } | 1145 | } |
@@ -1123,7 +1151,7 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long gpa, | |||
1123 | unsigned long gfn = gpa >> PAGE_SHIFT; | 1151 | unsigned long gfn = gpa >> PAGE_SHIFT; |
1124 | struct page *page, *pages[1]; | 1152 | struct page *page, *pages[1]; |
1125 | int npages; | 1153 | int npages; |
1126 | unsigned long hva, psize, offset; | 1154 | unsigned long hva, offset; |
1127 | unsigned long pa; | 1155 | unsigned long pa; |
1128 | unsigned long *physp; | 1156 | unsigned long *physp; |
1129 | int srcu_idx; | 1157 | int srcu_idx; |
@@ -1155,14 +1183,9 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long gpa, | |||
1155 | } | 1183 | } |
1156 | srcu_read_unlock(&kvm->srcu, srcu_idx); | 1184 | srcu_read_unlock(&kvm->srcu, srcu_idx); |
1157 | 1185 | ||
1158 | psize = PAGE_SIZE; | 1186 | offset = gpa & (PAGE_SIZE - 1); |
1159 | if (PageHuge(page)) { | ||
1160 | page = compound_head(page); | ||
1161 | psize <<= compound_order(page); | ||
1162 | } | ||
1163 | offset = gpa & (psize - 1); | ||
1164 | if (nb_ret) | 1187 | if (nb_ret) |
1165 | *nb_ret = psize - offset; | 1188 | *nb_ret = PAGE_SIZE - offset; |
1166 | return page_address(page) + offset; | 1189 | return page_address(page) + offset; |
1167 | 1190 | ||
1168 | err: | 1191 | err: |
@@ -1170,11 +1193,31 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long gpa, | |||
1170 | return NULL; | 1193 | return NULL; |
1171 | } | 1194 | } |
1172 | 1195 | ||
1173 | void kvmppc_unpin_guest_page(struct kvm *kvm, void *va) | 1196 | void kvmppc_unpin_guest_page(struct kvm *kvm, void *va, unsigned long gpa, |
1197 | bool dirty) | ||
1174 | { | 1198 | { |
1175 | struct page *page = virt_to_page(va); | 1199 | struct page *page = virt_to_page(va); |
1200 | struct kvm_memory_slot *memslot; | ||
1201 | unsigned long gfn; | ||
1202 | unsigned long *rmap; | ||
1203 | int srcu_idx; | ||
1176 | 1204 | ||
1177 | put_page(page); | 1205 | put_page(page); |
1206 | |||
1207 | if (!dirty || !kvm->arch.using_mmu_notifiers) | ||
1208 | return; | ||
1209 | |||
1210 | /* We need to mark this page dirty in the rmap chain */ | ||
1211 | gfn = gpa >> PAGE_SHIFT; | ||
1212 | srcu_idx = srcu_read_lock(&kvm->srcu); | ||
1213 | memslot = gfn_to_memslot(kvm, gfn); | ||
1214 | if (memslot) { | ||
1215 | rmap = &memslot->arch.rmap[gfn - memslot->base_gfn]; | ||
1216 | lock_rmap(rmap); | ||
1217 | *rmap |= KVMPPC_RMAP_CHANGED; | ||
1218 | unlock_rmap(rmap); | ||
1219 | } | ||
1220 | srcu_read_unlock(&kvm->srcu, srcu_idx); | ||
1178 | } | 1221 | } |
1179 | 1222 | ||
1180 | /* | 1223 | /* |