Re: [PATCH 1/2] KVM: Stop KVM_PRE_FAULT_MEMORY when the vCPU's dirty ring is full
From: Sean Christopherson
Date: Tue Nov 10 2026 - 11:01:22 EST
On Tue, Nov 10, 2026, Fuad Tabba wrote:
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index cf4cb586f1407..da1b76ceb65e3 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -4461,6 +4461,12 @@ static int kvm_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
> break;
> }
>
> + /* Like KVM_RUN: only the iteration crossing the soft limit uses the reserve. */
Please don't include AI comments verbatim.
> + if (vcpu->kvm->dirty_ring_size && kvm_dirty_ring_soft_full(&vcpu->dirty_ring)) {
Eh, I vote to just use kvm_dirty_ring_check_request(), I don't see any harm in
clobbering vcpu->run->exit_reason.
Side topic, kvm_dirty_ring_check_request() is rather confusing (clears and then
re-sets the requests). AFAICT, it can be this instead:
lockdep_assert_held(vcpu->mutex);
/*
* The vCPU isn't runnable when the dirty ring becomes soft full. Keep
* the requests set until the dirty pages are harvested and the dirty
* ring is reset by userspace. Note, checking if the ring is soft-full
* can get a false positive, but not a false negative, because only the
* vCPU can add entries to the ring, and its mutex is held.
*/
if (kvm_test_request(KVM_REQ_DIRTY_RING_SOFT_FULL, vcpu) &&
kvm_dirty_ring_soft_full(&vcpu->dirty_ring)) {
vcpu->run->exit_reason = KVM_EXIT_DIRTY_RING_FULL;
trace_kvm_dirty_ring_exit(vcpu);
return true;
}
kvm_clear_request(KVM_REQ_DIRTY_RING_SOFT_FULL, vcpu);
return false;
> + r = -ENOSPC;
> + break;
> + }
> +
> r = kvm_arch_vcpu_pre_fault_memory(vcpu, range);
> if (WARN_ON_ONCE(r == 0 || r == -EIO))
> break;
> --
> 2.47.3
>