From patchwork Mon Jan 23 16:03:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 9532893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 96D8F6020B for ; Mon, 23 Jan 2017 16:04:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 865C428450 for ; Mon, 23 Jan 2017 16:04:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AE7928452; Mon, 23 Jan 2017 16:04:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 172FC28459 for ; Mon, 23 Jan 2017 16:04:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751477AbdAWQDn (ORCPT ); Mon, 23 Jan 2017 11:03:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43280 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751292AbdAWQDl (ORCPT ); Mon, 23 Jan 2017 11:03:41 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E95E3C04B947; Mon, 23 Jan 2017 16:03:41 +0000 (UTC) Received: from [10.36.116.172] (ovpn-116-172.ams2.redhat.com [10.36.116.172]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0NG3dSe005256; Mon, 23 Jan 2017 11:03:39 -0500 Subject: Re: kvm: WARNING In kvm_apic_accept_events To: Dmitry Vyukov , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "x86@kernel.org" , KVM list , LKML , Steve Rutherford References: Cc: syzkaller From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <1516d642-081c-c5f5-e3ea-083fcd47011a@redhat.com> Date: Mon, 23 Jan 2017 17:03:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 23 Jan 2017 16:03:42 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Am 22.01.2017 um 09:52 schrieb Dmitry Vyukov: > On Sat, Nov 12, 2016 at 2:56 AM, Dmitry Vyukov wrote: >> Hello, >> >> The following program triggers WARNING in kvm_apic_accept_events: >> https://gist.githubusercontent.com/dvyukov/95b845a2e637485568ea1ef181a72370/raw/d90717dd67128b21715c5e794568a1600f613d97/gistfile1.txt >> >> On commit 015ed9433be2b476ec7e2e6a9a411a56e3b5b035 (Nov 11). >> >> ------------[ cut here ]------------ >> WARNING: CPU: 1 PID: 23523 at arch/x86/kvm/lapic.c:2330 >> kvm_apic_accept_events+0x3f6/0x460 >> Modules linked in:[ 55.632648] CPU: 1 PID: 2812 Comm: a.out Not >> tainted 4.9.0-rc4+ #41 >> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 >> ffff88006be77978 ffffffff81c2f79b 0000000000000000 0000000000000000 >> ffffffff8322d6a0 ffffffff81127426 ffff88006be779c0 ffffffff8123ffef >> ffffffff811acc46 ffffffff0000091a ffffffff8322d6a0 000000000000091a >> Call Trace: >> [< inline >] __dump_stack lib/dump_stack.c:15 >> [] dump_stack+0xb3/0x118 lib/dump_stack.c:51 >> [] __warn+0x19f/0x1e0 kernel/panic.c:550 >> [] warn_slowpath_null+0x2c/0x40 kernel/panic.c:585 >> [] kvm_apic_accept_events+0x3f6/0x460 >> arch/x86/kvm/lapic.c:2330 >> [< inline >] vcpu_block arch/x86/kvm/x86.c:6793 >> [< inline >] vcpu_run arch/x86/kvm/x86.c:6828 >> [] kvm_arch_vcpu_ioctl_run+0x1580/0x5a90 >> arch/x86/kvm/x86.c:6984 >> [] kvm_vcpu_ioctl+0x61e/0xdd0 >> arch/x86/kvm/../../../virt/kvm/kvm_main.c:2557 >> [< inline >] vfs_ioctl fs/ioctl.c:43 >> [] do_vfs_ioctl+0x18c/0x1040 fs/ioctl.c:679 >> [< inline >] SYSC_ioctl fs/ioctl.c:694 >> [] SyS_ioctl+0x8f/0xc0 fs/ioctl.c:685 >> [] entry_SYSCALL_64_fastpath+0x1f/0xc2 >> arch/x86/entry/entry_64.S:209 >> ---[ end trace b2415ddd1b26dce6 ]--- > > > ping > Our VCPU is in SMM mode but is switched into KVM_MP_STATE_INIT_RECEIVED. The relevant warning is (arch/x86/kvm/lapic.c:kvm_apic_accept_events()) if (is_smm(vcpu)) { WARN_ON_ONCE(vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED); .... Something like that might help (untested): From: David Hildenbrand Date: Mon, 23 Jan 2017 16:42:23 +0100 Subject: [PATCH] KVM: x86: fix illegal MP_STATE when in/entering SMM If we already entered/are about to enter SMM, don't allow switching to INIT/SIPI_RECEIVED, otherwise the next call to kvm_apic_accept_events() will report a warning. Fixes: cd7764fe9f73 ("KVM: x86: latch INITs while in system management mode") Reported-by: Dmitry Vyukov Signed-off-by: David Hildenbrand --- arch/x86/kvm/x86.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 57d8a85..06ffc91 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7247,6 +7247,12 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, mp_state->mp_state != KVM_MP_STATE_RUNNABLE) return -EINVAL; + /* INITs are latched while in SMM */ + if ((is_smm(vcpu) || vcpu->arch.smi_pending) && + (mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED || + mp_state->mp_state == KVM_MP_STATE_INIT_RECEIVED)) + return -EINVAL; + if (mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED) { vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED; set_bit(KVM_APIC_SIPI, &vcpu->arch.apic->pending_events);