From patchwork Tue Feb 7 13:38:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Lothar_Wa=C3=9Fmann?= X-Patchwork-Id: 139930 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 07C0F1007D3 for ; Wed, 8 Feb 2012 00:41:33 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RulG5-0007Wh-Dk; Tue, 07 Feb 2012 13:38:57 +0000 Received: from mail.karo-electronics.de ([81.173.242.67]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RulG1-0007WB-UA for linux-arm-kernel@lists.infradead.org; Tue, 07 Feb 2012 13:38:55 +0000 From: =?UTF-8?q?Lothar=20Wa=C3=9Fmann?= To: linux-kernel@vger.kernel.org Subject: [PATCH] genirq: Fix race condition in ONESHOT irq handler Date: Tue, 7 Feb 2012 14:38:41 +0100 Message-Id: <1328621921-17404-1-git-send-email-LW@KARO-electronics.de> X-Mailer: git-send-email 1.7.2.5 MIME-Version: 1.0 References: <4F31220A.2050708@metafoo.de> To: X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Yong Zhang , Thomas Gleixner , Lars-Peter Clausen , linux-arm-kernel@lists.infradead.org, =?UTF-8?q?Lothar=20Wa=C3=9Fmann?= X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org There is a race condition in the threaded IRQ handler code for oneshot interrupts that may lead to disabling an IRQ indefinitely. IRQs are masked before calling the hard-irq handler and are unmasked only after the soft-irq handler has been run. Thus if the hard-irq handler returns IRQ_HANDLED instead of IRQ_WAKE_THREAD, meaning the soft-irq will not be called, the interrupt will remain masked forever. This can happen due to a short pulse on the interrupt line, that triggers the interrupt logic, but goes undetected by the hard-irq handler. The problem can be reproduced with the TSC2007 touch controller driver that uses ONESHOT interrupts. The problem arises also with interrupt controllers that latch a level triggered IRQ until it is acknowledged (like the i.MX28 does). In this case the IRQ status bit will remain asserted after the soft-irq finishes and retrigger the interrupt while the interrupt line is already deasserted. Signed-off-by: Lothar Waßmann --- kernel/irq/chip.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index f7c543a..74fdef9 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -343,6 +343,8 @@ EXPORT_SYMBOL_GPL(handle_simple_irq); void handle_level_irq(unsigned int irq, struct irq_desc *desc) { + irqreturn_t ret; + raw_spin_lock(&desc->lock); mask_ack_irq(desc); @@ -360,10 +362,13 @@ handle_level_irq(unsigned int irq, struct irq_desc *desc) if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) goto out_unlock; - handle_irq_event(desc); + ret = handle_irq_event(desc); - if (!irqd_irq_disabled(&desc->irq_data) && !(desc->istate & IRQS_ONESHOT)) + if (!irqd_irq_disabled(&desc->irq_data) && + (!(desc->istate & IRQS_ONESHOT) || + !(ret & IRQ_WAKE_THREAD))) unmask_irq(desc); + out_unlock: raw_spin_unlock(&desc->lock); }