Skip to content

Commit 4438355

Browse files
Paul Durrantsean-jc
authored andcommitted
KVM: x86/xen: mark guest pages dirty with the pfncache lock held
Sampling gpa and memslot from an unlocked pfncache may yield inconsistent values so, since there is no problem with calling mark_page_dirty_in_slot() with the pfncache lock held, relocate the calls in kvm_xen_update_runstate_guest() and kvm_xen_inject_pending_events() accordingly. Signed-off-by: Paul Durrant <pdurrant@amazon.com> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Link: https://lore.kernel.org/r/20240215152916.1158-4-paul@xen.org Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 41496ff commit 4438355

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

arch/x86/kvm/xen.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,13 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
452452
smp_wmb();
453453
}
454454

455-
if (user_len2)
455+
if (user_len2) {
456+
mark_page_dirty_in_slot(v->kvm, gpc2->memslot, gpc2->gpa >> PAGE_SHIFT);
456457
read_unlock(&gpc2->lock);
457-
458-
read_unlock_irqrestore(&gpc1->lock, flags);
458+
}
459459

460460
mark_page_dirty_in_slot(v->kvm, gpc1->memslot, gpc1->gpa >> PAGE_SHIFT);
461-
if (user_len2)
462-
mark_page_dirty_in_slot(v->kvm, gpc2->memslot, gpc2->gpa >> PAGE_SHIFT);
461+
read_unlock_irqrestore(&gpc1->lock, flags);
463462
}
464463

465464
void kvm_xen_update_runstate(struct kvm_vcpu *v, int state)
@@ -565,13 +564,13 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)
565564
: "0" (evtchn_pending_sel32));
566565
WRITE_ONCE(vi->evtchn_upcall_pending, 1);
567566
}
567+
568+
mark_page_dirty_in_slot(v->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT);
568569
read_unlock_irqrestore(&gpc->lock, flags);
569570

570571
/* For the per-vCPU lapic vector, deliver it as MSI. */
571572
if (v->arch.xen.upcall_vector)
572573
kvm_xen_inject_vcpu_vector(v);
573-
574-
mark_page_dirty_in_slot(v->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT);
575574
}
576575

577576
int __kvm_xen_has_interrupt(struct kvm_vcpu *v)

0 commit comments

Comments
 (0)