From patchwork Thu May 4 22:13:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13231889 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 BF79FC7EE26 for ; Thu, 4 May 2023 22:41:07 +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=+S86iBoiUU2Yn2UADcGuNncSF+GZGsU1YYQYIaKeEsU=; b=oZghUICY/JzzzL ALuk26XLQCoaHFvzplxTcUEPRnh4glR1L2dJHXGkjGbS5ViScO6KMPJEwGx+lOHZ2GjHeQcT9oKk8 e0/TzpK/ZTzPA0qDH2V9vgv6m+/OUuSS0l8dEx6bd97ZYuOpMcOetNcGSFqixWgILH0Zm3F+QWye5 ZvL9m1qCn6R+MAYH0qWNb3xrtHSFdJdRkdKsbNPxsdw0apgAPIxJZV4az3DnwP7H/3Axmt3VxRY2G LrJCANCbUO6tw+ixFrnq522KoDdnmRWJqrk22S0eP8uQTH4zxBLFusWIV1uSR5KF4wHjPjmOcmbM/ gEfyVyr5P8OYhxMwClgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1puhcW-009EG3-2T; Thu, 04 May 2023 22:40:16 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1puhcV-009EFF-03 for linux-arm-kernel@bombadil.infradead.org; Thu, 04 May 2023 22:40:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Cb+ov5fy8GT79FMmcyf1ZMUm58eKGi3E0UeboMl9k0k=; b=BBitqiM7KW/TCV8WZoKlq4BAXC 764kuhbBK292SlrAbGCGXzrmymQn7nnN/FeNkRrhyNIwcJjDUz/rboyBkKT/2vJs8d6y93mc0weR7 jyFPBOVcE+f+gAL37feoxpIU4pZi3vIpFbssKazyDegSDcTHQQDpT/t1wC9szIBivP2OdQJoT8Z+t 3Blq/uqP3xfTBuplDik4q6HEXidvgbtRHEn6esEVCq7zuZzTcJaPUkoR5ifseSVKbxqqWTKnUrELD oumyx16Af5UftTO/hbtr5qv8SFyl2FE4l1f1YCvVzKYLnjxJ6Rp/vIjdIBNTmYjZm1dpuKucfeyxg /wXe4Dig==; Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1puhEa-001sup-2F for linux-arm-kernel@lists.infradead.org; Thu, 04 May 2023 22:15:35 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-64395e741fcso969508b3a.2 for ; Thu, 04 May 2023 15:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1683238531; x=1685830531; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cb+ov5fy8GT79FMmcyf1ZMUm58eKGi3E0UeboMl9k0k=; b=CjMBjXb4dakIH/Hz1W+AbgyxL0xcYhy7OZZf09KX3sDf9yAF4rhCtWuKzwEhAs+5/i hEzlyTV4xhw3Mp/uMdYzUq9UGSlBG4bqWtY9NWExnwuQfYOMW8tNfC51A60DvQW7afZn h/GwPSH86KKBgViH3tcM+m/6e9fAaR1bB8IPk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683238531; x=1685830531; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cb+ov5fy8GT79FMmcyf1ZMUm58eKGi3E0UeboMl9k0k=; b=SKCOCnMjUwjPK2kL9yGxAWhAS70LkzxBhO7PVymccxh+M9ol2gS1O3EOEFtl15jbz+ xGBghZcqWvIcSUjwFGe7z13Al/Etv+jn5qIuQoltP4/6TWmgjYGZZ7bZqm5oKxbbypnE NqGzsgYUEqWa9azEjSVsZR1zbm7wtvvHqri/HZl30w4i1t+dc5e+atqcKU51JGlnCC+o O7i9NPA45p+42GbRx/8lAAjHk2ofcMPRYWR3A4tj4GyNYEdsSIsyQr/ACVCGllqIdv53 8l8fyIuq1CVD49o6xKlZqQByW4wXAFPnhI2qXDUN8FZaDrBsfZwLYEJMAowH04524Mxv w71Q== X-Gm-Message-State: AC+VfDzB9Jll41wulYxSQXoANUhPlf16YvLmo2WKmqtIZwRSid1Bk0rT JBIkvcRnwqQhQsAwW/ZKmxFsiQ== X-Google-Smtp-Source: ACHHUZ4X6wdGMyW/UcCstp1VEpR79rnk9KRzJXDwHbVx8n04QbMhxm2ST+x4EIRRDKqxPh/P32rORQ== X-Received: by 2002:a05:6a00:80f:b0:5a8:8535:18b with SMTP id m15-20020a056a00080f00b005a88535018bmr4857970pfk.11.1683238531276; Thu, 04 May 2023 15:15:31 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:edf0:7321:6b9e:d5e7]) by smtp.gmail.com with ESMTPSA id g26-20020aa7819a000000b006437c0edf9csm169615pfi.16.2023.05.04.15.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 15:15:30 -0700 (PDT) From: Douglas Anderson To: Petr Mladek , Andrew Morton Cc: Sumit Garg , Mark Rutland , Matthias Kaehlcke , Stephane Eranian , Stephen Boyd , ricardo.neri@intel.com, Tzung-Bi Shih , Lecopzer Chen , kgdb-bugreport@lists.sourceforge.net, Masayoshi Mizuma , Guenter Roeck , Pingfan Liu , Andi Kleen , Ian Rogers , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, ito-yuichi@fujitsu.com, Randy Dunlap , Chen-Yu Tsai , christophe.leroy@csgroup.eu, davem@davemloft.net, sparclinux@vger.kernel.org, mpe@ellerman.id.au, Will Deacon , ravi.v.shankar@intel.com, npiggin@gmail.com, linuxppc-dev@lists.ozlabs.org, Marc Zyngier , Catalin Marinas , Daniel Thompson , Douglas Anderson Subject: [PATCH v4 15/17] watchdog/perf: Adapt the watchdog_perf interface for async model Date: Thu, 4 May 2023 15:13:47 -0700 Message-ID: <20230504151100.v4.15.If4ad5dd5d09fb1309cebf8bcead4b6a5a7758ca7@changeid> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog In-Reply-To: <20230504221349.1535669-1-dianders@chromium.org> References: <20230504221349.1535669-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230504_231533_041371_D2FAE47A X-CRM114-Status: GOOD ( 33.39 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Lecopzer Chen When lockup_detector_init()->watchdog_hardlockup_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_hardlockup_probe() returns non-zero which means the return code returned when PMU is not ready yet. Provide an API - lockup_detector_retry_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 Signed-off-by: Douglas Anderson --- I yanked this patch from the mailing lists [1] into my series just to make it easier to avoid conflicts between my series and the one adding the arm64 perf hardlockup detector, in case someone wanted to test them both together. As part of making this match with my series, I resolved a few conflicts and did a few renames. I also fixed the kernel test robot yell [2] by providing a dummy implementation of the retry function if CONFIG_LOCKUP_DETECTOR wasn't defined. That led me to move the definition of the function and sanitize the name of the function to match others around it. This patch makes less sense without the patches to add support for the arm64 perf hardlockup detector. Thus, I've put it at the end of the series. I removed the "kernel test robot" tag since that didn't really make sense. Presumably the robot found a problem on a previous version of the patch, but that's not normally a reason to add the Reported-by. [1] https://lore.kernel.org/r/20220903093415.15850-5-lecopzer.chen@mediatek.com/ [2] https://lore.kernel.org/r/202209050639.jDaWd49E-lkp@intel.com/ Changes in v4: - Pulled ("Adapt the watchdog_hld interface ...") into my series for v4. 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 9caea5ba494d..3cacc5fc16b9 100644 --- a/include/linux/nmi.h +++ b/include/linux/nmi.h @@ -13,6 +13,7 @@ #ifdef CONFIG_LOCKUP_DETECTOR void lockup_detector_init(void); +void lockup_detector_retry_init(void); void lockup_detector_soft_poweroff(void); void lockup_detector_cleanup(void); @@ -34,6 +35,7 @@ extern int sysctl_hardlockup_all_cpu_backtrace; #else /* CONFIG_LOCKUP_DETECTOR */ static inline void lockup_detector_init(void) { } +static inline void lockup_detector_retry_init(void) { } static inline void lockup_detector_soft_poweroff(void) { } static inline void lockup_detector_cleanup(void) { } #endif /* !CONFIG_LOCKUP_DETECTOR */ diff --git a/kernel/watchdog.c b/kernel/watchdog.c index 678d55172ef4..55471634d932 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -211,7 +211,13 @@ void __weak watchdog_hardlockup_enable(unsigned int cpu) { } void __weak watchdog_hardlockup_disable(unsigned int cpu) { } -/* Return 0, if a hardlockup watchdog is available. Error code otherwise */ +/* + * Watchdog-detector specific API. + * + * Return 0 when hardlockup watchdog is available, negative value otherwise. + * Note that the negative value means that a delayed probe might + * succeed later. + */ int __weak __init watchdog_hardlockup_probe(void) { /* @@ -957,6 +963,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_hardlockup_probe(); + if (ret) { + pr_info("Delayed init of the lockup detector failed: %d\n", ret); + pr_info("Hard watchdog permanently disabled\n"); + return; + } + + allow_lockup_detector_init_retry = false; + + nmi_watchdog_available = true; + lockup_detector_setup(); +} + +/* + * lockup_detector_retry_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 lockup_detector_retry_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()) @@ -967,6 +1029,9 @@ void __init lockup_detector_init(void) if (!watchdog_hardlockup_probe()) nmi_watchdog_available = true; + else + allow_lockup_detector_init_retry = true; + lockup_detector_setup(); watchdog_sysctl_init(); }