Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754737AbdCWKYA (ORCPT ); Thu, 23 Mar 2017 06:24:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33108 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753692AbdCWKX6 (ORCPT ); Thu, 23 Mar 2017 06:23:58 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 70FE880F9A Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=david@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 70FE880F9A Subject: Re: [PATCH v1] KVM: x86: fix illegal MP_STATE when in/entering SMM To: Dmitry Vyukov , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <20170322155354.18436-1-david@redhat.com> <20170322164932.GA1992@potion> Cc: KVM list , Paolo Bonzini , stable , LKML , syzkaller From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <1f21bbc9-baf3-723d-a140-1afecaa857e3@redhat.com> Date: Thu, 23 Mar 2017 11:23:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 23 Mar 2017 10:23:58 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2236 Lines: 56 > This program still triggers the warning in kvm_apic_accept_events with > the patch applied (on top of > 093b995e3b55a0ae0670226ddfcb05bfbf0099ae): > > https://gist.githubusercontent.com/dvyukov/2a39303347aa417aea2afd9fd99b7086/raw/09693aa7ed78d22b23948c726767f540b2276a99/gistfile1.txt > > ------------[ cut here ]------------ > WARNING: CPU: 3 PID: 2964 at arch/x86/kvm/lapic.c:2461 > kvm_apic_accept_events+0x46c/0x550 arch/x86/kvm/lapic.c:2461 > CPU: 3 PID: 2964 Comm: a.out Not tainted 4.11.0-rc3+ #365 > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 > Call Trace: > __dump_stack lib/dump_stack.c:16 [inline] > dump_stack+0x1b8/0x28d lib/dump_stack.c:52 > panic+0x20c/0x423 kernel/panic.c:180 > __warn+0x1c4/0x1e0 kernel/panic.c:541 > warn_slowpath_null+0x2c/0x40 kernel/panic.c:584 > kvm_apic_accept_events+0x46c/0x550 arch/x86/kvm/lapic.c:2461 > vcpu_block arch/x86/kvm/x86.c:7010 [inline] > vcpu_run arch/x86/kvm/x86.c:7048 [inline] > kvm_arch_vcpu_ioctl_run+0xefc/0x59e0 arch/x86/kvm/x86.c:7207 > kvm_vcpu_ioctl+0x627/0x1100 arch/x86/kvm/../../../virt/kvm/kvm_main.c:2573 > vfs_ioctl fs/ioctl.c:45 [inline] > do_vfs_ioctl+0x1af/0x16d0 fs/ioctl.c:685 > SYSC_ioctl fs/ioctl.c:700 [inline] > SyS_ioctl+0x8f/0xc0 fs/ioctl.c:691 > entry_SYSCALL_64_fastpath+0x1f/0xc2 > RIP: 0033:0x447109 > RSP: 002b:00007ffcb458a038 EFLAGS: 00000202 ORIG_RAX: 0000000000000010 > RAX: ffffffffffffffda RBX: 00000000004002b0 RCX: 0000000000447109 > RDX: 0000000000000000 RSI: 000000000000ae80 RDI: 0000000000000005 > RBP: 0000000000000086 R08: 0000000000000000 R09: 0000000000000000 > R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000000 > R13: 00000000004073f0 R14: 0000000000407480 R15: 0000000000000000 > I think we're seeing what Radim describes. So this is now a different call order. The VCPU is set to KVM_MP_STATE_SIPI_RECEIVED (which results in KVM_MP_STATE_INIT_RECEIVED). Then, KVM_SET_VCPU_EVENTS is set with KVM_VCPUEVENT_VALID_SMM | KVM_VCPUEVENT_VALID_NMI_PENDING, enabling SMM. Calling kvm_apic_accept_events() then will result in a warning on the next VCPU run. So the right thing is indeed adding an additional checks for KVM_SET_VCPU_EVENTS. -- Thanks, David