Re: KVM exit to userspace on WFI

From: Marc Zyngier
Date: Fri Oct 20 2023 - 15:56:39 EST


Hi Jan,

On Fri, 20 Oct 2023 19:45:05 +0100,
Jan Henrik Weinstock <jan@xxxxxx> wrote:
>
> Hi all,
>
> I am looking for a way to have KVM_RUN exit back to userspace once the
> vcpu encounters a WFI. It seems the kvm_run->request_interrupt_window
> flag is currently ignored by arm64.

Well, that's consistent with arm64 not being an x86 implementation. We
can inject interrupts any time, and there is no notion of "interrupt
window".

> So my solution thus far is to
> patch kvm_handle_wfx in arch/arm64/kvm/handle_exit.c and return to
> userspace with KVM_EXIT_IRQ_WINDOW_OPEN - working example attached.
> Any chance to get this (or something similar) mainline?

Certainly not as such. For start, this won't hit all WFIs, but only
those that actively trap. And we don't even *try* to trap WFx in a
number of cases (vcpu alone in its run queue and/or direct injection).
There isn't even any guarantee that WFx is anything other than a NOP
(it is architecturally only a hint), in which case no trap applies.

So your "working example" really isn't one, as the architecture
doesn't give you a way to do what you're asking for. If you want to
cause an exit, writing to 'immediate_exit' and delivering a signal is
the way.

Thanks,

M.

--
Without deviation from the norm, progress is not possible.