From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98A4FC433F5 for ; Tue, 5 Apr 2022 13:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bAa3ag+eHX8eUhTi3RlJcWhQgJHohfQvH7/M85ReWfs=; b=NIZjaGzW52LPrn ExZSQ55+309MHeB7uD9mvY6PF36b4QHUr7i927IUb4/qtKUT/7U/wRmSIt04Ie7BtPZ9iQ6AnABje u5QLBhGjP7qXlA9Rq1SAwDN2qpIr+gI+204w+ZLTTShTJ0mM+5ckPXH432r6c6UbIMng4xmgQLhB+ yww5LC+tdBabx6ERwbIWqSnNhO8NFai71esrliWEn/AfnIvzhOQBhZqJgvF91DU9cCvQh8rC+KaCf o6//6ewqQK6I6EXGxdQvdrq0/TgA5lXT7T4R8zHaonlLLTQ5d5a+F/QuBpbwPGFfnLVnKIRjjuzE8 eJJyk8CUKt9Yf3GI/pzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbjUk-001CWC-Qe; Tue, 05 Apr 2022 13:45:18 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbjUf-001CV5-Q7; Tue, 05 Apr 2022 13:45:17 +0000 X-UUID: 3c1748a8f8b340d5af793c4df7a9f3b8-20220405 X-UUID: 3c1748a8f8b340d5af793c4df7a9f3b8-20220405 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1008122166; Tue, 05 Apr 2022 06:45:07 -0700 Received: from mtkmbs10n2.mediatek.inc (172.21.101.183) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 5 Apr 2022 06:35:05 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Tue, 5 Apr 2022 21:35:03 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 5 Apr 2022 21:35:03 +0800 From: Lecopzer Chen To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v3 4/5] kernel/watchdog: Adapt the watchdog_hld interface for async model Date: Tue, 5 Apr 2022 21:35:03 +0800 Message-ID: <20220405133503.4487-1-lecopzer.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220404144113.GB26840@pathway.suse.cz> References: <20220404144113.GB26840@pathway.suse.cz> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220405_064513_900745_8984F306 X-CRM114-Status: GOOD ( 47.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org > On Thu 2022-03-24 22:14:04, Lecopzer Chen wrote: > > 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 queued only when the early one returns -EBUSY. > > It is 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. > > > > 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 > > > > Co-developed-by: Pingfan Liu > > Signed-off-by: Pingfan Liu > > Signed-off-by: Lecopzer Chen > > Suggested-by: Petr Mladek > > --- > > include/linux/nmi.h | 3 ++ > > kernel/watchdog.c | 69 +++++++++++++++++++++++++++++++++++++++++++-- > > 2 files changed, 70 insertions(+), 2 deletions(-) > > > > diff --git a/include/linux/nmi.h b/include/linux/nmi.h > > index b7bcd63c36b4..1d84c9a8b460 100644 > > --- a/include/linux/nmi.h > > +++ b/include/linux/nmi.h > > @@ -118,6 +118,9 @@ static inline int hardlockup_detector_perf_init(void) { return 0; } > > > > void watchdog_nmi_stop(void); > > void watchdog_nmi_start(void); > > + > > +extern bool allow_lockup_detector_init_retry; > > +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 b71d434cf648..308ba29f8f0f 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. > > + * The error code -EBUSY is special. It means that a deferred probe > > + * might succeed later. > > + */ > > int __weak __init watchdog_nmi_probe(void) > > { > > return hardlockup_detector_perf_init(); > > @@ -839,16 +845,75 @@ static void __init watchdog_sysctl_init(void) > > #define watchdog_sysctl_init() do { } while (0) > > #endif /* CONFIG_SYSCTL */ > > > > +static void lockup_detector_delay_init(struct work_struct *work); > > +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; > > + } > > + > > + nmi_watchdog_available = true; > > + lockup_detector_setup(); > > The name of the variable "allow_lockup_detector_init_retry" is > slightly confusing in this context. I suggest to add a comment: > > /* Retry is not needed any longer. */ > > + allow_lockup_detector_init_retry = false; > Got it, I'll add it, thanks. > > > +} > > + > > +/* > > + * retry_lockup_detector_init - retry init lockup detector if possible. > > + * > > + * Only take effect when allow_lockup_detector_init_retry is true, which > > + * means it must call between lockup_detector_init() and lockup_detector_check(). > > + * Be aware that caller must have __init attribute, relative functions > > + * will be freed after kernel initialization. > > + */ > > +void __init retry_lockup_detector_init(void) > > +{ > > + if (!allow_lockup_detector_init_retry) > > + return; > > + > > + queue_work_on(__smp_processor_id(), system_wq, &detector_work); > > +} > > + > > +/* Ensure the check is called after the initialization of driver */ > > +static int __init lockup_detector_check(void) > > +{ > > + /* Make sure no work is pending. */ > > + flush_work(&detector_work); > > This is racy. We should first disable > "allow_lockup_detector_init_retry" to make sure > that retry_lockup_detector_init() will not queue > the work any longer. But disable before flush_work will make the lockup_detector_delay_init() -> watchdog_nmi_probe -> + if (!allow_lockup_detector_init_retry) + return -EBUSY; Plese check the code I provide below. > > > + if (!allow_lockup_detector_init_retry) > > + return 0; > > + > > + allow_lockup_detector_init_retry = false; > > + pr_info("Delayed init checking failed, please check your driver.\n"); > > This prints that the init failed without checking the state > of the watchdog. I guess that it works but it is far from > obvious and any further change might break it. > > Is the message really needed? > Does it help? > What exact driver needs checking? > > IMHO, it just makes the code more complicated and > it is not worth it. > I think you're right, the message was needed in the patch v2 because we did another retry in lockup_detector_check(). But now we only do "checking" and the failed message in lockup_detector_delay_init should be enough. > I suggest to keep it simple: > > /* > * Ensure the check is called after the initialization of driver > * and before removing init code. > */ > static int __init lockup_detector_check(void) > { > allow_lockup_detector_init_retry = false; > flush_work(&detector_work); > > return 0; > } > Combine with the first racy problem, let me limit retry_lockup_detector_init can be called only once. how about: ... static bool __init delayed_init_allowed = true; ... /* * retry_lockup_detector_init - retry init lockup detector if possible. * * Only take effect when allow_lockup_detector_init_retry is true, which * means it must call between lockup_detector_init() and lockup_detector_check(). * Be aware that caller must have __init attribute, relative functions * will be freed after kernel initialization. */ void __init retry_lockup_detector_init(void) { if (!allow_lockup_detector_init_retry || !delayed_init_allowed) return; /* * we shouldn't queue any delayed init work twice to avoid * any unwanted racy. */ delayed_init_allowed = false; queue_work_on(__smp_processor_id(), system_wq, &detector_work); } /* * Ensure the check is called after the initialization of driver * and before removing init code. */ static int __init lockup_detector_check(void) { delayed_init_allowed = false; flush_work(&detector_work); allow_lockup_detector_init_retry = false; return 0; } > or if you really want that message then I would do: > > /* > * Ensure the check is called after the initialization of driver > * and before removing init code. > */ > static int __init lockup_detector_check(void) > { > bool delayed_init_allowed = allow_lockup_detector_init_retry; > > allow_lockup_detector_init_retry = false; > flush_work(&detector_work); > > if (delayed_init_allowed && !nmi_watchdog_available) > pr_info("Delayed init failed. Please, check your driver.\n"); > > return 0; > } > thanks BRs, Lecopzer _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel