Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp820519rwb; Sat, 3 Sep 2022 03:32:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR6xoKrRBM6b07oy48NyYTThAq4ldQrzk4qqadhVqCo4hdpfB6swiBZu+LV7qIPdeo/BpT+L X-Received: by 2002:a63:85c2:0:b0:42b:497d:e06a with SMTP id u185-20020a6385c2000000b0042b497de06amr34485903pgd.479.1662201140284; Sat, 03 Sep 2022 03:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662201140; cv=none; d=google.com; s=arc-20160816; b=Ow2/o2K6eimVlDkHGnzTNngcqExHn4ivtVl/ss3hvAFMaMUaaFnihVkIhaXvUtYoov oDZeLP28613EQOZIwNDdPLCanU3Wrnm1qYNePke5QYLOAd/PyT5jEzgkMqcbaW7g/WW+ E+kw4/51h83zMe7vRDzJv3TPNK+JQ1W723k0qEAA7eygF80nPSp4AtDnN9/c/i4SfL1t h1BFgXwGRRkBC0381iiPjEmdEYf3vbCbQnyATohgsGufyMuHwR1hfSkpQRqdVovTWsvY f/n4jCDx3CicrTr5uZidyXnoZgOMs1/nWdPhGICFhkM5ZOHOZ2H1yflUNjcQAEMkTgxE Udzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=MKjPOQSfw4i+nosmT0Yk7Xpa23Skr63LcOCzDbNQ9cM=; b=MS6i1azumISSYzJgKaBxPUKwlrK/KU8gYD8P/14nEuaciNZ+9XhKF4jP1JtIXTuO83 SvP+7SOGF6jOv9Zs6gkEgb4VwCopgj1/Zw607ui5quZQid27Y3OYHu8ty4GAXOXtwwiL N/bbTrV+YrrS2eyGs/hspK9hO/TSUQE37BYZJGGupuOVajELaDlmDlqq1VgumAv1ySOy HSbfYF99nRCO+Jwwbt5NowGlAo/1jwpdauc1gI9cc9NuEHYTzMnWCcGJIbvcurqW7joA oBFQ6YnHZwvkaoiUGXiJ5wRzliF1FZDTtGT7GBK6af0iUyKbkRPj5VMSkfwxaebIa/tI wuTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=NA53436T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i4-20020aa78b44000000b0052e03a6013fsi4172892pfd.126.2022.09.03.03.32.08; Sat, 03 Sep 2022 03:32:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=NA53436T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233125AbiICJez (ORCPT + 99 others); Sat, 3 Sep 2022 05:34:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232860AbiICJei (ORCPT ); Sat, 3 Sep 2022 05:34:38 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7725E20F45; Sat, 3 Sep 2022 02:34:36 -0700 (PDT) X-UUID: e159e1125547489db4b8ed5e3b46692a-20220903 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=MKjPOQSfw4i+nosmT0Yk7Xpa23Skr63LcOCzDbNQ9cM=; b=NA53436TGFpAN18RC/kl8XW8TIL/JiQpRpBB/rmy4RENqPAKKOzOx34PJ77dmYv+fJLMmSR8AdcA1thykSGUHjnSBH6Zx+xkuupMoX+cA6FpXKYo+/HReB1I/kht3ZS4la+ewiHv2B7T2zvKT3cOprlFLI7CYaLWh1E3KXlka3s=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.10,REQID:e78fed9e-e994-4927-bb47-c635915d72e0,OB:0,L OB:0,IP:0,URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Releas e_Ham,ACTION:release,TS:-25 X-CID-META: VersionHash:84eae18,CLOUDID:d36f0521-1c20-48a5-82a0-25f9c331906d,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil ,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: e159e1125547489db4b8ed5e3b46692a-20220903 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1095855068; Sat, 03 Sep 2022 17:34:18 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.3; Sat, 3 Sep 2022 17:34:17 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Sat, 3 Sep 2022 17:34:17 +0800 From: Lecopzer Chen To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v7 4/6] kernel/watchdog: Adapt the watchdog_hld interface for async model Date: Sat, 3 Sep 2022 17:34:13 +0800 Message-ID: <20220903093415.15850-5-lecopzer.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220903093415.15850-1-lecopzer.chen@mediatek.com> References: <20220903093415.15850-1-lecopzer.chen@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,RDNS_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY, URIBL_CSS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Co-developed-by: Pingfan Liu Signed-off-by: Pingfan Liu Signed-off-by: Lecopzer Chen Suggested-by: Petr Mladek Reported-by: kernel test robot --- 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