Skip to content

Commit bbe7a10

Browse files
nixiaomingtorvalds
authored andcommitted
hung_task: move hung_task sysctl interface to hung_task.c
The kernel/sysctl.c is a kitchen sink where everyone leaves their dirty dishes, this makes it very difficult to maintain. To help with this maintenance let's start by moving sysctls to places where they actually belong. The proc sysctl maintainers do not want to know what sysctl knobs you wish to add for your own piece of code, we just care about the core logic. So move hung_task sysctl interface to hung_task.c and use register_sysctl() to register the sysctl interface. [mcgrof@kernel.org: commit log refresh and fixed 2-3 0day reported compile issues] Link: https://lkml.kernel.org/r/20211123202347.818157-4-mcgrof@kernel.org Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Petr Mladek <pmladek@suse.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Amir Goldstein <amir73il@gmail.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Benjamin LaHaise <bcrl@kvack.org> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Iurii Zaikin <yzaikin@google.com> Cc: Jan Kara <jack@suse.cz> Cc: Paul Turner <pjt@google.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Qing Wang <wangqing@vivo.com> Cc: Sebastian Reichel <sre@kernel.org> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Stephen Kitt <steve@sk2.org> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Antti Palosaari <crope@iki.fi> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Clemens Ladisch <clemens@ladisch.de> Cc: David Airlie <airlied@linux.ie> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Julia Lawall <julia.lawall@inria.fr> Cc: Lukas Middendorf <kernel@tuxforce.de> Cc: Mark Fasheh <mark@fasheh.com> Cc: Phillip Potter <phil@philpotter.co.uk> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Cc: Douglas Gilbert <dgilbert@interlog.com> Cc: James E.J. Bottomley <jejb@linux.ibm.com> Cc: Jani Nikula <jani.nikula@intel.com> Cc: John Ogness <john.ogness@linutronix.de> Cc: Martin K. Petersen <martin.petersen@oracle.com> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: "Theodore Ts'o" <tytso@mit.edu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 78e36f3 commit bbe7a10

3 files changed

Lines changed: 79 additions & 77 deletions

File tree

‎include/linux/sched/sysctl.h‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,8 @@
77
struct ctl_table;
88

99
#ifdef CONFIG_DETECT_HUNG_TASK
10-
11-
#ifdef CONFIG_SMP
12-
extern unsigned int sysctl_hung_task_all_cpu_backtrace;
13-
#else
14-
#define sysctl_hung_task_all_cpu_backtrace 0
15-
#endif /* CONFIG_SMP */
16-
17-
extern int sysctl_hung_task_check_count;
18-
extern unsigned int sysctl_hung_task_panic;
10+
/* used for hung_task and block/ */
1911
extern unsigned long sysctl_hung_task_timeout_secs;
20-
extern unsigned long sysctl_hung_task_check_interval_secs;
21-
extern int sysctl_hung_task_warnings;
22-
int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
23-
void *buffer, size_t *lenp, loff_t *ppos);
2412
#else
2513
/* Avoid need for ifdefs elsewhere in the code */
2614
enum { sysctl_hung_task_timeout_secs = 0 };

‎kernel/hung_task.c‎

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ static struct task_struct *watchdog_task;
6363
* Should we dump all CPUs backtraces in a hung task event?
6464
* Defaults to 0, can be changed via sysctl.
6565
*/
66-
unsigned int __read_mostly sysctl_hung_task_all_cpu_backtrace;
66+
static unsigned int __read_mostly sysctl_hung_task_all_cpu_backtrace;
67+
#else
68+
#define sysctl_hung_task_all_cpu_backtrace 0
6769
#endif /* CONFIG_SMP */
6870

6971
/*
@@ -222,11 +224,13 @@ static long hung_timeout_jiffies(unsigned long last_checked,
222224
MAX_SCHEDULE_TIMEOUT;
223225
}
224226

227+
#ifdef CONFIG_SYSCTL
225228
/*
226229
* Process updating of timeout sysctl
227230
*/
228-
int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
229-
void *buffer, size_t *lenp, loff_t *ppos)
231+
static int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
232+
void __user *buffer,
233+
size_t *lenp, loff_t *ppos)
230234
{
231235
int ret;
232236

@@ -241,6 +245,76 @@ int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
241245
return ret;
242246
}
243247

