Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3014746imu; Mon, 19 Nov 2018 09:22:28 -0800 (PST) X-Google-Smtp-Source: AJdET5dwZu26RPpUQDfwunptZF0E6oIUONmdaCrsEIppGCb3SUe2R9BW74/jrRlnmql5eYg5oGbL X-Received: by 2002:a63:8043:: with SMTP id j64mr21279821pgd.405.1542648148608; Mon, 19 Nov 2018 09:22:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542648148; cv=none; d=google.com; s=arc-20160816; b=b7jXbMz0JCisk39QEP+K7qNIvMMEBJzX1+RYMnudvETGwGOAGz+RInCvEb835rhRrY W1WsEXtSixg/lHhm4aauYaGmh3BUk4BhfYny03rMcS89i8owUtSI8+Mi7U0W3OoooYWN B0lQkEQU0ESc6yqpbIG9h38XquY2gR2s9fCIqdEWkepLkzEF7SbporLa4vcJ1XHXee6Y BdwONoL9N3ZOdFp2pUGPJ2hhmdVO8POzhvOsGFivs09UKHihjMGpb4dlJPhcc2hRw/Vu ofQxwMSCYGJok2l/kvRql/CdRi4SBhI0VtrmkkhIF9JjmCq9+gGum0uGrJhA3VDKnLsw UHSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AOozy0TYBihPTY3x0df/X8b559ffXCr+n9IkSgxyrk4=; b=eCJYFstZORaS4HfemvFl5sfoRO1aQRXbt96ikLeaf1J+Z+TSxtQ7LZ0khnWdrJavQF YQGIRKa7NK1ZxHVK3RS0ahXf+tcteYPgRtSTsA252kIHyLKs0bRh7ci1Id8Fnj9pferF c/9JPRXR7iatWRqFIkqL/H64ZUwvMUka5fyWS+U3xpZ1DvcUIYVImzFfvsGforV+O1PG ba25fs5pHySuOQXqtdC2Nrmz5zQx1yq52AuF1FSPG5KMt1+jqlGpc/2p06eS3crVvfzc 1GaVNNwS7Hj1bAPxWid8NfMbItacSEszvueIsw7rzKV7zBcwAac/WbHB0+D9CJDaS+0D l2iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hIS9AiVU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4-v6si39887414plp.247.2018.11.19.09.22.03; Mon, 19 Nov 2018 09:22:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hIS9AiVU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405365AbeKTDYl (ORCPT + 99 others); Mon, 19 Nov 2018 22:24:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:37470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405346AbeKTDYk (ORCPT ); Mon, 19 Nov 2018 22:24:40 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6C973223CA; Mon, 19 Nov 2018 17:00:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542646823; bh=bN2onHJMQco2aXdrf1fFnVmIkYyoWOJiH6Q4yfrg44w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hIS9AiVUCCNnPrXUPCJFHeo7M/BEcNR1pbJ0lUT6PCvOkqL8wgi3vnbs3pMJfC9C9 NysmFLopZxNWorQYJRHY2ON6RoF+eJNUDPTaN8BHXt/e8BT6RZxkI6LZEguiduvjmH QuNHJXX9cvoauEwFWdZBKchQYKOCXrtPzEJSlFX8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Thomas Gleixner , Mathias Duckeck , Akshay Bhat , Casey Fitzpatrick Subject: [PATCH 4.4 067/160] genirq: Fix race on spurious interrupt detection Date: Mon, 19 Nov 2018 17:28:26 +0100 Message-Id: <20181119162637.842707470@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162630.031306128@linuxfoundation.org> References: <20181119162630.031306128@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lukas Wunner commit 746a923b863a1065ef77324e1e43f19b1a3eab5c upstream. Commit 1e77d0a1ed74 ("genirq: Sanitize spurious interrupt detection of threaded irqs") made detection of spurious interrupts work for threaded handlers by: a) incrementing a counter every time the thread returns IRQ_HANDLED, and b) checking whether that counter has increased every time the thread is woken. However for oneshot interrupts, the commit unmasks the interrupt before incrementing the counter. If another interrupt occurs right after unmasking but before the counter is incremented, that interrupt is incorrectly considered spurious: time | irq_thread() | irq_thread_fn() | action->thread_fn() | irq_finalize_oneshot() | unmask_threaded_irq() /* interrupt is unmasked */ | | /* interrupt fires, incorrectly deemed spurious */ | | atomic_inc(&desc->threads_handled); /* counter is incremented */ v This is observed with a hi3110 CAN controller receiving data at high volume (from a separate machine sending with "cangen -g 0 -i -x"): The controller signals a huge number of interrupts (hundreds of millions per day) and every second there are about a dozen which are deemed spurious. In theory with high CPU load and the presence of higher priority tasks, the number of incorrectly detected spurious interrupts might increase beyond the 99,900 threshold and cause disablement of the interrupt. In practice it just increments the spurious interrupt count. But that can cause people to waste time investigating it over and over. Fix it by moving the accounting before the invocation of irq_finalize_oneshot(). [ tglx: Folded change log update ] Fixes: 1e77d0a1ed74 ("genirq: Sanitize spurious interrupt detection of threaded irqs") Signed-off-by: Lukas Wunner Signed-off-by: Thomas Gleixner Cc: Mathias Duckeck Cc: Akshay Bhat Cc: Casey Fitzpatrick Cc: stable@vger.kernel.org # v3.16+ Link: https://lkml.kernel.org/r/1dfd8bbd16163940648045495e3e9698e63b50ad.1539867047.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman --- kernel/irq/manage.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -864,6 +864,9 @@ irq_forced_thread_fn(struct irq_desc *de local_bh_disable(); ret = action->thread_fn(action->irq, action->dev_id); + if (ret == IRQ_HANDLED) + atomic_inc(&desc->threads_handled); + irq_finalize_oneshot(desc, action); local_bh_enable(); return ret; @@ -880,6 +883,9 @@ static irqreturn_t irq_thread_fn(struct irqreturn_t ret; ret = action->thread_fn(action->irq, action->dev_id); + if (ret == IRQ_HANDLED) + atomic_inc(&desc->threads_handled); + irq_finalize_oneshot(desc, action); return ret; } @@ -957,8 +963,6 @@ static int irq_thread(void *data) irq_thread_check_affinity(desc, action); action_ret = handler_fn(desc, action); - if (action_ret == IRQ_HANDLED) - atomic_inc(&desc->threads_handled); if (action_ret == IRQ_WAKE_THREAD) irq_wake_secondary(desc, action);