From patchwork Mon Feb 27 12:11:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 9593055 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 9BF30601D7 for ; Mon, 27 Feb 2017 12:18:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91AB9282E8 for ; Mon, 27 Feb 2017 12:18:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8507E28487; Mon, 27 Feb 2017 12:18:50 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 0E905282E8 for ; Mon, 27 Feb 2017 12:18:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751955AbdB0MSd (ORCPT ); Mon, 27 Feb 2017 07:18:33 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33962 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751666AbdB0MSb (ORCPT ); Mon, 27 Feb 2017 07:18:31 -0500 Received: by mail-pf0-f194.google.com with SMTP id o64so4258394pfb.1; Mon, 27 Feb 2017 04:18:31 -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=kMx4J/2hIqaf0FT8QRUk2aouRAvL7rD7h85kgOLXxgU=; b=pk9OPjNplu6yAe0AAtcMS90s0KgeKdaW8I0qhmyEmcGfeycOrnsgF16/d5svZHLNMp MISAOOUKmfz7v7ylQ9ny8IunpvfpVpf14aur2Jwi2hQ4EsJmJ+MFFMZ8d4nlw5aMrblQ LwiwPOkLzTzlVm5vBKoaOLXK2qw2l0RVsJzpEDQ5ox52XrmtMSaXI0io/3iLCKoeDQxa 8l+B8HxJwMLN901A5ZyO0JQPYeVd/InXFcToqH+8akwdGbFAjDIGQCEDVZbeP58Rbdsy rOka3Y23DQ7TKNRo7odZLlQoUg/t96mOhW0OTSpYowC4TYIODKQahbAisWOM2Q02W2kq teEQ== 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=kMx4J/2hIqaf0FT8QRUk2aouRAvL7rD7h85kgOLXxgU=; b=YAQVcHD2nMIyyumiWwjy57aMk8uXIW3/CvQ+AVw6V5a7RbpeQ40PPLwozOgdNgDVfV d4iGZTQorLLUD/gQ94LzQUPjf9B3xzAZUlq86KdS2nTTBNrEuWA/KryfE+8g9OASE8uh XPRvU5Rzg2MHKq5s/kd/81xRqdQAyXa620tCmTw7SFEPnAVYlUOjcYdhz0BS46ta9TXs buxqWjGGrldQjlFI+6VnJlaYk/w7r0uPa/RRXrp4h8SMSEf7AK3ESfW6IKhlc95unzWd uTxYP+hX48GrV6JTWK3Nu5AWPeBJGGKG5sjmTUJw7rUoxTlTHxO42SVhkqSQyEt1KyEN Iz6w== X-Gm-Message-State: AMke39kVcCu9pqlSWXROahWDFe+2ovgpVLVwNu8N9lEkDOTTEPmCYc/6TBkMhofDRuldwg== X-Received: by 10.98.138.132 with SMTP id o4mr8627397pfk.70.1488197474266; Mon, 27 Feb 2017 04:11:14 -0800 (PST) Received: from localhost ([203.205.141.123]) by smtp.gmail.com with ESMTPSA id l22sm30413085pfk.69.2017.02.27.04.11.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Feb 2017 04:11:13 -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 v2] KVM: nVMX: Fix pending events injection Date: Mon, 27 Feb 2017 04:11:08 -0800 Message-Id: <1488197468-34259-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 bailing out for pending events and not consider new events in this scenario. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Jan Kiszka Signed-off-by: Wanpeng Li --- v1 -> v2: * bail out for pending events in vmx_check_nested_events() and not consider new events in this scenario arch/x86/kvm/vmx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index ef4ba71..d46af65 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -10642,6 +10642,11 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu, bool external_intr) { struct vcpu_vmx *vmx = to_vmx(vcpu); + if (vcpu->arch.exception.pending || + vcpu->arch.nmi_injected || + vcpu->arch.interrupt.pending) + return -EBUSY; + if (nested_cpu_has_preemption_timer(get_vmcs12(vcpu)) && vmx->nested.preemption_timer_expired) { if (vmx->nested.nested_run_pending)