From patchwork Wed Jun 13 00:57:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Neri X-Patchwork-Id: 928615 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4159fB02rQz9s3q for ; Wed, 13 Jun 2018 12:28:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4159f94pl5zDrnp for ; Wed, 13 Jun 2018 12:28:17 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.intel.com (client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=ricardo.neri-calderon@linux.intel.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4157kG4hkjzDqsx for ; Wed, 13 Jun 2018 11:01:42 +1000 (AEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2018 18:01:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,216,1526367600"; d="scan'208";a="47283514" Received: from voyager.sc.intel.com ([10.3.52.149]) by fmsmga008.fm.intel.com with ESMTP; 12 Jun 2018 18:01:34 -0700 From: Ricardo Neri To: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Subject: [RFC PATCH 17/23] watchdog/hardlockup/hpet: Convert the timer's interrupt to NMI Date: Tue, 12 Jun 2018 17:57:37 -0700 Message-Id: <1528851463-21140-18-git-send-email-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528851463-21140-1-git-send-email-ricardo.neri-calderon@linux.intel.com> References: <1528851463-21140-1-git-send-email-ricardo.neri-calderon@linux.intel.com> X-Mailman-Approved-At: Wed, 13 Jun 2018 11:52:45 +1000 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Rafael J. Wysocki" , Peter Zijlstra , Alexei Starovoitov , Kai-Heng Feng , sparclinux@vger.kernel.org, Christoffer Dall , Davidlohr Bueso , Ashok Raj , x86@kernel.org, iommu@lists.linux-foundation.org, David Rientjes , Andi Kleen , Waiman Long , Borislav Petkov , Masami Hiramatsu , Don Zickus , "Ravi V. Shankar" , Konrad Rzeszutek Wilk , Marc Zyngier , Ricardo Neri , Frederic Weisbecker , Nicholas Piggin , Byungchul Park , Mathieu Desnoyers , Josh Poimboeuf , "Paul E. McKenney" , Tony Luck , Babu Moger , Randy Dunlap , linux-kernel@vger.kernel.org, "Luis R. Rodriguez" , Jacob Pan , Philippe Ombredanne , Colin Ian King , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" In order to detect hardlockups, it is necessary to have the ability to receive interrupts even when disabled: a non-maskable interrupt is required. Add the flag IRQF_DELIVER_AS_NMI to the arguments of request_irq() for this purpose. Note that the timer, when programmed to deliver interrupts via the IO APIC is programmed as level-triggered. This is to have an indication that the NMI comes from HPET timer as indicated in the General Status Interrupt Register. However, NMIs are always edge-triggered, thus a GSI edge- triggered interrupt is now requested. An NMI handler is also implemented. The handler looks for hardlockups and kicks the timer. Cc: Ashok Raj Cc: Andi Kleen Cc: Tony Luck Cc: Borislav Petkov Cc: Jacob Pan Cc: "Rafael J. Wysocki" Cc: Don Zickus Cc: Nicholas Piggin Cc: Michael Ellerman Cc: Frederic Weisbecker Cc: Alexei Starovoitov Cc: Babu Moger Cc: Mathieu Desnoyers Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Andrew Morton Cc: Philippe Ombredanne Cc: Colin Ian King Cc: Byungchul Park Cc: "Paul E. McKenney" Cc: "Luis R. Rodriguez" Cc: Waiman Long Cc: Josh Poimboeuf Cc: Randy Dunlap Cc: Davidlohr Bueso Cc: Christoffer Dall Cc: Marc Zyngier Cc: Kai-Heng Feng Cc: Konrad Rzeszutek Wilk Cc: David Rientjes Cc: "Ravi V. Shankar" Cc: x86@kernel.org Cc: iommu@lists.linux-foundation.org Signed-off-by: Ricardo Neri --- arch/x86/kernel/hpet.c | 2 +- kernel/watchdog_hld_hpet.c | 55 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c index fda6e19..5ca1953 100644 --- a/arch/x86/kernel/hpet.c +++ b/arch/x86/kernel/hpet.c @@ -205,7 +205,7 @@ int hpet_hardlockup_detector_assign_legacy_irq(struct hpet_hld_data *hdata) break; } - gsi = acpi_register_gsi(NULL, hwirq, ACPI_LEVEL_SENSITIVE, + gsi = acpi_register_gsi(NULL, hwirq, ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_LOW); if (gsi > 0) break; diff --git a/kernel/watchdog_hld_hpet.c b/kernel/watchdog_hld_hpet.c index 8fa4e55..3bedffa 100644 --- a/kernel/watchdog_hld_hpet.c +++ b/kernel/watchdog_hld_hpet.c @@ -10,6 +10,7 @@ #include #include #include +#include #undef pr_fmt #define pr_fmt(fmt) "NMI hpet watchdog: " fmt @@ -183,6 +184,8 @@ static irqreturn_t hardlockup_detector_irq_handler(int irq, void *data) if (!(hdata->flags & HPET_DEV_PERI_CAP)) kick_timer(hdata); + pr_err("This interrupt should not have happened. Ensure delivery mode is NMI.\n"); + /* Acknowledge interrupt if in level-triggered mode */ if (!use_fsb) hpet_writel(BIT(hdata->num), HPET_STATUS); @@ -191,6 +194,47 @@ static irqreturn_t hardlockup_detector_irq_handler(int irq, void *data) } /** + * hardlockup_detector_nmi_handler() - NMI Interrupt handler + * @val: Attribute associated with the NMI. Not used. + * @regs: Register values as seen when the NMI was asserted + * + * When an NMI is issued, look for hardlockups. If the timer is not periodic, + * kick it. The interrupt is always handled when if delivered via the + * Front-Side Bus. + * + * Returns: + * + * NMI_DONE if the HPET timer did not cause the interrupt. NMI_HANDLED + * otherwise. + */ +static int hardlockup_detector_nmi_handler(unsigned int val, + struct pt_regs *regs) +{ + struct hpet_hld_data *hdata = hld_data; + unsigned int use_fsb; + + /* + * If FSB delivery mode is used, the timer interrupt is programmed as + * edge-triggered and there is no need to check the ISR register. + */ + use_fsb = hdata->flags & HPET_DEV_FSB_CAP; + + if (!use_fsb && !is_hpet_wdt_interrupt(hdata)) + return NMI_DONE; + + inspect_for_hardlockups(regs); + + if (!(hdata->flags & HPET_DEV_PERI_CAP)) + kick_timer(hdata); + + /* Acknowledge interrupt if in level-triggered mode */ + if (!use_fsb) + hpet_writel(BIT(hdata->num), HPET_STATUS); + + return NMI_HANDLED; +} + +/** * setup_irq_msi_mode() - Configure the timer to deliver an MSI interrupt * @data: Data associated with the instance of the HPET timer to configure * @@ -282,11 +326,20 @@ static int setup_hpet_irq(struct hpet_hld_data *hdata) if (ret) return ret; + /* Register the NMI handler, which will be the actual handler we use. */ + ret = register_nmi_handler(NMI_LOCAL, hardlockup_detector_nmi_handler, + 0, "hpet_hld"); + if (ret) + return ret; + /* * Request an interrupt to activate the irq in all the needed domains. */ ret = request_irq(hwirq, hardlockup_detector_irq_handler, - IRQF_TIMER, "hpet_hld", hdata); + IRQF_TIMER | IRQF_DELIVER_AS_NMI, + "hpet_hld", hdata); + if (ret) + unregister_nmi_handler(NMI_LOCAL, "hpet_hld"); return ret; }