From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F6A7286AC for ; Thu, 23 Jul 2026 16:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784823376; cv=none; b=p18wXAP7maZPSWlCJdKZh8cgSYfC8YuP2e+SIfyB8zniz6ycxYexpezwvfqqeWcOvX/duhVrVF3sds//4+Ka5n9d4L/3dO2RnOFVxBwiWX5ukLa07zz3ooyrIvYaRyBtsQ1C7K1q8QtGrdfTOP/zHDuZTEKZf4HPIYtf81QnEZY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784823376; c=relaxed/simple; bh=RhYZhATafjoMD0ZHXlRQHWN9Xd1AxMAMGtvwpmw4tCE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=irPXRVj+LwOJ653g0cc/J8Bo7R0dLZkz7ZQbnp4ymvb/LvA1LRZY1vUfauQWU1ZAW9UnyQb+RQs5Ce5oIqt4j9U3Z/d8GjGU1ybI4PSkMUfRk1MxQ/6jreDXxT9wzSjyFrEI35n22jU0xuxt/ug/9gdwPb3yxuhe8ooqWWhHkbE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=A9Mxu893; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A9Mxu893" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-39d4c864bfbso8218941fa.1 for ; Thu, 23 Jul 2026 09:16:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784823353; x=1785428153; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=iCFBAhStYCbZRWF7EYeTGTDCTAg3SzAm66lZxtMyduE=; b=A9Mxu89328xZTb6bSW/2wNnD+XEPmPHz3atfPhfCpmbOOVGSlflpXV4Jqm8nl+QhHh 7N3M/cilFKg91h9GOQ8CRh60AdSOd4wphKO07Gtin7NnpmNVTlVzWEtl3ycmlzS3HtY5 cdNuZX43vZUKpuFTo10Ai+KkbS6lzqDgcLbYAyXjez0Ddmix7VS0IHyFgyofPQAtK92q sVZ2DeSCeif8AfuWHSVTD/Dchg2oH+QgqWIFY0xfNH2J8Dp/UMTJgOTHIR9TQ69RQlbf ieLiBus83V/lNa8A6HcLgmFwmhO8pGIv3ddMtIaZiexwpZWHh4q/W5nSQI2XVeD7Nlb9 0ngg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784823353; x=1785428153; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=iCFBAhStYCbZRWF7EYeTGTDCTAg3SzAm66lZxtMyduE=; b=WJK3T/IF0A2CM5YKIui8P4j7OajCNBQ+2PY8IiM/VCUJxeL85/4QZodZPbDJr6+QWj OHz+KfZt6Un9Fr59Mka6fCSj1O0lr0QAGYySKYswzb5ta4SgPDhuVBGPjpPxh35jrjLP SYLZSexqcXZN8zpyPyAoj41EXKVEETLr9czVKl+FDA/xfGvETK/CFAAEHySCKx27JANe RpKVeAQHLZXPczOuSVd7a4DtsQ7je13J3Kp0YkCF3BTCILC4ERoIUszM1rPwqw9soK6Q sOFanW3DdB5SD/tUvKKKrFbVQYHXRbJlG/TzWxVFplFe6Gr1ZPKZJFTkG2QAzVBUdi36 koKg== X-Gm-Message-State: AOJu0YxkwWbJaMf5ctEE5S0AQYRFgJuA2vTrZXqdnoBvza88efmFs12H 3aS7v3RCc0RF3Ck0M4jZxUCvlm1fgm0+kDzGlUkESmTrOHuetBlmC1gXiqTVwS2XZbY= X-Gm-Gg: AR+sD10mHgwK/it/RU5C7sEuo1wrUyytnGB4mbjkasGh6Cwdi3L+RlAWOhidMvXr8se xEsif2DRgaYPpz8ffvc4WvzjMJnQzPntgJQ2jQUOeo86Jwsh6S+B7SgnJsUp/gDygXrWmXQSn8g JVWBj88dEaR3YhnlCGKUm0RJHa+cxaBl81gsCxg7JxYQ/8Lu693lV1x1ikDNapX3LVc8Bv6YMFF kKq+UgVLDvhIHQVxor6t5whGUFeRNSjb+XiztzG2Gee2eVkAyBxsJC0DKUZXOj58TLy2EJdYlQO zEl+lmISJRvtXDL/oFcO0gMjGHKzzZCn7xmWi+g4vTWq0f/mqC7sgDz7SVzYZTHhmIZpXF+ZTKs rq2ItVkCawUymv8fnN2R5O2Mbjvocvw+pG5vQG9Mfp9VrJDGCj1Yx7RZL0DRkYwI78iwAAQ9CVN 3kQU0dDLqpNGAnPFuo0WH3ZoCWJqS3xSCkPmkNPFxg6dipWXmFrktWnpwKxex68MHDN6cOvW/uo 5RB X-Received: by 2002:a2e:3a13:0:b0:39a:e29b:790b with SMTP id 38308e7fff4ca-39f07e96d46mr6427911fa.34.1784823352729; Thu, 23 Jul 2026 09:15:52 -0700 (PDT) Received: from localhost.localdomain (46-138-176-102.dynamic.spd-mgts.ru. [46.138.176.102]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-39ef6d8c40fsm9875561fa.41.2026.07.23.09.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 09:15:52 -0700 (PDT) From: Artem Lytkin To: linux-watchdog@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: linux-kernel@vger.kernel.org, wim@linux-watchdog.org, linux@roeck-us.net, ojeda@kernel.org, miguel.ojeda.sandonis@gmail.com, dakr@kernel.org, aliceryhl@google.com, a.hindborg@kernel.org, lossin@kernel.org Subject: [PATCH v2 0/3] rust: add watchdog abstraction and Rust softdog driver Date: Thu, 23 Jul 2026 19:15:26 +0300 Message-ID: <20260723161529.23759-1-iprintercanon@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series adds Rust abstractions for the watchdog subsystem and a Rust software watchdog driver functionally equivalent to the core of the C softdog. Patch 1 adds the watchdog abstraction: a Device wrapper, an Info wrapper with option flags, an Options configuration struct, a #[vtable] WatchdogOps trait with an associated Data type for driver private data, and a generic Registration that owns the device, the ops table and the driver data in a single heap allocation. Patch 2 adds a minimal kernel::reboot module wrapping emergency_restart(), needed by the softdog driver. Patch 3 adds the softdog_rs driver: an hrtimer is armed on start and re-armed on every keepalive ping; if userspace stops pinging, the timer expires and the system is restarted via emergency_restart(). Changes since v1 [1]: Most of v2 is a redesign addressing the review feedback from Guenter (via the Sashiko review [2]), Miguel, and the kernel test robot: - The ops table is no longer a &'static mut supplied by the driver; it is built by the abstraction and embedded in the per-device heap allocation, so multiple device instances need no static mutable state (Sashiko). - Driver private data is now supported via an associated Data type; every callback receives a reference to it (Sashiko). - Callbacks now take only shared references and Data must be Sync: the watchdog core does not hold its lock on every callback path (the first start/ping on open, the reboot notifier stop, and the stop on unregistration run without it), so exclusive references would be unsound. - max_hw_heartbeat_ms is configurable and the stop()-or-heartbeat registration requirement is documented (Sashiko). - Removed the Registration::device() accessor that allowed aliasing with the references used in callbacks (Sashiko). - stop_on_reboot is now opt-in and rejected with EINVAL for drivers without stop(); nowayout defaults to CONFIG_WATCHDOG_NOWAYOUT (Sashiko). - The watchdog is always stopped on unregistration so no callback can run after the driver data is freed. - softdog_rs now actually bites: it arms an hrtimer and calls emergency_restart() on expiry, instead of relying on the (wrong) assumption that the core handles expiry (Sashiko). - Kconfig mutual exclusion fixed to SOFT_WATCHDOG=n; !SOFT_WATCHDOG still allowed both drivers as modules (Sashiko). - C helpers marked __rust_helper (Miguel), and updated for the const-qualified watchdog_active()/watchdog_hw_running(). - Fixed rustfmt and clippy issues reported by the kernel test robot. - Drivers no longer use raw bindings: added the Info wrapper, the flags module, and the kernel::reboot module. - Added the new rust watchdog files to MAINTAINERS. - Rebased onto current mainline (post-v7.2-rc4). [1] https://lore.kernel.org/linux-watchdog/20260323195138.5541-1-iprintercanon@gmail.com/ [2] https://sashiko.dev/#/patchset/20260323195138.5541-1-iprintercanon%40gmail.com Artem Lytkin (3): rust: watchdog: add watchdog device abstraction rust: reboot: add emergency_restart() wrapper watchdog: softdog_rs: add Rust software watchdog driver MAINTAINERS | 2 + drivers/watchdog/Kconfig | 12 + drivers/watchdog/Makefile | 1 + drivers/watchdog/softdog_rs.rs | 143 +++++++++++ rust/bindings/bindings_helper.h | 2 + rust/helpers/helpers.c | 1 + rust/helpers/watchdog.c | 38 +++ rust/kernel/lib.rs | 3 + rust/kernel/reboot.rs | 19 ++ rust/kernel/watchdog.rs | 522 ++++++++++++++++++++++++++++++++++++++++ 10 files changed, 743 insertions(+) create mode 100644 drivers/watchdog/softdog_rs.rs create mode 100644 rust/helpers/watchdog.c create mode 100644 rust/kernel/reboot.rs create mode 100644 rust/kernel/watchdog.rs -- 2.43.0