From patchwork Wed Nov 25 15:10:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 11931405 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0770C63798 for ; Wed, 25 Nov 2020 15:10:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2705B2083E for ; Wed, 25 Nov 2020 15:10:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="W5tFAUXg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729949AbgKYPKU (ORCPT ); Wed, 25 Nov 2020 10:10:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726295AbgKYPKT (ORCPT ); Wed, 25 Nov 2020 10:10:19 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 789A1C0613D4 for ; Wed, 25 Nov 2020 07:10:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Mime-Version:Content-Type:References: In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Fq0H+7D6WCHp5sD/cqPJk3IRLiLIxxWtxQQNsf72xQ0=; b=W5tFAUXg1mE/WS0Ze2VyB2yN+b yp8GDGY6Fxl4HSJ+1IaKbR4Rdr/HSV77I1QP3cAFXQ4d4gyKKud9pTOwYpNjB1hoe/RG04gLg96K8 j/uCNIq3QHhHW4bhhAhZanIk9Z6ATw89yBqnAXusvEwxtrd9vd6pedTM9CmhtkIQFCw1PRdbu1QpP 0sDeE6QVPiDGJ+vK+U0jrI1L4o/zl3Z5qH62XloN/gpM9UCl8dQEaU4NoCgRve3365DHSJbU7NNN1 QYIbGlh25nnHzUmB590FDmqzPhBlnTUTMr0G0atJmMDg4SZDcIMg9TAgKTq/NTpOv4j5o+3/QXVdj GfCDOusA==; Received: from 54-240-197-238.amazon.com ([54.240.197.238] helo=u3832b3a9db3152.ant.amazon.com) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1khwQy-0007Yd-Fm; Wed, 25 Nov 2020 15:10:16 +0000 Message-ID: <017de9019136b5d2ec34132b96b9f0273c21d6f1.camel@infradead.org> Subject: [RFC PATCH] Fix split-irqchip vs interrupt injection window request. From: David Woodhouse To: kvm Cc: "Sironi, Filippo" , "Raslan, KarimAllah" , Matt Gingell , Steve Rutherford , liran@amazon.com Date: Wed, 25 Nov 2020 15:10:13 +0000 In-Reply-To: <62918f65ec78f8990278a6a0db0567968fa23e49.camel@infradead.org> References: <62918f65ec78f8990278a6a0db0567968fa23e49.camel@infradead.org> X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by merlin.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Thu, 2020-11-12 at 13:03 +0000, David Woodhouse wrote: > I'm using nested VMX for testing, while I add split-irqchip support to > my VMM. I see the vCPU lock up when attempting to deliver an interrupt. Turns out I don't need nesting or my own VMM to reproduce this; all I need to do is boot a guest in qemu with split-irqchip and 'noapic' on the guest command line. It locks up before getting to a login prompt, every time. qemu-system-x86_64 -serial mon:stdio -machine q35,accel=kvm,kernel-irqchip=split -m 2G -display none -drive file=foo.qcow2,if=virtio Commit 782d422bc ("KVM: x86: split kvm_vcpu_ready_for_interrupt_injection out of dm_request_for_irq_injection") made dm_request_for_irq_injection() return true even when kvm_cpu_has_interrupt() is true. So we enable the vmexit on interrupt window because userspace asked for it, but then kvm_vcpu_ready_for_interrupt_injection() returns false, causing us *not* to exit all the way to userspace but just to loop in vcpu_run() instead. But we *didn't* have an injectable interrupt from the kernel, so we just go straight back into the guest, vmexit again, loop again, ad infinitum. This appears to fix it: --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4028,7 +4028,7 @@ static int kvm_cpu_accept_dm_intr(struct kvm_vcpu *vcpu) static int kvm_vcpu_ready_for_interrupt_injection(struct kvm_vcpu *vcpu) { return kvm_arch_interrupt_allowed(vcpu) && - !kvm_cpu_has_interrupt(vcpu) && + !kvm_cpu_has_injectable_intr(vcpu) && !kvm_event_needs_reinjection(vcpu) && kvm_cpu_accept_dm_intr(vcpu); }