From: Sean Christopherson <seanjc@google.com>
To: Jim Mattson <jmattson@google.com>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
"Carlos López" <clopez@suse.de>,
"Maciej W . Rozycki" <macro@orcam.me.uk>
Subject: Re: [PATCH v3 7/8] KVM: x86: WARN if MOV DR emulation hits a "too late" #GP
Date: Mon, 15 Jun 2026 12:08:43 -0700 [thread overview]
Message-ID: <ajBNuya3czCahy4K@google.com> (raw)
In-Reply-To: <CALMp9eTDfP908gH7OH8HAJKAsaixNfA5dHnPXBKFquQRFVCxFA@mail.gmail.com>
On Mon, Jun 15, 2026, Jim Mattson wrote:
> On Fri, Jun 12, 2026 at 4:02 PM Sean Christopherson <seanjc@google.com> 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@google.com>
> > ---
> > 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()?
Yeah. I'm trying to explain why KVM WARNs, and also to guard against dropping
the value checks in check_dr_write() as future "cleanups".
Is this better?
/*
* Yell if the DR write is rejected, as all inputs have been validated.
* KVM must manually check for exceptions *before* emulating the write,
* as all exceptions have priority over MOV DR intercepts on SVM.
*/
> > + 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
> >
> >
next prev parent reply other threads:[~2026-06-15 19:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 23:01 [PATCH v3 0/8] KVM: x86: Fix emulated MOV DR{4,5} #GP bugs Sean Christopherson
2026-06-12 23:01 ` [PATCH v3 1/8] KVM: x86: Treat any non-zero return from set_dr() as a faulting condition Sean Christopherson
2026-06-15 17:46 ` Jim Mattson
2026-06-12 23:01 ` [PATCH v3 2/8] KVM: x86: Prioritize DR7.GD #DB over #GP due to illegal DR6/7 value Sean Christopherson
2026-06-15 17:51 ` Jim Mattson
2026-06-12 23:01 ` [PATCH v3 3/8] KVM: x86: Manually check DR4/5 write values to fix SVM intercept priority Sean Christopherson
2026-06-12 23:28 ` sashiko-bot
2026-06-15 18:04 ` Jim Mattson
2026-06-12 23:01 ` [PATCH v3 4/8] KVM: x86: Prioritize #UD on MOV DR over #GP due to non-zero CPL Sean Christopherson
2026-06-15 18:07 ` Jim Mattson
2026-06-12 23:01 ` [PATCH v3 5/8] KVM: VMX: Prioritize DR7.GD=1 #DB over CPL>0 #GP on Intel Sean Christopherson
2026-06-15 18:14 ` Jim Mattson
2026-06-12 23:01 ` [PATCH v3 6/8] KVM: x86: Use kvm_dr{6,7}_valid() to check DR{4,5,6,7} write values in emulator Sean Christopherson
2026-06-15 17:24 ` Jim Mattson
2026-06-12 23:01 ` [PATCH v3 7/8] KVM: x86: WARN if MOV DR emulation hits a "too late" #GP Sean Christopherson
2026-06-15 18:30 ` Jim Mattson
2026-06-15 19:08 ` Sean Christopherson [this message]
2026-06-15 20:35 ` Jim Mattson
2026-06-12 23:01 ` [PATCH v3 8/8] KVM: x86: Read CR4.DE in emulator if and only if accessing DR4 or DR5 Sean Christopherson
2026-06-15 17:40 ` Jim Mattson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ajBNuya3czCahy4K@google.com \
--to=seanjc@google.com \
--cc=clopez@suse.de \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=macro@orcam.me.uk \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox