Re: [PATCH v3 7/8] KVM: x86: WARN if MOV DR emulation hits a "too late" #GP
From: Jim Mattson
Date: Mon Jun 15 2026 - 14:31:05 EST
On Fri, Jun 12, 2026 at 4:02 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> WARN if ->set_dr() => kvm_set_dr() fails when emulating a MOV DR write,
> as the emulator _must_ pre-check for #GPs in order to get the event
> priority right when emulating MOV DR for L2 on SVM (all exceptions have
> higher priority than the instruction intercept).
>
> Opportunistically update the comment as the blurb about "#UD" being
> checked is incomplete and misleading.
>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> ---
> arch/x86/kvm/emulate.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index b1799ed01939..e030ef9b9744 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -3298,8 +3298,12 @@ static int em_dr_write(struct x86_emulate_ctxt *ctxt)
> else
> val = ctxt->src.val & ~0U;
>
> - /* #UD condition is already handled. */
> - if (ctxt->ops->set_dr(ctxt, ctxt->modrm_reg, val))
> + /*
> + * A #GP due to an illegal value should be impossible at this point, as
> + * such #GPs have priority over MOV DR intercepts on SVM, i.e. KVM must
> + * manually check the value *before* emulating the write.
> + */
This comment seems confusing to me. Isn't an illegal value impossible
simply because we already called check_dr_write()?
> + if (WARN_ON_ONCE(ctxt->ops->set_dr(ctxt, ctxt->modrm_reg, val)))
> return emulate_gp(ctxt, 0);
>
> /* Disable writeback. */
> --
> 2.54.0.1136.gdb2ca164c4-goog
>
>