History

printk: move printk sysctl to printk/sysctl.c

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 printk sysctl from kernel/sysctl.c to kernel/printk/sysctl.c. Use register_sysctl() to register the sysctl interface. [mcgrof@kernel.org: fixed compile issues when PRINTK is not set, commit log update]

Xiaoming Ni committed 4 years ago

Commit faaa3571 parent 3ba442d5 files · +96 −69Browse files

Showing the changes to kernel (5 of 5 files). Show all

Unified · Split

5 files
  1. kernel/printk/Makefile +4 −1
  2. kernel/printk/internal.h +6 −0
  3. kernel/printk/printk.c +1 −0
  4. kernel/printk/sysctl.c +85 −0
  5. kernel/sysctl.c +0 −68
kernel/printk/Makefile+4−1
@@ -2,5 +2,8 @@ · 1 unmodified line
22 obj-y = printk.o
33 obj-$(CONFIG_PRINTK) += printk_safe.o
44 obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o
5−obj-$(CONFIG_PRINTK) += printk_ringbuffer.o
65 obj-$(CONFIG_PRINTK_INDEX) += index.o
6+
7+obj-$(CONFIG_PRINTK) += printk_support.o
8+printk_support-y := printk_ringbuffer.o
9+printk_support-$(CONFIG_SYSCTL) += sysctl.o
kernel/printk/internal.h+6−0
@@ -4,6 +4,12 @@ · 3 unmodified lines
44 */
55 #include <linux/percpu.h>
66
7+#if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL)
8+void __init printk_sysctl_init(void);
9+#else
10+#define printk_sysctl_init() do { } while (0)
11+#endif
12+
713 #ifdef CONFIG_PRINTK
814
915 /* Flags for a single printk record. */
kernel/printk/printk.c+1−0
@@ -3211,6 +3211,7 @@ static int __init printk_late_init(void) · 3210 unmodified lines
32113211 ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "printk:online",
32123212 console_cpu_notify, NULL);
32133213 WARN_ON(ret < 0);
3214+ printk_sysctl_init();
32143215 return 0;
32153216 }
32163217 late_initcall(printk_late_init);
kernel/printk/sysctl.c+85−0
@@ -0,0 +1,85 @@
1+// SPDX-License-Identifier: GPL-2.0-only
2+/*
3+ * sysctl.c: General linux system control interface
4+ */
5+
6+#include <linux/sysctl.h>
7+#include <linux/printk.h>
8+#include <linux/capability.h>
9+#include <linux/ratelimit.h>
10+#include "internal.h"
11+
12+static const int ten_thousand = 10000;
13+
14+static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
15+ void __user *buffer, size_t *lenp, loff_t *ppos)
16+{
17+ if (write && !capable(CAP_SYS_ADMIN))
18+ return -EPERM;
19+
20+ return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
21+}
22+
23+static struct ctl_table printk_sysctls[] = {
24+ {
25+ .procname = "printk",
26+ .data = &console_loglevel,
27+ .maxlen = 4*sizeof(int),
28+ .mode = 0644,
29+ .proc_handler = proc_dointvec,
30+ },
31+ {
32+ .procname = "printk_ratelimit",
33+ .data = &printk_ratelimit_state.interval,
34+ .maxlen = sizeof(int),
35+ .mode = 0644,
36+ .proc_handler = proc_dointvec_jiffies,
37+ },
38+ {
39+ .procname = "printk_ratelimit_burst",
40+ .data = &printk_ratelimit_state.burst,
41+ .maxlen = sizeof(int),
42+ .mode = 0644,
43+ .proc_handler = proc_dointvec,
44+ },
45+ {
46+ .procname = "printk_delay",
47+ .data = &printk_delay_msec,
48+ .maxlen = sizeof(int),
49+ .mode = 0644,
50+ .proc_handler = proc_dointvec_minmax,
51+ .extra1 = SYSCTL_ZERO,
52+ .extra2 = (void *)&ten_thousand,
53+ },
54+ {
55+ .procname = "printk_devkmsg",
56+ .data = devkmsg_log_str,
57+ .maxlen = DEVKMSG_STR_MAX_SIZE,
58+ .mode = 0644,
59+ .proc_handler = devkmsg_sysctl_set_loglvl,
60+ },
61+ {
62+ .procname = "dmesg_restrict",
63+ .data = &dmesg_restrict,
64+ .maxlen = sizeof(int),
65+ .mode = 0644,
66+ .proc_handler = proc_dointvec_minmax_sysadmin,
67+ .extra1 = SYSCTL_ZERO,
68+ .extra2 = SYSCTL_ONE,
69+ },
70+ {
71+ .procname = "kptr_restrict",
72+ .data = &kptr_restrict,
73+ .maxlen = sizeof(int),
74+ .mode = 0644,
75+ .proc_handler = proc_dointvec_minmax_sysadmin,
76+ .extra1 = SYSCTL_ZERO,
77+ .extra2 = SYSCTL_TWO,
78+ },
79+ {}
80+};
81+
82+void __init printk_sysctl_init(void)
83+{
84+ register_sysctl_init("kernel", printk_sysctls);
85+}
kernel/sysctl.c+0−68
@@ -908,17 +908,6 @@ static int proc_taint(struct ctl_table *table, int write, · 907 unmodified lines
908908 return err;
909909 }
910910
911−#ifdef CONFIG_PRINTK
912−static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
913− void *buffer, size_t *lenp, loff_t *ppos)
914−{
915− if (write && !capable(CAP_SYS_ADMIN))
916− return -EPERM;
917−
918− return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
919−}
920−#endif
921−
922911 /**
923912 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
924913 * @min: pointer to minimum allowable value
@@ -2210,63 +2199,6 @@ static struct ctl_table kern_table[] = { · 1285 unmodified lines
22102199 .mode = 0644,
22112200 .proc_handler = proc_doulongvec_minmax,
22122201 },
2213−#if defined CONFIG_PRINTK
2214− {
2215− .procname = "printk",
2216− .data = &console_loglevel,
2217− .maxlen = 4*sizeof(int),
2218− .mode = 0644,
2219− .proc_handler = proc_dointvec,
2220− },
2221− {
2222− .procname = "printk_ratelimit",
2223− .data = &printk_ratelimit_state.interval,
2224− .maxlen = sizeof(int),
2225− .mode = 0644,
2226− .proc_handler = proc_dointvec_jiffies,
2227− },
2228− {
2229− .procname = "printk_ratelimit_burst",
2230− .data = &printk_ratelimit_state.burst,
2231− .maxlen = sizeof(int),
2232− .mode = 0644,
2233− .proc_handler = proc_dointvec,
2234− },
2235− {
2236− .procname = "printk_delay",
2237− .data = &printk_delay_msec,
2238− .maxlen = sizeof(int),
2239− .mode = 0644,
2240− .proc_handler = proc_dointvec_minmax,
2241− .extra1 = SYSCTL_ZERO,
2242− .extra2 = (void *)&ten_thousand,
2243− },
2244− {
2245− .procname = "printk_devkmsg",
2246− .data = devkmsg_log_str,
2247− .maxlen = DEVKMSG_STR_MAX_SIZE,
2248− .mode = 0644,
2249− .proc_handler = devkmsg_sysctl_set_loglvl,
2250− },
2251− {
2252− .procname = "dmesg_restrict",
2253− .data = &dmesg_restrict,
2254− .maxlen = sizeof(int),
2255− .mode = 0644,
2256− .proc_handler = proc_dointvec_minmax_sysadmin,
2257− .extra1 = SYSCTL_ZERO,
2258− .extra2 = SYSCTL_ONE,
2259− },
2260− {
2261− .procname = "kptr_restrict",
2262− .data = &kptr_restrict,
2263− .maxlen = sizeof(int),
2264− .mode = 0644,
2265− .proc_handler = proc_dointvec_minmax_sysadmin,
2266− .extra1 = SYSCTL_ZERO,
2267− .extra2 = SYSCTL_TWO,
2268− },
2269−#endif
22702202 {
22712203 .procname = "ngroups_max",
22722204 .data = (void *)&ngroups_max,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t