All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wanpeng Li <kernellwp@gmail.com>
To: Sean Christopherson <seanjc@google.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kvm <kvm@vger.kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>
Subject: Re: [PATCH] KVM: X86: Fix warning caused by stale emulation context
Date: Tue, 25 May 2021 09:17:10 +0800	[thread overview]
Message-ID: <CANRm+CyA=p+_bsP=3vZXMKnCqYKvE0rNR4xEfE6nUyg5Dmznyg@mail.gmail.com> (raw)
In-Reply-To: <YKvHFbPfGnaQ4huw@google.com>

On Mon, 24 May 2021 at 23:32, Sean Christopherson <seanjc@google.com> wrote:
>
> On Sun, May 23, 2021, Wanpeng Li wrote:
> > From: Wanpeng Li <wanpengli@tencent.com>
> >
> > Reported by syzkaller:
> >
> >   WARNING: CPU: 7 PID: 10526 at /home/kernel/ssd/linux/arch/x86/kvm//x86.c:7621 x86_emulate_instruction+0x41b/0x510 [kvm]
> >   RIP: 0010:x86_emulate_instruction+0x41b/0x510 [kvm]
> >   Call Trace:
> >    kvm_mmu_page_fault+0x126/0x8f0 [kvm]
> >    vmx_handle_exit+0x11e/0x680 [kvm_intel]
> >    vcpu_enter_guest+0xd95/0x1b40 [kvm]
> >    kvm_arch_vcpu_ioctl_run+0x377/0x6a0 [kvm]
> >    kvm_vcpu_ioctl+0x389/0x630 [kvm]
> >    __x64_sys_ioctl+0x8e/0xd0
> >    do_syscall_64+0x3c/0xb0
> >    entry_SYSCALL_64_after_hwframe+0x44/0xae
> >
> > Commit 4a1e10d5b5d8c (KVM: x86: handle hardware breakpoints during emulation())
> > adds hardware breakpoints check before emulation the instruction and parts of
> > emulation context initialization, actually we don't have EMULTYPE_NO_DECODE flag
> > here and the emulation context will not be reused. Commit c8848cee74ff (KVM: x86:
> > set ctxt->have_exception in x86_decode_insn()) triggers the warning because it
> > catches the stale emulation context has #UD, however, it is not during instruction
> > decoding which should result in EMULATION_FAILED. This patch fixes it by moving
> > the second part emulation context initialization before hardware breakpoints check.
> >
> > syzkaller source: https://syzkaller.appspot.com/x/repro.c?x=134683fdd00000
> >
> > Reported-by: syzbot+71271244f206d17f6441@syzkaller.appspotmail.com
> > Fixes: 4a1e10d5b5d8 (KVM: x86: handle hardware breakpoints during emulation)
> > Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> > ---
> >  arch/x86/kvm/x86.c | 14 +++++++-------
> >  1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index bbc4e04..eca69f9 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -7552,6 +7552,13 @@ int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_type,
> >
> >       init_emulate_ctxt(vcpu);
> >
> > +     ctxt->interruptibility = 0;
> > +     ctxt->have_exception = false;
> > +     ctxt->exception.vector = -1;
> > +     ctxt->perm_ok = false;
>
> What about moving this block all the way into init_emulate_ctxt()?
>
> > +     ctxt->ud = emulation_type & EMULTYPE_TRAP_UD;
>
> This can be left where it is since ctxt->ud is consumed only by x86_decode_insn().
> I don't have a strong preference as it really only matters for the backport.  For
> upstream, we can kill it off in a follow-up patch by passing emulation_type to
> x86_decode_insn() and dropping ctxt->ud altogether.  Tracking that info in ctxt
> for literally one call is silly.

Good suggestion, will do in v2.

    Wanpeng

      reply	other threads:[~2021-05-25  1:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24  4:35 [PATCH] KVM: X86: Fix warning caused by stale emulation context Wanpeng Li
2021-05-24 15:32 ` Sean Christopherson
2021-05-25  1:17   ` Wanpeng Li [this message]

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='CANRm+CyA=p+_bsP=3vZXMKnCqYKvE0rNR4xEfE6nUyg5Dmznyg@mail.gmail.com' \
    --to=kernellwp@gmail.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.