From patchwork Fri Feb 21 02:35:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Cherian X-Patchwork-Id: 13984759 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 071F93C2F; Fri, 21 Feb 2025 02:36:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740105384; cv=none; b=YLNBKYRgzI0OqW7DI9FpGZAv/x8yhia0E2EQQKco2F0LqkzLeGzw8qSoZ/OBj0rKLuAajWwunNyTX793hsUFAhYUxUs8Ofa6xfDe1+hhk3UJsUw0zqtq71kPj5a9bTBq9oT09OvOuOlUR/Tv4AYeaBtWVufr+pRwNE6GiWDIYvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740105384; c=relaxed/simple; bh=bZK0D6NskJV20GTUtw762wIucpi7jyCaWV4efMBFBJw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=G72ityn/Td9vgN15llGRztZjQOww5vlWJ5ldggcOZqV9vpvb4kQbvMZAL1nlQcgbbNa7zEl+ioZNDkVAbp/YSx3wZz1fGz5WGaLpz1+cXnYj5W2I4y+Sk4gCrZHOKvPX1dtlysn4m/ucns63bXIVxCgA94kRwiD3eh7AYVFSrRs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=a71xTtDu; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="a71xTtDu" Received: from pps.filterd (m0431383.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51KLpI4X019253; Thu, 20 Feb 2025 18:36:06 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=pfpt0220; bh=yrGSGxFZaPyMAX/abbQYP6Y xMutI6bHyx5LFZnAqtuc=; b=a71xTtDu5NQM6q5GRDyuBKOtLvldojJzSZlQl8S ux2GtvKRxWp/ggH4g0GIxj/7ZZ3y4qiBoXVsvqAdqjhOFIB1n/0dJreXaFYWeSia eRXlHFrxxpxFBCG+VDKO5M/Jp0y1Vy942okcUXtUi2c467QjvlyIUXfN8s5KOxrp LSDuXP6zEh2g4E2TU+XNx+V0Fs30zMDpFPhSqJ0dElzM0hC8fNbtZKD7YxH2tGO8 Uem8yvgG/nIxEnUmsdZQ/Q2Fj4BKT/bJAOLYybZ7ilOiwggaR/MOWjh9GWojFU5h 7oP1wyWZs+eSDq6StDpVwByU2prbfqFqLjqbf4QS0/6lf+Q== Received: from dc6wp-exch02.marvell.com ([4.21.29.225]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 44wu8pb3u9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 20 Feb 2025 18:36:06 -0800 (PST) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 20 Feb 2025 18:36:05 -0800 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 20 Feb 2025 18:36:05 -0800 Received: from tx2-sever.caveonetworks.com (unknown [10.110.141.15]) by maili.marvell.com (Postfix) with ESMTP id 221A53F708C; Thu, 20 Feb 2025 18:36:05 -0800 (PST) From: George Cherian To: , , CC: , , , George Cherian Subject: [PATCH 1/2] drivers: watchdog: Add support for panic notifier callback Date: Fri, 21 Feb 2025 02:35:49 +0000 Message-ID: <20250221023550.2092232-1-george.cherian@marvell.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: jaxOC1g25aDZTmy-Cop8rA6vdyl7fdW5 X-Proofpoint-GUID: jaxOC1g25aDZTmy-Cop8rA6vdyl7fdW5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-20_09,2025-02-20_02,2024-11-22_01 Watchdog is not turned off in kernel panic situation. In certain systems this might prevent the successful loading of kdump kernel. The kdump kernel might hit a watchdog reset while it is booting. To avoid such scenarios add a panic notifier call back function which can stop the watchdog. This provision can be enabled on per driver basis if the user wishes to by setting the flag WDOG_STOP_ON_PANIC from respective drivers. Signed-off-by: George Cherian --- drivers/watchdog/watchdog_core.c | 31 +++++++++++++++++++++++++++++++ include/linux/watchdog.h | 8 ++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c index d46d8c8c01f2..cce29d54535c 100644 --- a/drivers/watchdog/watchdog_core.c +++ b/drivers/watchdog/watchdog_core.c @@ -34,6 +34,7 @@ #include /* For ida_* macros */ #include /* For IS_ERR macros */ #include /* For of_get_timeout_sec */ +#include #include #include "watchdog_core.h" /* For watchdog_dev_register/... */ @@ -155,6 +156,23 @@ int watchdog_init_timeout(struct watchdog_device *wdd, } EXPORT_SYMBOL_GPL(watchdog_init_timeout); +static int watchdog_panic_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct watchdog_device *wdd; + + wdd = container_of(nb, struct watchdog_device, panic_nb); + if (watchdog_active(wdd)) { + int ret; + + ret = wdd->ops->stop(wdd); + if (ret) + return NOTIFY_BAD; + } + + return NOTIFY_DONE; +} + static int watchdog_reboot_notifier(struct notifier_block *nb, unsigned long code, void *data) { @@ -334,6 +352,16 @@ static int ___watchdog_register_device(struct watchdog_device *wdd) wdd->id, ret); } + if (test_bit(WDOG_STOP_ON_PANIC, &wdd->status)) { + if (!wdd->ops->stop) { + pr_warn("watchdog%d: stop_on_panic not supported\n", wdd->id); + } else { + wdd->panic_nb.notifier_call = watchdog_panic_notify; + atomic_notifier_chain_register(&panic_notifier_list, + &wdd->panic_nb); + } + } + return 0; } @@ -390,6 +418,9 @@ static void __watchdog_unregister_device(struct watchdog_device *wdd) if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) unregister_reboot_notifier(&wdd->reboot_nb); + if (test_bit(WDOG_STOP_ON_PANIC, &wdd->status)) + atomic_notifier_chain_unregister(&panic_notifier_list, + &wdd->panic_nb); watchdog_dev_unregister(wdd); ida_free(&watchdog_ida, wdd->id); } diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h index 99660197a36c..3c21b527ede9 100644 --- a/include/linux/watchdog.h +++ b/include/linux/watchdog.h @@ -108,6 +108,7 @@ struct watchdog_device { struct notifier_block reboot_nb; struct notifier_block restart_nb; struct notifier_block pm_nb; + struct notifier_block panic_nb; void *driver_data; struct watchdog_core_data *wd_data; unsigned long status; @@ -118,6 +119,7 @@ struct watchdog_device { #define WDOG_HW_RUNNING 3 /* True if HW watchdog running */ #define WDOG_STOP_ON_UNREGISTER 4 /* Should be stopped on unregister */ #define WDOG_NO_PING_ON_SUSPEND 5 /* Ping worker should be stopped on suspend */ +#define WDOG_STOP_ON_PANIC 6 /* Should be stopped on panic for loading kdump kernels */ struct list_head deferred; }; @@ -146,6 +148,12 @@ static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway set_bit(WDOG_NO_WAY_OUT, &wdd->status); } +/* Use the following function to stop the watchdog on panic */ +static inline void watchdog_stop_on_panic(struct watchdog_device *wdd) +{ + set_bit(WDOG_STOP_ON_PANIC, &wdd->status); +} + /* Use the following function to stop the watchdog on reboot */ static inline void watchdog_stop_on_reboot(struct watchdog_device *wdd) { From patchwork Fri Feb 21 02:35:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Cherian X-Patchwork-Id: 13984760 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 620831D6DDD; Fri, 21 Feb 2025 02:36:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740105385; cv=none; b=Ny7rK+AUeOW7/JOH2gnFrQNDI2SsBVYze7qYGBMLExR+5lxIFfnlZGK0UzM1ca9k+NWdW1XaNjsAznMsnMw+5h2kvTTYFySe0mRTwZrVzlj04Vt07TOD8riNdNGprQbm7ERBloWcJi492gN2lr2fZ2To98IlvdQXuzSYEYhykzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740105385; c=relaxed/simple; bh=VqTu4nppqqlBq/VZAIHyMyHkdtdVObY0u7hXFwd8HdU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YwwITpMQXIHz6Dk4ucN4Hk8wZbfAc4ktApm4XPhgMS6mKFOZCdb8tYf8hUoimrjqT0z1z25yBI5JqJP7UAIKmTVjlGVzi87x6jKfVq2GXXRfkgdi3zar/nsFtPWHxkOq5oyjRprrVpDugHdXQ+Fwc14OMC7ce9krSOmFOMScTps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=MjOyxfCS; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="MjOyxfCS" Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51KL8v1q028904; Thu, 20 Feb 2025 18:36:08 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=y udWezXlfftzuF3RFWfaWuFDvNQm9x3qNmDMXd3OOUY=; b=MjOyxfCSUrpDTYnh/ PfwpISIZMOYByPdXAty9MgFcxc2v0971UXO2EUzGGgAa6+di8E/D5svto/e59HSS BqMqqLiaJt4gpaq/T8Zw7aZoopAebDDH3hA3OgF33E2HIhNRdy277MQgGtr/owLy 1Pku3lWeaNyoPkMYOov2HvyNTSOANho3mUDfNguLTRfPZh5SfE98J8vIM9dBi6zV ssBQP93qXFJ+kL7ioZ4yQLnCZl5WcKH0LbD/INYO1pxPUIZRN+ZbIj01ocSmUf6J qZvjkUdSMopF2EtVXWrg3RO9qjOXFpvZw3HiR8Xgk+pR7c7HVXUZb7PpzKFB5W6X 2ZEpQ== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 44xc24rnb8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 20 Feb 2025 18:36:08 -0800 (PST) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 20 Feb 2025 18:36:07 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 20 Feb 2025 18:36:07 -0800 Received: from tx2-sever.caveonetworks.com (unknown [10.110.141.15]) by maili.marvell.com (Postfix) with ESMTP id 28C123F708C; Thu, 20 Feb 2025 18:36:07 -0800 (PST) From: George Cherian To: , , CC: , , , George Cherian Subject: [PATCH 2/2] watchdog: sbsa_gwdt: Enable the WDOG_STOP_ON_PANIC Date: Fri, 21 Feb 2025 02:35:50 +0000 Message-ID: <20250221023550.2092232-2-george.cherian@marvell.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250221023550.2092232-1-george.cherian@marvell.com> References: <20250221023550.2092232-1-george.cherian@marvell.com> Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: QwdYUEhnYmHFtEzpbHkNampRzp5I6eOb X-Proofpoint-ORIG-GUID: QwdYUEhnYmHFtEzpbHkNampRzp5I6eOb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-20_09,2025-02-20_02,2024-11-22_01 Enable the watchdog stop on panic feature if the module parameter panicnotify is set. sbsa_gwdt.panicnotify=1 will disable the watchdog in panic situations. This helps in avoiding watchdog reset while booting kdump kernel. Signed-off-by: George Cherian --- Documentation/watchdog/watchdog-parameters.rst | 3 +++ drivers/watchdog/sbsa_gwdt.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/Documentation/watchdog/watchdog-parameters.rst b/Documentation/watchdog/watchdog-parameters.rst index 0a0119edfa82..3d7a02d12dc3 100644 --- a/Documentation/watchdog/watchdog-parameters.rst +++ b/Documentation/watchdog/watchdog-parameters.rst @@ -523,6 +523,9 @@ sbsa_gwdt: nowayout: Watchdog cannot be stopped once started (default=kernel config parameter) + panicnotify: + Watchdog to be stopped after kernel panic + (default=0, don't stop watchdog on panic) ------------------------------------------------- diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c index 5f23913ce3b4..f289a0b32d30 100644 --- a/drivers/watchdog/sbsa_gwdt.c +++ b/drivers/watchdog/sbsa_gwdt.c @@ -116,6 +116,9 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); +static int panicnotify; +module_param(panicnotify, int, 0); +MODULE_PARM_DESC(panicnotify, "after kernel panic, do: 0 = don't stop wd(*) 1 = stop wd"); /* * Arm Base System Architecture 1.0 introduces watchdog v1 which * increases the length watchdog offset register to 48 bits. @@ -307,6 +310,9 @@ static int sbsa_gwdt_probe(struct platform_device *pdev) if (status & SBSA_GWDT_WCS_EN) set_bit(WDOG_HW_RUNNING, &wdd->status); + if (!nowayout && panicnotify) + watchdog_stop_on_panic(wdd); + if (action) { irq = platform_get_irq(pdev, 0); if (irq < 0) {