Re: [PATCH v3 2/3] KVM: Warn userspace against ioctls while an exit is pending
From: Fuad Tabba
Date: Mon Nov 23 2026 - 10:24:43 EST
On Mon, 23 Nov 2026 at 15:09, Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx> wrote:
[...]
> Very much agree with Sean's take here that we should instil sufficient fear in
> users at doing silly things (also in general not only KVM :).
>
> I wonder if we could add some specific examples or broad description of why it's
> unwise for better effect, though? Comments below.
>
> In general though:
>
> Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
Thanks!
> > ---
> > Documentation/virt/kvm/api.rst | 11 +++++++----
> > 1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> > index 89eb6be9bc6e3..980ef0cdc1c91 100644
> > --- a/Documentation/virt/kvm/api.rst
> > +++ b/Documentation/virt/kvm/api.rst
> > @@ -6974,10 +6974,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.
>
> Perhaps worth saying why? E.g. (as I understand it) that for these exits the
> operation is only completed on the next KVM_RUN, and that KVM relies on state
> left over from the exit (including parts of struct kvm_run such as exit_reason)
> to do so, so any ioctl invoked in between might clobber that state?
>
> I see you intentionally avoided documenting the pre-fault case on its own, but
> with the above stated I think a concrete example might be example here, like
> e.g.:
>
> "For example, if you were to ... that would result in ... which would absolutely
> ruin your day because ..."
>
> Kinda thing :)
:)
I'm not sure it would help, tbh. I think a reason or an example would
have the effect Sean wanted to avoid [1], where a reader takes an
ioctl that doesn't match it to be safe.
Cheers,
/fuad
[1] https://lore.kernel.org/all/av5CBjbeidUUWiLq@xxxxxxxxxxxxxxx.internal/