From: Paolo Bonzini <pbonzini@redhat.com>
To: Dmitry Vyukov <dvyukov@google.com>,
mtosatti@redhat.com, yoshikawa_takuya_b1@lab.ntt.co.jp,
guangrong.xiao@linux.intel.com,
Steve Rutherford <srutherford@google.com>,
rkrcmar@redhat.com, KVM list <kvm@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Cc: syzkaller <syzkaller@googlegroups.com>,
Alexander Potapenko <glider@google.com>,
Sasha Levin <sasha.levin@oracle.com>,
Kostya Serebryany <kcc@google.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: kvm: GPF in kvm_lapic_set_tpr
Date: Tue, 21 Jun 2016 16:12:39 +0200 [thread overview]
Message-ID: <b87847ee-1a2a-7288-40ce-1284da6c44f4@redhat.com> (raw)
In-Reply-To: <CACT4Y+a01sL5jhLi_tOCBtdq4LuXDB_YYPuNkMDSDoQBPXKn4A@mail.gmail.com>
On 21/06/2016 15:18, Dmitry Vyukov wrote:
> [<ffffffff811269be>] kvm_lapic_set_tpr+0x5e/0xe0 arch/x86/kvm/lapic.c:1648
> [<ffffffff8109496c>] kvm_set_cr8.part.135+0x2c/0xb0 arch/x86/kvm/x86.c:809
> [<ffffffff81094a22>] kvm_set_cr8+0x32/0x50 arch/x86/kvm/x86.c:806
> [<ffffffff81178dd4>] vmx_vcpu_reset+0x114/0xb60 arch/x86/kvm/vmx.c:4996
> [<ffffffff810b91b0>] kvm_vcpu_reset+0x410/0x580 arch/x86/kvm/x86.c:7470
> [<ffffffff810b9355>] kvm_arch_vcpu_setup+0x35/0x60 arch/x86/kvm/x86.c:7393
> [< inline >] kvm_vm_ioctl_create_vcpu virt/kvm/kvm_main.c:2355
> [<ffffffff8106b9f2>] kvm_vm_ioctl+0x582/0x10d0 virt/kvm/kvm_main.c:2839
> [< inline >] vfs_ioctl fs/ioctl.c:43
> [<ffffffff818510bc>] do_vfs_ioctl+0x18c/0xff0 fs/ioctl.c:674
> [< inline >] SYSC_ioctl fs/ioctl.c:689
> [<ffffffff81851faf>] SyS_ioctl+0x8f/0xc0 fs/ioctl.c:680
> [<ffffffff86a96fc0>] entry_SYSCALL_64_fastpath+0x23/0xc1
The bug is not in KVM. Modulo the shuffling of system calls from
threading, the program is equivalent to this:
long r[7];
int main(void)
{
struct kvm_vcpu_events ve;
r[0] = open("/dev/kvm", O_RDONLY);
r[1] = ioctl(r[0], KVM_CREATE_VM, 0x0ul, 0, 0, 0);
r[2] = ioctl(r[1], KVM_CREATE_VCPU, 0x1ul, 0, 0, 0);
r[3] = ioctl(r[2], KVM_RUN, 0, 0, 0, 0);
r[4] = ioctl(r[2], KVM_RUN, 0, 0, 0, 0);
r[5] = ioctl(r[2], KVM_RUN, 0, 0, 0, 0);
r[6] = ioctl(r[2], KVM_GET_VCPU_EVENTS, &ve, 0, 0, 0);
return 0;
}
However, it is easy to see that there is a clear critical path in the
bug, so that the threading must be completely irrelevant:
1) r[1] was valid in KVM_CREATE_VCPU, so KVM_CREATE_VCPU started after
the assignment of KVM_CREATE_VM
2) r[0] was valid in KVM_CREATE_VM, so KVM_CREATE_VM started after the
assignment of open("/dev/kvm")
3) the assignment of r[2] must not have happened because of the
backtrace, so KVM_CREATE_VCPU has not finished and the other ioctls will
not get to KVM.
The GP _could_ happen because of a bug, because lapic_in_kernel attempts
to skip a NULL check using a static key. But the static key is
incremented before the point that is in the backtrace:
kvm_vm_ioctl_create_vcpu (virt/kvm/kvm_main.c)
kvm_arch_vcpu_create (arch/x86/kvm/x86.c)
vmx_create_vcpu (arch/x86/kvm/vmx.c)
kvm_vcpu_init (virt/kvm/kvm_main.c)
kvm_arch_vcpu_init (arch/x86/kvm/x86.c)
static_key_slow_inc
<-
<-
<-
<-
kvm_arch_vcpu_setup (arch/x86/kvm/x86.c)
kvm_vcpu_reset (arch/x86/kvm/x86.c)
vmx_vcpu_reset (arch/x86/kvm/vmx.c)
kvm_set_cr8 (arch/x86/kvm/x86.c)
*mumble mumble*
Ok, the bug shows up when you do two concurrent calls to
static_key_slow_inc and is caused by commit 706249c22. Patch on its way.
Paolo
prev parent reply other threads:[~2016-06-21 14:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-21 13:18 Dmitry Vyukov
2016-06-21 14:12 ` Paolo Bonzini [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=b87847ee-1a2a-7288-40ce-1284da6c44f4@redhat.com \
--to=pbonzini@redhat.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=guangrong.xiao@linux.intel.com \
--cc=kcc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=peterz@infradead.org \
--cc=rkrcmar@redhat.com \
--cc=sasha.levin@oracle.com \
--cc=srutherford@google.com \
--cc=syzkaller@googlegroups.com \
--cc=yoshikawa_takuya_b1@lab.ntt.co.jp \
/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
all inboxes | Powered by JetHome®