[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240822070944.GA13716@didi-ThinkCentre-M930t-N000>
Date: Thu, 22 Aug 2024 15:09:44 +0800
From: Tio Zhang <tiozhang@...iglobal.com>
To: <akpm@...ux-foundation.org>, <dianders@...omium.org>
CC: <linux-kernel@...r.kernel.org>, <tglx@...utronix.de>,
<zyhtheonly@...il.com>, <tiozhang@...iglobal.com>, <zyhtheonly@...h.net>
Subject: [PATCH] watchdog: when watchdog_enabled is 0, let (soft,nmi)switch
remain 1 after we read them in proc
For users set "watchdog_user_enabled=0" but remaining
"(soft,nmi)watchdog_user_enabled=1". Watchdog threads(,nmi watchdog)
rework only if users reset "watchdog_user_enabled=1" without printing
those watchdog swicthes. Otherwise (soft,nmi)watchdog_user_enabled
will turn to 0 because of printing their values (It makes sense to print 0
since they do not work any more, but it does not make sense to let user's
swicthes change to 0 only by prints).
And after that, watchdog only should work again by doing:
(soft,nmi)watchdog_user_enabled=1
*** can't print, or everything go back to 0 again ***
watchdog_user_enabled=1
So this patch fixes this situation:
| name | value
|----------------------------|--------------------------
| watchdog_enabled | 0
|----------------------------|--------------------------
| nmi_watchdog_user_enabled | 1
|----------------------------|--------------------------
| soft_watchdog_user_enabled | 1
|----------------------------|--------------------------
| watchdog_user_enabled | 0
|----------------------------|--------------------------
cat /proc/sys/kernel/*watchdog
|
|
V
| name | value
|----------------------------|--------------------------
| watchdog_enabled | 0
|----------------------------|--------------------------
| nmi_watchdog_user_enabled | 0
|----------------------------|--------------------------
| soft_watchdog_user_enabled | 0
|----------------------------|--------------------------
| watchdog_user_enabled | 0
|----------------------------|--------------------------
Signed-off-by: Tio Zhang <tiozhang@...iglobal.com>
---
kernel/watchdog.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 51915b44ac73..42e69e83e76d 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -995,8 +995,18 @@ static int proc_watchdog_common(int which, struct ctl_table *table, int write,
* On read synchronize the userspace interface. This is a
* racy snapshot.
*/
+ old = READ_ONCE(*param);
*param = (watchdog_enabled & which) != 0;
err = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+ /*
+ * When "old" is 1 and watchdog_enabled is 0,
+ * it should not be change to 0 for printing
+ * nmi_watchdog_user_enabled or soft_watchdog_user_enabled.
+ * So after we print it as 0,
+ * we should recover it to 1.
+ */
+ if (old && !watchdog_enabled)
+ *param = old;
} else {
old = READ_ONCE(*param);
err = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
--
2.17.1
Powered by blists - more mailing lists