Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3313339imm; Fri, 19 Oct 2018 08:34:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV62DRzD1d5B/Ta1VtyFvkr24P7NdHl7fveKc6wmR7urV2RGKN5ljlBYuQ3LuVOc9NQiMBJXm X-Received: by 2002:a17:902:148:: with SMTP id 66-v6mr6071341plb.140.1539963291789; Fri, 19 Oct 2018 08:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539963291; cv=none; d=google.com; s=arc-20160816; b=tl3bJ789jX1UQuJNNSp/qwTmlVm7msBOO8ovZD7qKevaak/rlFZLYcE4WavJXDBkXg 3mrPxFSzvdbvb8dKh4h6yhY3Bnt7CqZhFr0NVruqg8DROWICvIem0iNylHJCgjQaGkUP bJPc+lO8/x3CikFq1+Dhk8UFBM2cGNh3qjZZbHAC5TJa7WK0XHMNlCVy9LFa6whal3QW 3sFEzBIyLvUh3Q2mcji6TKMRHWnDyvECGblFlPvYlGxu/Ot/pnjitA05G7MKcX+1bAIT 3AnXhry/j726kV9YVJmk61u4appl3PGI8kcltOfWlZ91MDafZNfQgwMT42m7CAgU5Azg TrJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=UAUb878zWEgDXhEa2FtLLNFZb/SICUVKn0qK5fLReZE=; b=HdIOlEyTleAkpqqchrq4bBM7JFfUu6SwL/uIjMH4rJtKr6LnWWegQEBU0f4ABIasXL 8YPADKQ6lJhitJ+VllPG1HWlp/dg3pKdl0i/a3mUkOdO31VZVh8oE5jbYm1BtMFAk2UD q2xEG7co3JLoDQVc3G3sfZ0OqveqIv6NuxfnjbMKrOqmmcHVxuk5Nr8UFCoDgfYLXUNq lsPnIy3Fw1gn5bHSODwATqREKlvXwgIZ3B4lulBBb3fBkUoKRRwJd+zCprWIC2gM6nXW YxStw7WVgDcoAcQkWAl3LE9LI3VUg36QHk20q/dYQ3I9BLXCk/6SJyHOMJZJD4v1JkSo BkFg== ARC-Authentication-Results: i=1; mx.google.com; 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 c21-v6si24133098pgg.407.2018.10.19.08.34.34; Fri, 19 Oct 2018 08:34:51 -0700 (PDT) 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; 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 S1727516AbeJSXkg (ORCPT + 99 others); Fri, 19 Oct 2018 19:40:36 -0400 Received: from terminus.zytor.com ([198.137.202.136]:39577 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726465AbeJSXkg (ORCPT ); Fri, 19 Oct 2018 19:40:36 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w9JFXo0C1288783 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 19 Oct 2018 08:33:50 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w9JFXoI51288780; Fri, 19 Oct 2018 08:33:50 -0700 Date: Fri, 19 Oct 2018 08:33:50 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Lukas Wunner Message-ID: Cc: mingo@kernel.org, casey.fitzpatrick@timesys.com, lukas@wunner.de, akshay.bhat@timesys.com, hpa@zytor.com, linux-kernel@vger.kernel.org, m.duckeck@kunbus.de, tglx@linutronix.de Reply-To: casey.fitzpatrick@timesys.com, lukas@wunner.de, mingo@kernel.org, tglx@linutronix.de, m.duckeck@kunbus.de, hpa@zytor.com, akshay.bhat@timesys.com, linux-kernel@vger.kernel.org In-Reply-To: <1dfd8bbd16163940648045495e3e9698e63b50ad.1539867047.git.lukas@wunner.de> References: <1dfd8bbd16163940648045495e3e9698e63b50ad.1539867047.git.lukas@wunner.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:irq/core] genirq: Fix race on spurious interrupt detection Git-Commit-ID: 746a923b863a1065ef77324e1e43f19b1a3eab5c X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 746a923b863a1065ef77324e1e43f19b1a3eab5c Gitweb: https://git.kernel.org/tip/746a923b863a1065ef77324e1e43f19b1a3eab5c Author: Lukas Wunner AuthorDate: Thu, 18 Oct 2018 15:15:05 +0200 Committer: Thomas Gleixner CommitDate: Fri, 19 Oct 2018 17:31:00 +0200 genirq: Fix race on spurious interrupt detection 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 --- kernel/irq/manage.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index fb86146037a7..9dbdccab3b6a 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -927,6 +927,9 @@ irq_forced_thread_fn(struct irq_desc *desc, struct irqaction *action) 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; @@ -943,6 +946,9 @@ static irqreturn_t irq_thread_fn(struct irq_desc *desc, 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; } @@ -1020,8 +1026,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);