From patchwork Thu Dec 27 05:39:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Ogilvie X-Patchwork-Id: 208252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DAFA92C00C4 for ; Thu, 27 Dec 2012 16:47:56 +1100 (EST) Received: from localhost ([::1]:34946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1To6Jv-0003cu-4B for incoming@patchwork.ozlabs.org; Thu, 27 Dec 2012 00:47:55 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1To6Ji-0003bx-Sr for qemu-devel@nongnu.org; Thu, 27 Dec 2012 00:47:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1To6Jf-0003t0-UO for qemu-devel@nongnu.org; Thu, 27 Dec 2012 00:47:42 -0500 Received: from qmta01.emeryville.ca.mail.comcast.net ([2001:558:fe2d:43:76:96:30:16]:46009) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1To6Jf-0003sv-Lz for qemu-devel@nongnu.org; Thu, 27 Dec 2012 00:47:39 -0500 Received: from omta08.emeryville.ca.mail.comcast.net ([76.96.30.12]) by qmta01.emeryville.ca.mail.comcast.net with comcast id gT7n1k0040FhH24A1VnfFV; Thu, 27 Dec 2012 05:47:39 +0000 Received: from mmogilvi.homeip.net ([75.70.117.91]) by omta08.emeryville.ca.mail.comcast.net with comcast id gVnd1k0091yPlfP8UVndPZ; Thu, 27 Dec 2012 05:47:38 +0000 Received: by mmogilvi.homeip.net (Postfix, from userid 501) id 805861E9601F; Wed, 26 Dec 2012 22:41:16 -0700 (MST) From: Matthew Ogilvie To: qemu-devel@nongnu.org Date: Wed, 26 Dec 2012 22:39:55 -0700 Message-Id: <1356586796-7631-4-git-send-email-mmogilvi_qemu@miniinfo.net> X-Mailer: git-send-email 1.7.10.2.484.gcd07cc5 In-Reply-To: <1356586796-7631-1-git-send-email-mmogilvi_qemu@miniinfo.net> References: <1356586796-7631-1-git-send-email-mmogilvi_qemu@miniinfo.net> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20121106; t=1356587259; bh=jXDJi+gyAjGkmloSJwzIM3AJrLiA9ITg/E0qGeB9wSU=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=Bbr6HjMVHQjQmEFwV26pVIXA+BFJQA30w2txSlGfFvWeOUE0pye3ImVFXu3VmdWiR lUNkbIVfUuO+Du5kCQN3Us6+VGD4E2r+QG4b1rklTZjv4e9pRSP7jOl0lfR96M7WuG XqImMFEJYwgxh9xAzFVw/pK1Jj3wp3tNBuM0keokmt/6jzP2sWchdUa5E18tGI2hDE t8frDwSpHKhOojNFW3wQM5q4jtJc8INIgqQ+xDqAsKqHjbYoduPdsE2yUhxHkqQuyd xuXESsbQEF6I8RKV1JQPRVSPTXoxuUtymrdYiCEr4rtoRp6F7nrdCQ8k0rgCg2PAr/ n8dWA7Y2focCA== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:558:fe2d:43:76:96:30:16 Cc: Gleb Natapov , Jan Kiszka , Matthew Ogilvie , kvm@vger.kernel.org, "Maciej W. Rozycki" Subject: [Qemu-devel] [PATCH KVM v2 3/4] KVM: fix i8259 interrupt high to low transition logic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Intel's definition of "edge triggered" means: "asserted with a low-to-high transition at the time an interrupt is registered and then kept high until the interrupt is served via one of the EOI mechanisms or goes away unhandled." So the only difference between edge triggered and level triggered is in the leading edge, with no difference in the trailing edge. This bug manifested itself when the guest was Microport UNIX System V/386 v2.1 (ca. 1987), because it would sometimes mask off IRQ14 in the slave IMR after it had already been asserted. The master would still try to deliver an interrupt to the CPU even though IRQ2 had dropped again, resulting in a spurious interupt (IRQ15) and a panicked UNIX kernel. Signed-off-by: Matthew Ogilvie --- arch/x86/kvm/i8259.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c index cc31f7c..76d8dc1 100644 --- a/arch/x86/kvm/i8259.c +++ b/arch/x86/kvm/i8259.c @@ -111,8 +111,10 @@ static inline int pic_set_irq1(struct kvm_kpic_state *s, int irq, int level) s->irr |= mask; } s->last_irr |= mask; - } else + } else { + s->irr &= ~mask; s->last_irr &= ~mask; + } return (s->imr & mask) ? -1 : ret; } @@ -169,14 +171,10 @@ static void pic_update_irq(struct kvm_pic *s) { int irq2, irq; + /* slave PIC notifies master PIC via IRQ2 */ irq2 = pic_get_irq(&s->pics[1]); - if (irq2 >= 0) { - /* - * if irq request by slave pic, signal master PIC - */ - pic_set_irq1(&s->pics[0], 2, 1); - pic_set_irq1(&s->pics[0], 2, 0); - } + pic_set_irq1(&s->pics[0], 2, irq2 >= 0); + irq = pic_get_irq(&s->pics[0]); pic_irq_request(s->kvm, irq >= 0); }