248+
/*
249+
* This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
250+
* and hung_task_check_interval_secs
251+
*/
252+
static const unsigned long hung_task_timeout_max = (LONG_MAX / HZ);
253+
static struct ctl_table hung_task_sysctls[] = {
254+
#ifdef CONFIG_SMP
255+
{
256+
.procname = "hung_task_all_cpu_backtrace",
257+
.data = &sysctl_hung_task_all_cpu_backtrace,
258+
.maxlen = sizeof(int),
259+
.mode = 0644,
260+
.proc_handler = proc_dointvec_minmax,
261+
.extra1 = SYSCTL_ZERO,
262+
.extra2 = SYSCTL_ONE,
263+
},
264+
#endif /* CONFIG_SMP */
265+
{
266+
.procname = "hung_task_panic",
267+
.data = &sysctl_hung_task_panic,
268+
.maxlen = sizeof(int),
269+
.mode = 0644,
270+
.proc_handler = proc_dointvec_minmax,
271+
.extra1 = SYSCTL_ZERO,
272+
.extra2 = SYSCTL_ONE,
273+
},
274+
{
275+
.procname = "hung_task_check_count",
276+
.data = &sysctl_hung_task_check_count,
277+
.maxlen = sizeof(int),
278+
.mode = 0644,
279+
.proc_handler = proc_dointvec_minmax,
280+
.extra1 = SYSCTL_ZERO,
281+
},
282+
{
283+
.procname = "hung_task_timeout_secs",
284+
.data = &sysctl_hung_task_timeout_secs,
285+
.maxlen = sizeof(unsigned long),
286+
.mode = 0644,
287+
.proc_handler = proc_dohung_task_timeout_secs,
288+
.extra2 = (void *)&hung_task_timeout_max,
289+
},
290+
{
291+
.procname = "hung_task_check_interval_secs",
292+
.data = &sysctl_hung_task_check_interval_secs,
293+
.maxlen = sizeof(unsigned long),
294+
.mode = 0644,
295+
.proc_handler = proc_dohung_task_timeout_secs,
296+
.extra2 = (void *)&hung_task_timeout_max,
297+
},
298+
{
299+
.procname = "hung_task_warnings",
300+
.data = &sysctl_hung_task_warnings,
301+
.maxlen = sizeof(int),
302+
.mode = 0644,
303+
.proc_handler = proc_dointvec_minmax,
304+
.extra1 = SYSCTL_NEG_ONE,
305+
},
306+
{}
307+
};
308+
309+
static void __init hung_task_sysctl_init(void)
310+
{
311+
register_sysctl_init("kernel", hung_task_sysctls);
312+
}
313+
#else
314+
#define hung_task_sysctl_init() do { } while (0)
315+
#endif /* CONFIG_SYSCTL */
316+
317+
244318
static atomic_t reset_hung_task = ATOMIC_INIT(0);
245319

246320
void reset_hung_task_detector(void)
@@ -310,6 +384,7 @@ static int __init hung_task_init(void)
310384
pm_notifier(hungtask_pm_notify, 0);
311385

312386
watchdog_task = kthread_run(watchdog, NULL, "khungtaskd");
387+
hung_task_sysctl_init();
313388

314389
return 0;
315390
}

‎kernel/sysctl.c‎

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,6 @@ static int minolduid;
134134
static int ngroups_max = NGROUPS_MAX;
135135
static const int cap_last_cap = CAP_LAST_CAP;
136136

137-
/*
138-
* This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
139-
* and hung_task_check_interval_secs
140-
*/
141-
#ifdef CONFIG_DETECT_HUNG_TASK
142-
static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
143-
#endif
144137

145138
#ifdef CONFIG_INOTIFY_USER
146139
#include <linux/inotify.h>
@@ -2508,60 +2501,6 @@ static struct ctl_table kern_table[] = {
25082501
.proc_handler = proc_dointvec,
25092502
},
25102503
#endif
2511-
#ifdef CONFIG_DETECT_HUNG_TASK
2512-
#ifdef CONFIG_SMP
2513-
{
2514-
.procname = "hung_task_all_cpu_backtrace",
2515-
.data = &sysctl_hung_task_all_cpu_backtrace,
2516-
.maxlen = sizeof(int),
2517-
.mode = 0644,
2518-
.proc_handler = proc_dointvec_minmax,
2519-
.extra1 = SYSCTL_ZERO,
2520-
.extra2 = SYSCTL_ONE,
2521-
},
2522-
#endif /* CONFIG_SMP */
2523-
{
2524-
.procname = "hung_task_panic",
2525-
.data = &sysctl_hung_task_panic,
2526-
.maxlen = sizeof(int),
2527-
.mode = 0644,
2528-
.proc_handler = proc_dointvec_minmax,
2529-
.extra1 = SYSCTL_ZERO,
2530-
.extra2 = SYSCTL_ONE,
2531-
},
2532-
{
2533-
.procname = "hung_task_check_count",
2534-
.data = &sysctl_hung_task_check_count,
2535-
.maxlen = sizeof(int),
2536-
.mode = 0644,
2537-
.proc_handler = proc_dointvec_minmax,
2538-
.extra1 = SYSCTL_ZERO,
2539-
},
2540-
{
2541-
.procname = "hung_task_timeout_secs",
2542-
.data = &sysctl_hung_task_timeout_secs,
2543-
.maxlen = sizeof(unsigned long),
2544-
.mode = 0644,
2545-
.proc_handler = proc_dohung_task_timeout_secs,
2546-
.extra2 = &hung_task_timeout_max,
2547-
},
2548-
{
2549-
.procname = "hung_task_check_interval_secs",
2550-
.data = &sysctl_hung_task_check_interval_secs,
2551-
.maxlen = sizeof(unsigned long),
2552-
.mode = 0644,
2553-
.proc_handler = proc_dohung_task_timeout_secs,
2554-
.extra2 = &hung_task_timeout_max,
2555-
},
2556-
{
2557-
.procname = "hung_task_warnings",
2558-
.data = &sysctl_hung_task_warnings,
2559-
.maxlen = sizeof(int),
2560-
.mode = 0644,
2561-
.proc_handler = proc_dointvec_minmax,
2562-
.extra1 = SYSCTL_NEG_ONE,
2563-
},
2564-
#endif
25652504
#ifdef CONFIG_RT_MUTEXES
25662505
{
25672506
.procname = "max_lock_depth",

0 commit comments

Comments
 (0)