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]
Unified · Split
| @@ -2,5 +2,8 @@ · 1 unmodified line | |||
| 2 | obj-y = printk.o | 2 | obj-y = printk.o |
| 3 | obj-$(CONFIG_PRINTK) += printk_safe.o | 3 | obj-$(CONFIG_PRINTK) += printk_safe.o |
| 4 | obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o | 4 | obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o |
| 5 | obj-$(CONFIG_PRINTK) += printk_ringbuffer.o | ||
| 6 | obj-$(CONFIG_PRINTK_INDEX) += index.o | 5 | 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 | ||
| @@ -4,6 +4,12 @@ · 3 unmodified lines | |||
| 4 | */ | 4 | */ |
| 5 | #include <linux/percpu.h> | 5 | #include <linux/percpu.h> |
| 6 | 6 | ||
| 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 | |||
| 7 | #ifdef CONFIG_PRINTK | 13 | #ifdef CONFIG_PRINTK |
| 8 | 14 | ||
| 9 | /* Flags for a single printk record. */ | 15 | /* Flags for a single printk record. */ |
| @@ -3211,6 +3211,7 @@ static int __init printk_late_init(void) · 3210 unmodified lines | |||
| 3211 | ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "printk:online", | 3211 | ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "printk:online", |
| 3212 | console_cpu_notify, NULL); | 3212 | console_cpu_notify, NULL); |
| 3213 | WARN_ON(ret < 0); | 3213 | WARN_ON(ret < 0); |
| 3214 | printk_sysctl_init(); | ||
| 3214 | return 0; | 3215 | return 0; |
| 3215 | } | 3216 | } |
| 3216 | late_initcall(printk_late_init); | 3217 | late_initcall(printk_late_init); |
| @@ -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 | } | ||
| @@ -908,17 +908,6 @@ static int proc_taint(struct ctl_table *table, int write, · 907 unmodified lines | |||
| 908 | return err; | 908 | return err; |
| 909 | } | 909 | } |
| 910 | 910 | ||
| 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 | |||
| 922 | /** | 911 | /** |
| 923 | * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure | 912 | * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure |
| 924 | * @min: pointer to minimum allowable value | 913 | * @min: pointer to minimum allowable value |
| @@ -2210,63 +2199,6 @@ static struct ctl_table kern_table[] = { · 1285 unmodified lines | |||
| 2210 | .mode = 0644, | 2199 | .mode = 0644, |
| 2211 | .proc_handler = proc_doulongvec_minmax, | 2200 | .proc_handler = proc_doulongvec_minmax, |
| 2212 | }, | 2201 | }, |
| 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 | ||
| 2270 | { | 2202 | { |
| 2271 | .procname = "ngroups_max", | 2203 | .procname = "ngroups_max", |
| 2272 | .data = (void *)&ngroups_max, | 2204 | .data = (void *)&ngroups_max, |