Re: [PATCH v2 1/2] KVM: Stop KVM_PRE_FAULT_MEMORY when the vCPU's dirty ring is full
From: Sean Christopherson
Date: Wed Nov 18 2026 - 19:25:54 EST
On Tue, Nov 17, 2026, Fuad Tabba wrote:
> > But the overflow bug only applies to x86 (see below), so is this something
> > we should worry about at all?
>
> The ring overflows on arm64 too (below). As for exit_reason, I asked
> Sean about the arm64 MMIO case on v1, and his answer was that a VMM
> that pre-faults between a KVM_EXIT_MMIO return and the next KVM_RUN
> "gets to deal with the fallout" [1]. I think the same goes for riscv's
> exits.
>
> [...]
> > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> [...]
> > > The dirty ring can get full. When it happens, the KVM_RUN of the
> > > -vcpu will return with exit reason KVM_EXIT_DIRTY_RING_FULL.
> > > +vcpu will return with exit reason KVM_EXIT_DIRTY_RING_FULL, and
> > > +KVM_PRE_FAULT_MEMORY on the vcpu will process no more pages until the
> > > +ring has been harvested and reset.
> >
> > Maybe worth mentioning the exit_reason thing if we keep this arch-generic?
>
> Sure, I'll document that userspace should complete a pending exit with
> KVM_RUN before it pre-faults on that vCPU.
If we're going to do a documentation update, I vote to keep it vague and scary,
otherwise readers might think the exception proves the rule. I.e. if we say
that KVM_PRE_FAULT_MEMORY isn't supported, then userspace might think all other
ioctls are safe, which is most definitely not the case. E.g. something like
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index e95c9cda085d..45dc1e3c0b03 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -6971,10 +6971,13 @@ to the byte array.
The pending state of the operation is not preserved in state which is
visible to userspace, thus userspace should ensure that the operation is
- completed before performing a live migration. Userspace can re-enter the
- guest with an unmasked signal pending or with the immediate_exit field set
- to complete pending operations without allowing any further instructions
- to be executed.
+ completed before performing a live migration. In general, userspace should
+ exercise extreme caution when invoking ioctls other than KVM_RUN prior to
+ completing the original operation.
+
+ Userspace can re-enter the guest with an unmasked signal pending or with
+ the immediate_exit field set to complete pending operations without
+ allowing any further instructions to be executed.
::