From patchwork Thu Oct 14 02:41:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 12557681 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F7F1C433EF for ; Thu, 14 Oct 2021 02:45:22 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7195B61130 for ; Thu, 14 Oct 2021 02:45:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7195B61130 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=ciKS0SuU+GBrxceD44Oppq6gAMr1QDX00PEQfPv5cSo=; b=dEFu/WQlNu0HuR WQalnwAFHh0rS0GxXJXtzIlpL/K6lAK6Tk28rKyRZ+vk+8+TPmFs4FLXHIGuwji7pfJBAPvZp7RgO 56ABzvCqKRUrm8hndSLCJ3QqSJnfoanoBDKPf5FfeOCQ3lySPLh8jZsfpbE9YRLCr+zeuY4PsIRry LLAhbPXfY9C1JEg5T6HD6D/RVE5Z5cmOPkmUdYTK3JRp9OIjZPkm19El/8pUyaXyJgHhFGO8Y6pY3 Hxi87uer/bBFtSufxWGDmWb/gFAD4iUblR/Dh1mDQX/d1hppjcSTu7If5l6LjHZqzp9pEhDJog28j d3YonBMpXnCTwKTyAoDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1maqhl-001Il9-4N; Thu, 14 Oct 2021 02:42:49 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1maqhN-001Idz-VN for linux-arm-kernel@lists.infradead.org; Thu, 14 Oct 2021 02:42:27 +0000 Received: by mail-pl1-x62c.google.com with SMTP id n11so3138668plf.4 for ; Wed, 13 Oct 2021 19:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MCXL1wxbIIPtVPUvxM8dtdoMd+TQ/MoVrnyuxcC09GE=; b=FaGvFeFK7B5vD2fuaQKs3c9JWuSrhIAaB/JnMeXsYhkiT3ielLvLFlqHV+2RivA8YZ Pkqgcnp6ps4TBY65YZeCYsGK59FDt7jmNGUAmXNHP9BYq2hz3ExFYblx6xeLK1wxLaIv 5S+PgFwx/WOmjCW7zzpyFm3PnlNm9TnlgNdhetCwLYtw31prKPIptI9Ppdkf3WPvzt8N zoUY4vqp5YH9owOnAKALXjwMgSAJhHIYU+RWmeJuvgoAgwAtStFlB3Hk1Ohq3Uiid5Vo GOR1TJhEMoAHsUUVWhTkrPzxQsKVck56FddkSju8OIazy4OlIU2iz+MtWRIN5TibltzR vefA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MCXL1wxbIIPtVPUvxM8dtdoMd+TQ/MoVrnyuxcC09GE=; b=pUlKpMoerUIKGB1IJ7lgJ0sknic5F6DrGCuEWx0cSAIUJD/paD4B2Nvhqfh+02BJD4 Vcok5Jf14mgOoWuHQJSUCxDZS1ZRJxlQKhBjHrbq6Yt4e1obbM4ZFxkSrb9nlHEy97pF hF5C1nR9A/LOD1M7lzrcHl7nunMcGvr+9shd16hZXeSDZNTCvUblRM/jWuEKBpenAaAX vHf1F35f1bUYDGTCGiGC1vzxGqI+cTYPCKDQJd3Oig66xhc9KUojqXofT+7Z4PMXVOL8 0s7tE/Y/WAde8/nrjauj60pkK3f3hX672nwKGTkAytkuUSHqJ6HC7flMaZIXKmn3M5Ac Vghg== X-Gm-Message-State: AOAM531jtQcDhBEX7i+OhsGU6wQPa4Tmk/qcVid/y89nNattFeRxtlKn Ec10CVAPo6PghcXMOcuWmg== X-Google-Smtp-Source: ABdhPJzQThXgZOxXmw2uYnollO+CHFsrzcj2LwY1rvFejhCwsA8wZZvMcg1/bdTITlfgBpi5ypRaVQ== X-Received: by 2002:a17:902:d501:b0:13f:1b44:baa2 with SMTP id b1-20020a170902d50100b0013f1b44baa2mr2709101plg.56.1634179343578; Wed, 13 Oct 2021 19:42:23 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m28sm818403pgl.9.2021.10.13.19.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 19:42:23 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org Cc: Pingfan Liu , Sumit Garg , Catalin Marinas , Will Deacon , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Marc Zyngier , Kees Cook , Masahiro Yamada , Sami Tolvanen , Petr Mladek , Andrew Morton , Wang Qing , "Peter Zijlstra (Intel)" , Santosh Sivaraj , linux-arm-kernel@lists.infradead.org Subject: [PATCHv3 3/4] kernel/watchdog: Adapt the watchdog_hld interface for async model Date: Thu, 14 Oct 2021 10:41:54 +0800 Message-Id: <20211014024155.15253-4-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211014024155.15253-1-kernelfans@gmail.com> References: <20211014024155.15253-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211013_194226_045901_6E59AD4B X-CRM114-Status: GOOD ( 22.01 ) 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 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 by enabling watchdog_hld to get the capability of PMU async. The async model is achieved by expanding watchdog_nmi_probe() with -EBUSY, and a re-initializing work_struct which waits on a wait_queue_head. Signed-off-by: Pingfan Liu Cc: Sumit Garg Cc: Catalin Marinas Cc: Will Deacon Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Marc Zyngier Cc: Kees Cook Cc: Masahiro Yamada Cc: Sami Tolvanen Cc: Petr Mladek Cc: Andrew Morton Cc: Wang Qing Cc: "Peter Zijlstra (Intel)" Cc: Santosh Sivaraj Cc: linux-arm-kernel@lists.infradead.org To: linux-kernel@vger.kernel.org --- include/linux/nmi.h | 9 +++++++ kernel/watchdog.c | 57 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/include/linux/nmi.h b/include/linux/nmi.h index b7bcd63c36b4..9def85c00bd8 100644 --- a/include/linux/nmi.h +++ b/include/linux/nmi.h @@ -118,6 +118,15 @@ static inline int hardlockup_detector_perf_init(void) { return 0; } void watchdog_nmi_stop(void); void watchdog_nmi_start(void); + +enum hld_detector_state { + DELAY_INIT_NOP, + DELAY_INIT_WAIT, + DELAY_INIT_READY +}; + +extern enum hld_detector_state detector_delay_init_state; +extern struct wait_queue_head hld_detector_wait; 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 6e6dd5f0bc3e..2f267d21a7a1 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -103,7 +103,11 @@ 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, if a NMI watchdog is available. -EBUSY if not + * ready, and arch code should wake up hld_detector_wait when ready. Other + * negative value if not support. + */ int __weak __init watchdog_nmi_probe(void) { return hardlockup_detector_perf_init(); @@ -739,15 +743,64 @@ int proc_watchdog_cpumask(struct ctl_table *table, int write, } #endif /* CONFIG_SYSCTL */ +static void lockup_detector_delay_init(struct work_struct *work); +enum hld_detector_state detector_delay_init_state __initdata; + +struct wait_queue_head hld_detector_wait __initdata = + __WAIT_QUEUE_HEAD_INITIALIZER(hld_detector_wait); + +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; + + wait_event(hld_detector_wait, + detector_delay_init_state == DELAY_INIT_READY); + ret = watchdog_nmi_probe(); + if (!ret) { + nmi_watchdog_available = true; + lockup_detector_setup(); + } else { + WARN_ON(ret == -EBUSY); + pr_info("Perf NMI watchdog permanently disabled\n"); + } +} + +/* Ensure the check is called after the initialization of PMU driver */ +static int __init lockup_detector_check(void) +{ + if (detector_delay_init_state < DELAY_INIT_WAIT) + return 0; + + if (WARN_ON(detector_delay_init_state == DELAY_INIT_WAIT)) { + detector_delay_init_state = DELAY_INIT_READY; + wake_up(&hld_detector_wait); + } + flush_work(&detector_work); + return 0; +} +late_initcall_sync(lockup_detector_check); + + void __init lockup_detector_init(void) { + int ret; + if (tick_nohz_full_enabled()) pr_info("Disabling watchdog on nohz_full cores by default\n"); cpumask_copy(&watchdog_cpumask, housekeeping_cpumask(HK_FLAG_TIMER)); - if (!watchdog_nmi_probe()) + ret = watchdog_nmi_probe(); + if (!ret) nmi_watchdog_available = true; + else if (ret == -EBUSY) { + detector_delay_init_state = DELAY_INIT_WAIT; + queue_work_on(smp_processor_id(), system_wq, &detector_work); + } + lockup_detector_setup(); }