Re: [PATCH 1/2] KVM: Stop KVM_PRE_FAULT_MEMORY when the vCPU's dirty ring is full

From: Fuad Tabba

Date: Tue Nov 10 2026 - 12:34:57 EST


Hi Sean,

On Tue, 10 Nov 2026 15:48:37 +0000, Sean Christopherson
<seanjc@xxxxxxxxxx> wrote:
> On Tue, Nov 10, 2026, Fuad Tabba wrote:
> > diff --git 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.

The series is LLM-assisted, but the comment was actually me.

> > + 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.

Will do.

> 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;

I'll send it as its own patch.

Cheers,
/fuad