From patchwork Wed Jun 3 10:39:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Woody Lin X-Patchwork-Id: 11585497 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7540C14F6 for ; Wed, 3 Jun 2020 10:40:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BF5C2074B for ; Wed, 3 Jun 2020 10:40:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mqgtV/eo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725930AbgFCKkr (ORCPT ); Wed, 3 Jun 2020 06:40:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725828AbgFCKkr (ORCPT ); Wed, 3 Jun 2020 06:40:47 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A852C08C5C0 for ; Wed, 3 Jun 2020 03:40:47 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id t4so2636304yba.12 for ; Wed, 03 Jun 2020 03:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=Dx8BZCAyOelUut0rl9Q9MMUdQl4nnORmkfsPLfnsf9I=; b=mqgtV/eo4BkZHFXXVju/3WABrqnYwuXHGrSz102vmjoxmxHqFFHyQ9a1yN1pIC8KN1 wDM+RSjgurcfuf6sT4x1Mxxzgnd6OY5HlPZcaJYeBdlmuHfGUyf4/eWjHuF4ULxj9pE9 u3wHTXd7e4mb680zmVouUfZYkg9FwUuVOm5WdMTdIKC9oCtgjkSRx7TWyiUmHox1thlZ /LvSM2TXz7JRrqEaltbg3Lm74U3+7h3f5iztc4ZYJHNcIJVOdZd22SNKWpad70lLHlce kqtk1kr6/JFp+f9ykTuurar0kxOCS+jEbvDW1SvZBP7ekq0jL/0vp/0vudM2tlsFeVem sr3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=Dx8BZCAyOelUut0rl9Q9MMUdQl4nnORmkfsPLfnsf9I=; b=LJph3tPKGg9vivii6HxSafC1WtnNaw2oH606VoPC0FY151l3c6R3Q47kpkxv9TUBvF tmJrSXfsAPTuWn8MuYAJyL3IiyUATcd6Uuwd479cL2BhOuIrGKM8Wr0CQ6zA5mBUY5Xg 8+Ux5RUH45lUKU1rPY//LXgPv/hTAz/d/iRUdjnJEQ/uOmuNOnpyjKYNXMh5RAml7G3f HmfzzOxD2jowCK/2SUqMCj1nrhNDT99JslmhfcEwS29jwAZ559mHtzp1cR4LbBpWZrle X05DbRc3DuyGd/LcqdFi18t6TyVKVnEhtRvBpSWsdXjI1P/nJtt81H6vz5EWJ8EEurNo jn1g== X-Gm-Message-State: AOAM530XSjHmTjz/NDEkhwsbAWgGhEnAA7jFUv9vcXlA2QrkLS4Do130 slFePZqCEJyMbxki9PO8ozc3dOuJM2Glug== X-Google-Smtp-Source: ABdhPJyoC8t2KMc/aMEktF8cUJY2eR4tlOdFRNKqM99WWDuNN02vdfCr2gf9KKK1yOhvd2wdApd7hw6cxZ+tNQ== X-Received: by 2002:a25:3203:: with SMTP id y3mr38762116yby.77.1591180846405; Wed, 03 Jun 2020 03:40:46 -0700 (PDT) Date: Wed, 3 Jun 2020 18:39:24 +0800 Message-Id: <20200603103923.116113-1-woodylin@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.27.0.rc2.251.g90737beb825-goog Subject: [PATCH] softdog: Add options 'soft_reboot_target' and 'soft_active_on_boot' From: Woody Lin To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, Woody Lin Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Add module parameters 'soft_reboot_target' and 'soft_active_on_boot' for customizing softdog configuration; config reboot target by assigning soft_reboot_target, and set soft_active_on_boot to start up softdog timer at module initialization stage. Signed-off-by: Woody Lin --- drivers/watchdog/softdog.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/watchdog/softdog.c b/drivers/watchdog/softdog.c index 3e4885c1545e..f5027acddbbb 100644 --- a/drivers/watchdog/softdog.c +++ b/drivers/watchdog/softdog.c @@ -20,11 +20,13 @@ #include #include #include +#include #include #include #include #include #include +#include #define TIMER_MARGIN 60 /* Default is 60 seconds */ static unsigned int soft_margin = TIMER_MARGIN; /* in seconds */ @@ -49,9 +51,32 @@ module_param(soft_panic, int, 0); MODULE_PARM_DESC(soft_panic, "Softdog action, set to 1 to panic, 0 to reboot (default=0)"); +static char *soft_reboot_target; +module_param(soft_reboot_target, charp, 0000); +MODULE_PARM_DESC(soft_reboot_target, + "Softdog action, set reboot target (default=emergency)"); + +static bool soft_active_on_boot; +module_param(soft_active_on_boot, bool, 0000); +MODULE_PARM_DESC(soft_active_on_boot, + "Set to true to active Softdog on boot (default=false)"); + static struct hrtimer softdog_ticktock; static struct hrtimer softdog_preticktock; +static int reboot_kthread_fn(void *data) +{ + kernel_restart(soft_reboot_target); + emergency_restart(); /* Should not reach here */ + return -EPERM; /* Should not reach here */ +} + +static void reboot_work_fn(struct work_struct *unused) +{ + if (IS_ERR(kthread_run(reboot_kthread_fn, NULL, "softdog_reboot"))) + emergency_restart(); +} + static enum hrtimer_restart softdog_fire(struct hrtimer *timer) { module_put(THIS_MODULE); @@ -62,6 +87,12 @@ static enum hrtimer_restart softdog_fire(struct hrtimer *timer) panic("Software Watchdog Timer expired"); } else { pr_crit("Initiating system reboot\n"); + if (soft_reboot_target != NULL) { + static DECLARE_WORK(reboot_work, reboot_work_fn); + + schedule_work(&reboot_work); + return HRTIMER_NORESTART; + } emergency_restart(); pr_crit("Reboot didn't ?????\n"); } @@ -145,12 +176,19 @@ static int __init softdog_init(void) softdog_preticktock.function = softdog_pretimeout; } + if (soft_active_on_boot) { + set_bit(WDOG_HW_RUNNING, &softdog_dev.status); + set_bit(WDOG_ACTIVE, &softdog_dev.status); + } + ret = watchdog_register_device(&softdog_dev); if (ret) return ret; pr_info("initialized. soft_noboot=%d soft_margin=%d sec soft_panic=%d (nowayout=%d)\n", soft_noboot, softdog_dev.timeout, soft_panic, nowayout); + pr_info(" soft_reboot_target=%s soft_active_on_boot=%d\n", + soft_reboot_target, soft_active_on_boot); return 0; }