Skip to content

Commit 78b7463

Browse files
Paul Durrantsean-jc
authored andcommitted
KVM: pfncache: add a mark-dirty helper
At the moment pages are marked dirty by open-coded calls to mark_page_dirty_in_slot(), directly deferefencing the gpa and memslot from the cache. After a subsequent patch these may not always be set so add a helper now so that caller will protected from the need to know about this detail. Signed-off-by: Paul Durrant <pdurrant@amazon.com> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Link: https://lore.kernel.org/r/20240215152916.1158-5-paul@xen.org [sean: decrease indentation, use gpa_to_gfn()] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 4438355 commit 78b7463

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3160,7 +3160,7 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v,
31603160

31613161
guest_hv_clock->version = ++vcpu->hv_clock.version;
31623162

3163-
mark_page_dirty_in_slot(v->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT);
3163+
kvm_gpc_mark_dirty_in_slot(gpc);
31643164
read_unlock_irqrestore(&gpc->lock, flags);
31653165

31663166
trace_kvm_pvclock_update(v->vcpu_id, &vcpu->hv_clock);

arch/x86/kvm/xen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,11 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
453453
}
454454

455455
if (user_len2) {
456-
mark_page_dirty_in_slot(v->kvm, gpc2->memslot, gpc2->gpa >> PAGE_SHIFT);
456+
kvm_gpc_mark_dirty_in_slot(gpc2);
457457
read_unlock(&gpc2->lock);
458458
}
459459

460-
mark_page_dirty_in_slot(v->kvm, gpc1->memslot, gpc1->gpa >> PAGE_SHIFT);
460+
kvm_gpc_mark_dirty_in_slot(gpc1);
461461
read_unlock_irqrestore(&gpc1->lock, flags);
462462
}
463463

@@ -565,7 +565,7 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)
565565
WRITE_ONCE(vi->evtchn_upcall_pending, 1);
566566
}
567567

568-
mark_page_dirty_in_slot(v->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT);
568+
kvm_gpc_mark_dirty_in_slot(gpc);
569569
read_unlock_irqrestore(&gpc->lock, flags);
570570

571571
/* For the per-vCPU lapic vector, deliver it as MSI. */

include/linux/kvm_host.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,16 @@ static inline bool kvm_is_error_gpa(struct kvm *kvm, gpa_t gpa)
17951795
return kvm_is_error_hva(hva);
17961796
}
17971797

1798+
static inline void kvm_gpc_mark_dirty_in_slot(struct gfn_to_pfn_cache *gpc)
1799+
{
1800+
lockdep_assert_held(&gpc->lock);
1801+
1802+
if (!gpc->memslot)
1803+
return;
1804+
1805+
mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpa_to_gfn(gpc->gpa));
1806+
}
1807+
17981808
enum kvm_stat_kind {
17991809
KVM_STAT_VM,
18001810
KVM_STAT_VCPU,

0 commit comments

Comments
 (0)