From nobody Tue Jan 11 13:57:06 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id D8092193DC41; Tue, 11 Jan 2022 13:57:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JYC1G3fHnz4Z30; Tue, 11 Jan 2022 13:57:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5CFEA1A4A9; Tue, 11 Jan 2022 13:57:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20BDv6Bi051488; Tue, 11 Jan 2022 13:57:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20BDv6Et051487; Tue, 11 Jan 2022 13:57:06 GMT (envelope-from git) Date: Tue, 11 Jan 2022 13:57:06 GMT Message-Id: <202201111357.20BDv6Et051487@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andriy Gapon Subject: git: ee900888c42f - main - dwwdt: make it actually useful List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ee900888c42f12f7ccf73e5a320446da4661a0e9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641909426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=do4F7Dnca/mbRRpvLEiLs+5rY4EjqVrYms+syFiis4g=; b=VYV29BarYc2Wi1vKiXBr4h7YINCteZj123OkjplWRccdI1y8Y5+3nDJlmx+imyiUMm6HCp c++asYiHotzPZMAWYl7/Heo3pZNqOdQP1uhmUBT8JwDrkQA4K9t9+CJ/coPUor/Pqqtx8D J+fuHgXPeiSW0/lQc9iownIubQ/n12LTLrsaAFMKhIcX1AN+PxdB0hhUrpBlxnhoFlXvjA +ia5yCBMC0uwGxGZZoH5D7HlacGWhQJUmizsPDSX0dB4ag5HSqs5mmwPjK5FIJT2Icfw0G svpyr0I2WgGGMpcevWiYL6iGxG8h2CIH6NJLPogeerHxD4Kd7LHjFIRQC4Cg+w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641909426; a=rsa-sha256; cv=none; b=xX/M344+V9sdQ4ASg/4AuQpfB4zdUMGGlpORETFMx5A/VrwRBgcqD6brkoQQ0eq8fDaVrm IjLj5Reeko/ciLZFSuSviSvp7A9zkh9kIynrS9C3mMgCJBK7t78VdJbkYlKMdMZUPOZIZf IOnFuEfRv9W78xd7xpgXGJLpLlIfQEP/LAehLpL6cfsKhM6BcLG19j4M6C1pWS+9A9Ap5n /miSq0OGAkHcLXLaY/oN2ZATbbQgtPYZXpIalVapMT0Fd7IjtQVmKMTEUf4Yf5ZOCjpcIs oU7/6/5qia/Ri8HFr/5Yj064A2wkj77XxkpuCIXxfp7tYzzg3V67UlxEPoWoYw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=ee900888c42f12f7ccf73e5a320446da4661a0e9 commit ee900888c42f12f7ccf73e5a320446da4661a0e9 Author: Andriy Gapon AuthorDate: 2022-01-11 13:56:07 +0000 Commit: Andriy Gapon CommitDate: 2022-01-11 13:56:07 +0000 dwwdt: make it actually useful Flip dwwdt_prevent_restart to false. What's the use of a watchdog if it does not restart a hung system? Add a knob for panic-ing on the first timeout, resetting on the second one. This can be useful if interrupts can still work, otherwise a reset recovers a system without any aid for debugging the hang. The change also doubles the timeout that's programmed into the hardware. The previous version of the code always had the interrupt on the first timeout enabled, but it took no action on it. Only the second timeout could be configured to reset the system. So, the hardware timeout was set to a half of the user requested timeout. But now,we can take a corrective action on the first timeout, so we use the user requested timeout. While here, define boolean sysctl-s as such. Reviewed by: manu MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D33534 --- sys/dev/dwwdt/dwwdt.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/sys/dev/dwwdt/dwwdt.c b/sys/dev/dwwdt/dwwdt.c index 4eab26ef2915..5cc20c3c9d2f 100644 --- a/sys/dev/dwwdt/dwwdt.c +++ b/sys/dev/dwwdt/dwwdt.c @@ -93,15 +93,20 @@ static struct ofw_compat_data compat_data[] = { SYSCTL_NODE(_dev, OID_AUTO, dwwdt, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "Synopsys Designware watchdog timer"); -/* Setting this to 0 enables full restart mode. */ -static uint32_t dwwdt_prevent_restart = 1; -SYSCTL_UINT(_dev_dwwdt, OID_AUTO, prevent_restart, CTLFLAG_RW | CTLFLAG_MPSAFE, - &dwwdt_prevent_restart, 1, - "Prevent system restart (0 - Disabled; 1 - Enabled)"); -static uint32_t dwwdt_debug_enabled = 0; -SYSCTL_UINT(_dev_dwwdt, OID_AUTO, debug, CTLFLAG_RW | CTLFLAG_MPSAFE, - &dwwdt_debug_enabled, 1, "Debug mode (0 - Disabled; 1 - Enabled)"); +/* Setting this to true disables full restart mode. */ +static bool dwwdt_prevent_restart = false; +SYSCTL_BOOL(_dev_dwwdt, OID_AUTO, prevent_restart, CTLFLAG_RW | CTLFLAG_MPSAFE, + &dwwdt_prevent_restart, 0, "Disable system reset on timeout"); + +static bool dwwdt_debug_enabled = false; +SYSCTL_BOOL(_dev_dwwdt, OID_AUTO, debug, CTLFLAG_RW | CTLFLAG_MPSAFE, + &dwwdt_debug_enabled, 0, "Enable debug mode"); + +static bool dwwdt_panic_first = true; +SYSCTL_BOOL(_dev_dwwdt, OID_AUTO, panic_first, CTLFLAG_RW | CTLFLAG_MPSAFE, + &dwwdt_panic_first, 0, + "Try to panic on timeout, reset on another timeout"); static int dwwdt_probe(device_t); static int dwwdt_attach(device_t); @@ -181,13 +186,17 @@ dwwdt_intr(void *arg) KASSERT((DWWDT_READ4(sc, DWWDT_STAT) & DWWDT_STAT_STATUS) != 0, ("Missing interrupt status bit?")); - if (dwwdt_prevent_restart != 0 || sc->sc_status == DWWDT_STOPPED) { + if (dwwdt_prevent_restart || sc->sc_status == DWWDT_STOPPED) { /* * Confirm interrupt reception. Restart counter. * This also emulates stopping watchdog. */ (void)DWWDT_READ4(sc, DWWDT_EOI); + return; } + + if (dwwdt_panic_first) + panic("dwwdt pre-timeout interrupt"); } static void @@ -199,7 +208,7 @@ dwwdt_event(void *arg, unsigned int cmd, int *error) int val; timeout = cmd & WD_INTERVAL; - val = MAX(0, timeout + exponent - DWWDT_EXP_OFFSET); + val = MAX(0, timeout + exponent - DWWDT_EXP_OFFSET + 1); dwwdt_stop(sc); if (cmd == 0 || val > 0x0f) { @@ -341,7 +350,7 @@ dwwdt_shutdown(device_t dev) sc = device_get_softc(dev); /* Prevent restarts during shutdown. */ - dwwdt_prevent_restart = 1; + dwwdt_prevent_restart = true; dwwdt_stop(sc); return (bus_generic_shutdown(dev)); }