Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1946558img; Wed, 27 Feb 2019 08:06:52 -0800 (PST) X-Google-Smtp-Source: AHgI3IaD1r9f2AsKGGfDE8VMBmiCManIR4aetnbU6Tqqc2Y5XF5a8ZW4Xp382pDhb9g4p1eGHlUU X-Received: by 2002:a63:2ad4:: with SMTP id q203mr3728163pgq.43.1551283612633; Wed, 27 Feb 2019 08:06:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551283612; cv=none; d=google.com; s=arc-20160816; b=GWWTQSZss+EdNw1JVSKNZqy+7O0dZVU/GqpoLXDk5rfRcAMxa1Wyx6AJERFyprvG4B QNnVsArKIV1irgqwk5KXbS1h58FqTaIf+nGZIEL9ESeHoi25UWZTZe8WlSgjCd/l+/7J GkHsHQe1dAisOQSG/KyWOOpAMKpg78burtK54UFsKtxWC+KTK9ruknQLx/8+z6CAs3gz Mf0KAM8g5UOlv7++oq6Ie17Gfh2B4PSFByVgfikusFq4dXUbjuIsXe3OrAZmwnAYcynG InM0PtQforvQhM1sNNWqVVSJpcqPL5GM+y3VfMxzHhQfcOojHSdhjKcrckjq2rBzl67T SOqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=3s7T9AXfrCaT8ZJySHkzYnRPDEt+MF2YYAd6aV0y0/c=; b=PiRPca2UHXwt8SMzVG0RvoXBFiyuu2W+iIVzpbYBKFGKdm7oCc2KlSnTdqdI86V+8T BWB0jGXr2ou42mF5MOtYdXDPmWVQ0BT9mWizgzE8zgYBV0SbBqW4uTT8ZfRFX4Ob70jb nbLJ0BbJ8K8VWL3OWCt6XoKFPOedEgxNgiJa3eKTXEFEoMugbtb5VwDntttbJ9Tc0An7 q0gne7GNo1kpOvT7V6ffaSU1xK//GDjBtALN8GQSC+YHxGsA9u5vVEYv5LWG3VrlFzMW rMt4Ogp9Ja5mFX8fWV1xPxBzBtYleyjWuPV11iAEO/D74Y35jgYk3oD11y5JubkHjzgx 1uCg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v190si14994584pgd.584.2019.02.27.08.06.36; Wed, 27 Feb 2019 08:06:52 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730137AbfB0QGD (ORCPT + 99 others); Wed, 27 Feb 2019 11:06:03 -0500 Received: from mga02.intel.com ([134.134.136.20]:24160 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730062AbfB0QF7 (ORCPT ); Wed, 27 Feb 2019 11:05:59 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2019 08:05:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,420,1544515200"; d="scan'208";a="303011741" Received: from unknown (HELO luv-build.sc.intel.com) ([172.25.110.25]) by orsmga005.jf.intel.com with ESMTP; 27 Feb 2019 08:05:56 -0800 From: Ricardo Neri To: Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Ashok Raj , Andi Kleen , Peter Zijlstra , "Ravi V. Shankar" , x86@kernel.org, linux-kernel@vger.kernel.org, Ricardo Neri , Ricardo Neri , "H. Peter Anvin" , Tony Luck , Clemens Ladisch , Arnd Bergmann , Philippe Ombredanne , Kate Stewart , "Rafael J. Wysocki" , Mimi Zohar , Jan Kiszka , Nick Desaulniers , Masahiro Yamada , Nayna Jain Subject: [RFC PATCH v2 14/14] x86/watchdog: Add a shim hardlockup detector Date: Wed, 27 Feb 2019 08:05:18 -0800 Message-Id: <1551283518-18922-15-git-send-email-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551283518-18922-1-git-send-email-ricardo.neri-calderon@linux.intel.com> References: <1551283518-18922-1-git-send-email-ricardo.neri-calderon@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The generic hardlockup detector is based on perf. It also provides a set of weak stubs that CPU architectures can override. Add a shim hardlockup detector for x86 that selects between perf and hpet implementations. Specifically, this shim implementation is needed for the HPET-based hardlockup detector; it can also be used for future implementations. Cc: "H. Peter Anvin" Cc: Ashok Raj Cc: Andi Kleen Cc: Tony Luck Cc: Peter Zijlstra Cc: Clemens Ladisch Cc: Arnd Bergmann Cc: Philippe Ombredanne Cc: Kate Stewart Cc: "Rafael J. Wysocki" Cc: Mimi Zohar Cc: Jan Kiszka Cc: Nick Desaulniers Cc: Masahiro Yamada Cc: Nayna Jain Cc: "Ravi V. Shankar" Cc: x86@kernel.org Suggested-by: Nicholas Piggin Signed-off-by: Ricardo Neri --- arch/x86/Kconfig.debug | 4 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/watchdog_hld.c | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 arch/x86/kernel/watchdog_hld.c diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug index 3a2845a29e8a..5e5f4d2330af 100644 --- a/arch/x86/Kconfig.debug +++ b/arch/x86/Kconfig.debug @@ -169,10 +169,14 @@ config IOMMU_LEAK config HAVE_MMIOTRACE_SUPPORT def_bool y +config X86_HARDLOCKUP_DETECTOR + bool + config X86_HARDLOCKUP_DETECTOR_HPET bool "Use HPET Timer for Hard Lockup Detection" select SOFTLOCKUP_DETECTOR select HARDLOCKUP_DETECTOR + select X86_HARDLOCKUP_DETECTOR depends on HPET_TIMER && HPET && X86_64 help Say y to enable a hardlockup detector that is driven by an High- diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 9d610e8a9224..5372453fe2a7 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -106,6 +106,7 @@ obj-$(CONFIG_VM86) += vm86_32.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-$(CONFIG_HPET_TIMER) += hpet.o +obj-$(CONFIG_X86_HARDLOCKUP_DETECTOR) += watchdog_hld.o obj-$(CONFIG_X86_HARDLOCKUP_DETECTOR_HPET) += watchdog_hld_hpet.o obj-$(CONFIG_APB_TIMER) += apb_timer.o diff --git a/arch/x86/kernel/watchdog_hld.c b/arch/x86/kernel/watchdog_hld.c new file mode 100644 index 000000000000..a2f6190dbce0 --- /dev/null +++ b/arch/x86/kernel/watchdog_hld.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * A shim hardlockup detector. It simply overrides the weak stubs of the + * generic implementation. + * + * Copyright (C) Intel Corporation 2019 + */ + +#include +#include + +enum x86_hardlockup_detector { + X86_HARDLOCKUP_DETECTOR_PERF, + X86_HARDLOCKUP_DETECTOR_HPET, +}; + +static enum __read_mostly x86_hardlockup_detector detector_type; + +int watchdog_nmi_enable(unsigned int cpu) +{ + if (detector_type == X86_HARDLOCKUP_DETECTOR_PERF) { + hardlockup_detector_perf_enable(); + return 0; + } + + if (detector_type == X86_HARDLOCKUP_DETECTOR_HPET) { + hardlockup_detector_hpet_enable(); + return 0; + } + + return -ENODEV; +} + +void watchdog_nmi_disable(unsigned int cpu) +{ + if (detector_type == X86_HARDLOCKUP_DETECTOR_PERF) { + hardlockup_detector_perf_disable(); + return; + } + + if (detector_type == X86_HARDLOCKUP_DETECTOR_HPET) { + hardlockup_detector_hpet_disable(); + return; + } +} + +int __init watchdog_nmi_probe(void) +{ + int ret; + + /* + * Try first with the HPET hardlockup detector. It will only + * succeed if selected at build time and the nmi_watchdog + * command-line parameter is configured. This ensure that the + * perf-based detector is used by default, if selected at + * build time. + */ + ret = hardlockup_detector_hpet_init(); + if (!ret) { + detector_type = X86_HARDLOCKUP_DETECTOR_HPET; + return ret; + } + + ret = hardlockup_detector_perf_init(); + if (!ret) { + detector_type = X86_HARDLOCKUP_DETECTOR_PERF; + return ret; + } + + return ret; +} + +void watchdog_nmi_stop(void) +{ + /* Only the HPET lockup detector defines a stop function. */ + if (detector_type == X86_HARDLOCKUP_DETECTOR_HPET) + hardlockup_detector_hpet_enable(); +} -- 2.17.1