From: Lecopzer Chen <lecopzer.chen@mediatek.com>
To: <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>,
<linux-perf-users@vger.kernel.org>, <mark.rutland@arm.com>,
<will@kernel.org>
Cc: <lecopzer.chen@mediatek.com>, <acme@kernel.org>,
<akpm@linux-foundation.org>, <alexander.shishkin@linux.intel.com>,
<catalin.marinas@arm.com>, <davem@davemloft.net>,
<jolsa@redhat.com>, <jthierry@redhat.com>,
<keescook@chromium.org>, <kernelfans@gmail.com>,
<masahiroy@kernel.org>, <matthias.bgg@gmail.com>,
<maz@kernel.org>, <mcgrof@kernel.org>, <mingo@redhat.com>,
<namhyung@kernel.org>, <nixiaoming@huawei.com>,
<peterz@infradead.org>, <pmladek@suse.com>,
<sparclinux@vger.kernel.org>, <sumit.garg@linaro.org>,
<wangqing@vivo.com>, <yj.chiang@mediatek.com>
Subject: [PATCH v7 4/6] kernel/watchdog: Adapt the watchdog_hld interface for async model
Date: Sat, 3 Sep 2022 17:34:13 +0800 [thread overview]
Message-ID: <20220903093415.15850-5-lecopzer.chen@mediatek.com> (raw)
In-Reply-To: <20220903093415.15850-1-lecopzer.chen@mediatek.com>
When lockup_detector_init()->watchdog_nmi_probe(), PMU may be not ready
yet. E.g. on arm64, PMU is not ready until
device_initcall(armv8_pmu_driver_init). And it is deeply integrated
with the driver model and cpuhp. Hence it is hard to push this
initialization before smp_init().
But it is easy to take an opposite approach and try to initialize
the watchdog once again later.
The delayed probe is called using workqueues. It need to allocate
memory and must be proceed in a normal context.
The delayed probe is able to use if watchdog_nmi_probe() returns
non-zero which means the return code returned when PMU is not ready yet.
Provide an API - retry_lockup_detector_init() for anyone who needs
to delayed init lockup detector if they had ever failed at
lockup_detector_init().
The original assumption is: nobody should use delayed probe after
lockup_detector_check() which has __init attribute.
That is, anyone uses this API must call between lockup_detector_init()
and lockup_detector_check(), and the caller must have __init attribute
Reviewed-by: Petr Mladek <pmladek@suse.com>
Co-developed-by: Pingfan Liu <kernelfans@gmail.com>
Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Signed-off-by: Lecopzer Chen <lecopzer.chen@mediatek.com>
Suggested-by: Petr Mladek <pmladek@suse.com>
Reported-by: kernel test robot <lkp@intel.com>
---
include/linux/nmi.h | 2 ++
kernel/watchdog.c | 67 ++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/include/linux/nmi.h b/include/linux/nmi.h
index 81217ebbc4bd..7f128e3aae38 100644
--- a/include/linux/nmi.h
+++ b/include/linux/nmi.h
@@ -118,6 +118,8 @@ static inline int hardlockup_detector_perf_init(void) { return 0; }
void watchdog_nmi_stop(void);
void watchdog_nmi_start(void);
+
+void retry_lockup_detector_init(void);
int watchdog_nmi_probe(void);
void watchdog_nmi_enable(unsigned int cpu);
void watchdog_nmi_disable(unsigned int cpu);
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index c705a18b26bf..0b650d726e50 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -103,7 +103,13 @@ void __weak watchdog_nmi_disable(unsigned int cpu)
hardlockup_detector_perf_disable();
}
-/* Return 0, if a NMI watchdog is available. Error code otherwise */
+/*
+ * Arch specific API.
+ *
+ * Return 0 when NMI watchdog is available, negative value otherwise.
+ * Note that the negative value means that a delayed probe might
+ * succeed later.
+ */
int __weak __init watchdog_nmi_probe(void)
{
return hardlockup_detector_perf_init();
@@ -850,6 +856,62 @@ static void __init watchdog_sysctl_init(void)
#define watchdog_sysctl_init() do { } while (0)
#endif /* CONFIG_SYSCTL */
+static void __init lockup_detector_delay_init(struct work_struct *work);
+static bool allow_lockup_detector_init_retry __initdata;
+
+static struct work_struct detector_work __initdata =
+ __WORK_INITIALIZER(detector_work, lockup_detector_delay_init);
+
+static void __init lockup_detector_delay_init(struct work_struct *work)
+{
+ int ret;
+
+ ret = watchdog_nmi_probe();
+ if (ret) {
+ pr_info("Delayed init of the lockup detector failed: %d\n", ret);
+ pr_info("Perf NMI watchdog permanently disabled\n");
+ return;
+ }
+
+ allow_lockup_detector_init_retry = false;
+
+ nmi_watchdog_available = true;
+ lockup_detector_setup();
+}
+
+/*
+ * retry_lockup_detector_init - retry init lockup detector if possible.
+ *
+ * Retry hardlockup detector init. It is useful when it requires some
+ * functionality that has to be initialized later on a particular
+ * platform.
+ */
+void __init retry_lockup_detector_init(void)
+{
+ /* Must be called before late init calls */
+ if (!allow_lockup_detector_init_retry)
+ return;
+
+ schedule_work(&detector_work);
+}
+
+/*
+ * Ensure that optional delayed hardlockup init is proceed before
+ * the init code and memory is freed.
+ */
+static int __init lockup_detector_check(void)
+{
+ /* Prevent any later retry. */
+ allow_lockup_detector_init_retry = false;
+
+ /* Make sure no work is pending. */
+ flush_work(&detector_work);
+
+ return 0;
+
+}
+late_initcall_sync(lockup_detector_check);
+
void __init lockup_detector_init(void)
{
if (tick_nohz_full_enabled())
@@ -860,6 +922,9 @@ void __init lockup_detector_init(void)
if (!watchdog_nmi_probe())
nmi_watchdog_available = true;
+ else
+ allow_lockup_detector_init_retry = true;
+
lockup_detector_setup();
watchdog_sysctl_init();
}
--
2.34.1
next prev parent reply other threads:[~2022-09-03 9:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-03 9:34 [PATCH v7 0/6] Support hld delayed init based on Pseudo-NMI for Lecopzer Chen
2022-09-03 9:34 ` [PATCH v7 1/6] kernel/watchdog: remove WATCHDOG_DEFAULT Lecopzer Chen
2022-09-03 9:34 ` [PATCH v7 2/6] kernel/watchdog: change watchdog_nmi_enable() to void Lecopzer Chen
2022-09-03 9:34 ` [PATCH v7 3/6] kernel/watchdog_hld: Ensure CPU-bound context when creating hardlockup detector event Lecopzer Chen
2022-09-03 9:34 ` Lecopzer Chen [this message]
2022-09-03 9:34 ` [PATCH v7 5/6] arm64: add hw_nmi_get_sample_period for preparation of lockup detector Lecopzer Chen
2022-09-03 9:34 ` [PATCH v7 6/6] arm64: Enable perf events based hard " Lecopzer Chen
2022-09-04 22:57 ` kernel test robot
2022-09-03 9:45 ` [PATCH v7 0/6] Support hld delayed init based on Pseudo-NMI for arm64 Lecopzer Chen
2022-11-07 15:18 ` [PATCH v7 0/6] Support hld delayed init based on Pseudo-NMI for Will Deacon
2023-05-04 22:41 ` Doug Anderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220903093415.15850-5-lecopzer.chen@mediatek.com \
--to=lecopzer.chen@mediatek.com \
--cc=acme@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=catalin.marinas@arm.com \
--cc=davem@davemloft.net \
--cc=jolsa@redhat.com \
--cc=jthierry@redhat.com \
--cc=keescook@chromium.org \
--cc=kernelfans@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=masahiroy@kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=maz@kernel.org \
--cc=mcgrof@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=nixiaoming@huawei.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=sparclinux@vger.kernel.org \
--cc=sumit.garg@linaro.org \
--cc=wangqing@vivo.com \
--cc=will@kernel.org \
--cc=yj.chiang@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).