From patchwork Sun Feb 26 08:46:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 9592255 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 58E7F60459 for ; Sun, 26 Feb 2017 08:55:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4441A28339 for ; Sun, 26 Feb 2017 08:55:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37E8428497; Sun, 26 Feb 2017 08:55:53 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 C751828339 for ; Sun, 26 Feb 2017 08:55:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751970AbdBZIz1 (ORCPT ); Sun, 26 Feb 2017 03:55:27 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35553 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750970AbdBZIz0 (ORCPT ); Sun, 26 Feb 2017 03:55:26 -0500 Received: by mail-pg0-f65.google.com with SMTP id 1so9047795pgz.2; Sun, 26 Feb 2017 00:55:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BXinIYLSNYDZ25XFQH8QCtuJCaqIvBp/KZJZpBnZk9c=; b=JgnXPoNvtgIXZUQx1FQ0aagHZAsvt7C8Di56j84pZAkcNI+mCEzX38+ORoaeGRNxgL m7dNzVkKGy/58iF1fcDmGUxbydui0jCMRZdHxgV4SEAhLgJ6/ldCA5cY4bQRbsXxviIK BGVhYWIa7fDevZ0hlFTNdQgTnaPCn5tBId55pdWCtufYs2Tjb1IPtAMOM2Urbc1Y8Igq X1m64BV1mA1ZaI8Vg48vrauoF6QKo8FFbJhKNToD0XoCWw6KsdG40OUYRFQ9JXJ58ULr T+nOHa/B+Xj9HsQwsWFv6oh8/V5HsTNLgVbAnUYk9hmt03IGl5cR4l1QBE0i+24RvfMm LxPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BXinIYLSNYDZ25XFQH8QCtuJCaqIvBp/KZJZpBnZk9c=; b=P/Ue3LbVnUeMcvNH1tq5op4Adrk3pu+VlR2KnMoGNQ/CRNODhJirTVu5nA1twlY5Kx OQkgHMv0DLwkifPW5Udz7IKJqPKZcom5cFo8YfmaCkAPf5j3MxyWjdLueMF86L7hncJi 1DlfTamLjxGV1l9NnPvInqH+9GkDdnUbLRA1NDcKHYIxoD6E103Q/5z30ToNYmXtXF2t qTJ+ln1ec/OTlLVQkmFXvo23eg/8vKWTS/6iH0IkKEJw+8r8jnyIoscPov5By82HMpoY Blmxmuvojzlu2hoSyq9i4Hc+L2tt8aEWNzGsy3no9f8kk5S28TMBZihGNzMT0j6duMgx aY0Q== X-Gm-Message-State: AMke39lkR2RRIfg9oWSyzSoWORh1mmtU2RqCnTChwrxeVDnSP+g3/Urv9xBuBxxvsa5f+A== X-Received: by 10.84.194.1 with SMTP id g1mr15851930pld.98.1488098813142; Sun, 26 Feb 2017 00:46:53 -0800 (PST) Received: from localhost ([223.255.127.5]) by smtp.gmail.com with ESMTPSA id 19sm23847052pft.46.2017.02.26.00.46.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Feb 2017 00:46:51 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li , Jan Kiszka Subject: [PATCH] KVM: nVMX: Fix pending events injection Date: Sun, 26 Feb 2017 00:46:51 -0800 Message-Id: <1488098811-24953-1-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li L2 fails to boot on a non-APICv box dues to 'commit 0ad3bed6c5ec ("kvm: nVMX: move nested events check to kvm_vcpu_running")' KVM internal error. Suberror: 3 extra data[0]: 800000ef extra data[1]: 1 RAX=0000000000000000 RBX=ffffffff81f36140 RCX=0000000000000000 RDX=0000000000000000 RSI=0000000000000000 RDI=0000000000000000 RBP=ffff88007c92fe90 RSP=ffff88007c92fe90 R8 =ffff88007fccdca0 R9 =0000000000000000 R10=00000000fffedb3d R11=0000000000000000 R12=0000000000000003 R13=0000000000000000 R14=0000000000000000 R15=ffff88007c92c000 RIP=ffffffff810645e6 RFL=00000246 [---Z-P-] CPL=0 II=0 A20=1 SMM=0 HLT=0 ES =0000 0000000000000000 ffffffff 00c00000 CS =0010 0000000000000000 ffffffff 00a09b00 DPL=0 CS64 [-RA] SS =0000 0000000000000000 ffffffff 00c00000 DS =0000 0000000000000000 ffffffff 00c00000 FS =0000 0000000000000000 ffffffff 00c00000 GS =0000 ffff88007fcc0000 ffffffff 00c00000 LDT=0000 0000000000000000 ffffffff 00c00000 TR =0040 ffff88007fcd4200 00002087 00008b00 DPL=0 TSS64-busy GDT= ffff88007fcc9000 0000007f IDT= ffffffffff578000 00000fff CR0=80050033 CR2=00000000ffffffff CR3=0000000001e0a000 CR4=003406e0 DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 DR6=00000000fffe0ff0 DR7=0000000000000400 EFER=0000000000000d01 We should try to reinject previous events if any before trying to inject new event if pending. If vmexit is triggered by L2 guest and L0 interested in, we should reinject IDT-vectoring info to L2 through vmcs02 if any, otherwise, we can consider new IRQs/NMIs which can be injected and call nested events callback to switch from L2 to L1 if needed and inject the proper vmexit events. However, 'commit 0ad3bed6c5ec ("kvm: nVMX: move nested events check to kvm_vcpu_running")' results in the handle events order reversely on non-APICv box. This patch fixes it by checking nested events if there is no KVM_REQ_EVENT since APICv interrupt injection doesn't use KVM_REQ_EVENT any more. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Jan Kiszka Signed-off-by: Wanpeng Li --- arch/x86/kvm/x86.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b2a4b11..74fc47b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6843,7 +6843,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) update_cr8_intercept(vcpu); kvm_lapic_sync_to_vapic(vcpu); } - } + } else if (is_guest_mode(vcpu) && kvm_x86_ops->check_nested_events) + kvm_x86_ops->check_nested_events(vcpu, false); r = kvm_mmu_reload(vcpu); if (unlikely(r)) { @@ -7025,9 +7026,6 @@ static inline int vcpu_block(struct kvm *kvm, struct kvm_vcpu *vcpu) static inline bool kvm_vcpu_running(struct kvm_vcpu *vcpu) { - if (is_guest_mode(vcpu) && kvm_x86_ops->check_nested_events) - kvm_x86_ops->check_nested_events(vcpu, false); - return (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE && !vcpu->arch.apf.halted); } @@ -8397,6 +8395,9 @@ static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu) int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu) { + if (is_guest_mode(vcpu) && kvm_x86_ops->check_nested_events) + kvm_x86_ops->check_nested_events(vcpu, false); + return kvm_vcpu_running(vcpu) || kvm_vcpu_has_events(vcpu); }