linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups
@ 2021-11-24 23:14 Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 1/8] firmware_loader: move firmware sysctl to its own files Luis Chamberlain
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Luis Chamberlain @ 2021-11-24 23:14 UTC (permalink / raw)
  To: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, pmladek, senozhatsky, rostedt, john.ogness,
	dgilbert, jejb, martin.petersen, mcgrof, mcgrof, linux-scsi
  Cc: linux-fsdevel, linux-kernel

This is the third set of patches to help address cleaning the kitchen
seink in kernel/sysctl.c and to move sysctls away to where they are
actually implemented / used.

Note that Andrew Morton is staging these to get visibility into changes
in the various trees which might conflict. He already grabbed the
first two sets of patch sets, and so I think these changes are probably
best to be eventually considered to be merged through his tree, to
avoid conflicts.

On this v2 series since last year's v1 series has these changes:

  * extended commit log to clarify that in these cases, while we
    are not producing less lines of code we justify the move
    because otherwise the file kernel/sysctl.c gets way out of hand
    to maintain.

  * addressed 0-day complaints

  * the firmware loader changes requested by Greg KH were adopted

  * added the new sysctl mount point helper as suggested by
    Eric W. Biederman

Luis Chamberlain (3):
  sysctl: add helper to register a sysctl mount point
  fs: move binfmt_misc sysctl to its own file
  sysctl: share unsigned long const values

Xiaoming Ni (5):
  firmware_loader: move firmware sysctl to its own files
  random: move the random sysctl declarations to its own file
  printk: move printk sysctl to printk/sysctl.c
  scsi/sg: move sg-big-buff sysctl to scsi/sg.c
  stackleak: move stack_erasing sysctl to stackleak.c

 drivers/base/firmware_loader/fallback.c       |   7 +-
 drivers/base/firmware_loader/fallback.h       |  11 ++
 drivers/base/firmware_loader/fallback_table.c |  21 ++-
 drivers/char/random.c                         |  14 +-
 drivers/scsi/sg.c                             |  35 ++++-
 fs/binfmt_misc.c                              |   6 +-
 fs/proc/proc_sysctl.c                         |  16 +++
 include/linux/stackleak.h                     |   5 -
 include/linux/sysctl.h                        |  15 ++-
 include/scsi/sg.h                             |   4 -
 kernel/printk/Makefile                        |   5 +-
 kernel/printk/internal.h                      |   6 +
 kernel/printk/printk.c                        |   1 +
 kernel/printk/sysctl.c                        |  85 ++++++++++++
 kernel/stackleak.c                            |  26 +++-
 kernel/sysctl.c                               | 122 +-----------------
 16 files changed, 239 insertions(+), 140 deletions(-)
 create mode 100644 kernel/printk/sysctl.c

-- 
2.33.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/8] firmware_loader: move firmware sysctl to its own files
  2021-11-24 23:14 [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups Luis Chamberlain
@ 2021-11-24 23:14 ` Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 2/8] random: move the random sysctl declarations to its own file Luis Chamberlain
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Luis Chamberlain @ 2021-11-24 23:14 UTC (permalink / raw)
  To: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, pmladek, senozhatsky, rostedt, john.ogness,
	dgilbert, jejb, martin.petersen, mcgrof, mcgrof, linux-scsi
  Cc: linux-fsdevel, linux-kernel

From: Xiaoming Ni <nixiaoming@huawei.com>

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 the firmware configuration sysctl table to the only place
where it is used, and make it clear that if sysctls are disabled
this is not used.

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
[mcgrof: major commit log update to justify the move]
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/base/firmware_loader/fallback.c       |  7 ++++++-
 drivers/base/firmware_loader/fallback.h       | 11 ++++++++++
 drivers/base/firmware_loader/fallback_table.c | 21 +++++++++++++++++--
 include/linux/sysctl.h                        |  1 -
 kernel/sysctl.c                               |  7 -------
 5 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
index d7d63c1aa993..4afb0e9312c0 100644
--- a/drivers/base/firmware_loader/fallback.c
+++ b/drivers/base/firmware_loader/fallback.c
@@ -199,11 +199,16 @@ static struct class firmware_class = {
 
 int register_sysfs_loader(void)
 {
-	return class_register(&firmware_class);
+	int ret = class_register(&firmware_class);
+
+	if (ret != 0)
+		return ret;
+	return register_firmware_config_sysctl();
 }
 
 void unregister_sysfs_loader(void)
 {
+	unregister_firmware_config_sysctl();
 	class_unregister(&firmware_class);
 }
 
diff --git a/drivers/base/firmware_loader/fallback.h b/drivers/base/firmware_loader/fallback.h
index 3af7205b302f..9f3055d3b4ca 100644
--- a/drivers/base/firmware_loader/fallback.h
+++ b/drivers/base/firmware_loader/fallback.h
@@ -42,6 +42,17 @@ void fw_fallback_set_default_timeout(void);
 
 int register_sysfs_loader(void);
 void unregister_sysfs_loader(void);
+#ifdef CONFIG_SYSCTL
+extern int register_firmware_config_sysctl(void);
+extern void unregister_firmware_config_sysctl(void);
+#else
+static inline int register_firmware_config_sysctl(void)
+{
+	return 0;
+}
+static inline void unregister_firmware_config_sysctl(void) { }
+#endif /* CONFIG_SYSCTL */
+
 #else /* CONFIG_FW_LOADER_USER_HELPER */
 static inline int firmware_fallback_sysfs(struct firmware *fw, const char *name,
 					  struct device *device,
diff --git a/drivers/base/firmware_loader/fallback_table.c b/drivers/base/firmware_loader/fallback_table.c
index 46a731dede6f..51751c46cdcf 100644
--- a/drivers/base/firmware_loader/fallback_table.c
+++ b/drivers/base/firmware_loader/fallback_table.c
@@ -24,7 +24,7 @@ struct firmware_fallback_config fw_fallback_config = {
 EXPORT_SYMBOL_NS_GPL(fw_fallback_config, FIRMWARE_LOADER_PRIVATE);
 
 #ifdef CONFIG_SYSCTL
-struct ctl_table firmware_config_table[] = {
+static struct ctl_table firmware_config_table[] = {
 	{
 		.procname	= "force_sysfs_fallback",
 		.data		= &fw_fallback_config.force_sysfs_fallback,
@@ -45,4 +45,21 @@ struct ctl_table firmware_config_table[] = {
 	},
 	{ }
 };
-#endif
+
+static struct ctl_table_header *firmware_config_sysct_table_header;
+int register_firmware_config_sysctl(void)
+{
+	firmware_config_sysct_table_header =
+		register_sysctl("kernel/firmware_config",
+				firmware_config_table);
+	if (!firmware_config_sysct_table_header)
+		return -ENOMEM;
+	return 0;
+}
+
+void unregister_firmware_config_sysctl(void)
+{
+	unregister_sysctl_table(firmware_config_sysct_table_header);
+	firmware_config_sysct_table_header = NULL;
+}
+#endif /* CONFIG_SYSCTL */
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 5e0428a71899..ae6e66177d88 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -217,7 +217,6 @@ extern int no_unaligned_warning;
 
 extern struct ctl_table sysctl_mount_point[];
 extern struct ctl_table random_table[];
-extern struct ctl_table firmware_config_table[];
 
 #else /* CONFIG_SYSCTL */
 static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index b09ff41720e3..3032aaa11ed9 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2153,13 +2153,6 @@ static struct ctl_table kern_table[] = {
 		.mode		= 0555,
 		.child		= usermodehelper_table,
 	},
-#ifdef CONFIG_FW_LOADER_USER_HELPER
-	{
-		.procname	= "firmware_config",
-		.mode		= 0555,
-		.child		= firmware_config_table,
-	},
-#endif
 	{
 		.procname	= "overflowuid",
 		.data		= &overflowuid,
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/8] random: move the random sysctl declarations to its own file
  2021-11-24 23:14 [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 1/8] firmware_loader: move firmware sysctl to its own files Luis Chamberlain
@ 2021-11-24 23:14 ` Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 3/8] sysctl: add helper to register a sysctl mount point Luis Chamberlain
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Luis Chamberlain @ 2021-11-24 23:14 UTC (permalink / raw)
  To: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, pmladek, senozhatsky, rostedt, john.ogness,
	dgilbert, jejb, martin.petersen, mcgrof, mcgrof, linux-scsi
  Cc: linux-fsdevel, linux-kernel

From: Xiaoming Ni <nixiaoming@huawei.com>

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 the random sysctls to its own file and use
register_sysctl_init().

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
[mcgrof: commit log update to justify the move]
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/char/random.c  | 14 ++++++++++++--
 include/linux/sysctl.h |  1 -
 kernel/sysctl.c        |  5 -----
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 605969ed0f96..35fcc09c0228 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -2077,8 +2077,7 @@ static int proc_do_entropy(struct ctl_table *table, int write,
 }
 
 static int sysctl_poolsize = INPUT_POOL_WORDS * 32;
-extern struct ctl_table random_table[];
-struct ctl_table random_table[] = {
+static struct ctl_table random_table[] = {
 	{
 		.procname	= "poolsize",
 		.data		= &sysctl_poolsize,
@@ -2140,6 +2139,17 @@ struct ctl_table random_table[] = {
 #endif
 	{ }
 };
+
+/*
+ * rand_initialize() is called before sysctl_init(),
+ * so we cannot call register_sysctl_init() in rand_initialize()
+ */
+static int __init random_sysctls_init(void)
+{
+	register_sysctl_init("kernel/random", random_table);
+	return 0;
+}
+device_initcall(random_sysctls_init);
 #endif 	/* CONFIG_SYSCTL */
 
 struct batched_entropy {
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index ae6e66177d88..e4da44567f18 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -216,7 +216,6 @@ extern int unaligned_dump_stack;
 extern int no_unaligned_warning;
 
 extern struct ctl_table sysctl_mount_point[];
-extern struct ctl_table random_table[];
 
 #else /* CONFIG_SYSCTL */
 static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 3032aaa11ed9..1682714605e6 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2143,11 +2143,6 @@ static struct ctl_table kern_table[] = {
 		.mode		= 0644,
 		.proc_handler	= sysctl_max_threads,
 	},
-	{
-		.procname	= "random",
-		.mode		= 0555,
-		.child		= random_table,
-	},
 	{
 		.procname	= "usermodehelper",
 		.mode		= 0555,
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/8] sysctl: add helper to register a sysctl mount point
  2021-11-24 23:14 [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 1/8] firmware_loader: move firmware sysctl to its own files Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 2/8] random: move the random sysctl declarations to its own file Luis Chamberlain
@ 2021-11-24 23:14 ` Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 4/8] fs: move binfmt_misc sysctl to its own file Luis Chamberlain
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Luis Chamberlain @ 2021-11-24 23:14 UTC (permalink / raw)
  To: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, pmladek, senozhatsky, rostedt, john.ogness,
	dgilbert, jejb, martin.petersen, mcgrof, mcgrof, linux-scsi
  Cc: linux-fsdevel, linux-kernel

The way to create a subdirectory on top of sysctl_mount_point is
a bit obscure, and *why* we do that even so more. Provide a helper
which makes it clear why we do this.

Suggested-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 fs/proc/proc_sysctl.c  | 13 +++++++++++++
 include/linux/sysctl.h |  7 +++++++
 2 files changed, 20 insertions(+)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 6d462644bb00..aa743bbb8400 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -35,6 +35,19 @@ struct ctl_table sysctl_mount_point[] = {
 	{ }
 };
 
+/**
+ * register_sysctl_mount_point() - registers a sysctl mount point
+ * @path: path for the mount point
+ *
+ * Used to create a permanently empty directory to serve as mount point.
+ * There are some subtle but important permission checks this allows in the
+ * case of unprivileged mounts.
+ */
+struct ctl_table_header *register_sysctl_mount_point(const char *path)
+{
+	return register_sysctl(path, sysctl_mount_point);
+}
+
 static bool is_empty_dir(struct ctl_table_header *head)
 {
 	return head->ctl_table[0].child == sysctl_mount_point;
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index e4da44567f18..7946b532e964 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -208,6 +208,8 @@ extern int sysctl_init(void);
 extern void __register_sysctl_init(const char *path, struct ctl_table *table,
 				 const char *table_name);
 #define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table)
+extern struct ctl_table_header *register_sysctl_mount_point(const char *path);
+
 void do_sysctl_args(void);
 
 extern int pwrsw_enabled;
@@ -223,6 +225,11 @@ static inline struct ctl_table_header *register_sysctl_table(struct ctl_table *
 	return NULL;
 }
 
+static inline struct sysctl_header *register_sysctl_mount_point(const char *path)
+{
+	return NULL;
+}
+
 static inline struct ctl_table_header *register_sysctl_paths(
 			const struct ctl_path *path, struct ctl_table *table)
 {
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 4/8] fs: move binfmt_misc sysctl to its own file
  2021-11-24 23:14 [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups Luis Chamberlain
                   ` (2 preceding siblings ...)
  2021-11-24 23:14 ` [PATCH v2 3/8] sysctl: add helper to register a sysctl mount point Luis Chamberlain
@ 2021-11-24 23:14 ` Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 5/8] printk: move printk sysctl to printk/sysctl.c Luis Chamberlain
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Luis Chamberlain @ 2021-11-24 23:14 UTC (permalink / raw)
  To: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, pmladek, senozhatsky, rostedt, john.ogness,
	dgilbert, jejb, martin.petersen, mcgrof, mcgrof, linux-scsi
  Cc: linux-fsdevel, linux-kernel

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.

This moves the binfmt_misc sysctl to its own file to help remove
clutter from kernel/sysctl.c.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 fs/binfmt_misc.c | 6 +++++-
 kernel/sysctl.c  | 7 -------
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index e1eae7ea823a..ddea6acbddde 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -822,7 +822,11 @@ static int __init init_misc_binfmt(void)
 	int err = register_filesystem(&bm_fs_type);
 	if (!err)
 		insert_binfmt(&misc_format);
-	return err;
+	if (!register_sysctl_mount_point("fs/binfmt_misc")) {
+		pr_warn("Failed to create fs/binfmt_misc sysctl mount point");
+		return -ENOMEM;
+	}
+	return 0;
 }
 
 static void __exit exit_misc_binfmt(void)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 1682714605e6..7745c9b72bda 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -3126,13 +3126,6 @@ static struct ctl_table fs_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_TWO,
 	},
-#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
-	{
-		.procname	= "binfmt_misc",
-		.mode		= 0555,
-		.child		= sysctl_mount_point,
-	},
-#endif
 	{
 		.procname	= "pipe-max-size",
 		.data		= &pipe_max_size,
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 5/8] printk: move printk sysctl to printk/sysctl.c
  2021-11-24 23:14 [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups Luis Chamberlain
                   ` (3 preceding siblings ...)
  2021-11-24 23:14 ` [PATCH v2 4/8] fs: move binfmt_misc sysctl to its own file Luis Chamberlain
@ 2021-11-24 23:14 ` Luis Chamberlain
  2021-11-26 12:51   ` Petr Mladek
  2021-11-24 23:14 ` [PATCH v2 6/8] scsi/sg: move sg-big-buff sysctl to scsi/sg.c Luis Chamberlain
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 11+ messages in thread
From: Luis Chamberlain @ 2021-11-24 23:14 UTC (permalink / raw)
  To: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, pmladek, senozhatsky, rostedt, john.ogness,
	dgilbert, jejb, martin.petersen, mcgrof, mcgrof, linux-scsi
  Cc: linux-fsdevel, linux-kernel

From: Xiaoming Ni <nixiaoming@huawei.com>

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 printk sysctl from kernel/sysctl.c to kernel/printk/sysctl.c.
Use register_sysctl() to register the sysctl interface.

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
[mcgrof: fixed compile issues when PRINTK is not set, commit log update]
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 kernel/printk/Makefile   |  5 ++-
 kernel/printk/internal.h |  6 +++
 kernel/printk/printk.c   |  1 +
 kernel/printk/sysctl.c   | 85 ++++++++++++++++++++++++++++++++++++++++
 kernel/sysctl.c          | 68 --------------------------------
 5 files changed, 96 insertions(+), 69 deletions(-)
 create mode 100644 kernel/printk/sysctl.c

diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile
index d118739874c0..f5b388e810b9 100644
--- a/kernel/printk/Makefile
+++ b/kernel/printk/Makefile
@@ -2,5 +2,8 @@
 obj-y	= printk.o
 obj-$(CONFIG_PRINTK)	+= printk_safe.o
 obj-$(CONFIG_A11Y_BRAILLE_CONSOLE)	+= braille.o
-obj-$(CONFIG_PRINTK)	+= printk_ringbuffer.o
 obj-$(CONFIG_PRINTK_INDEX)	+= index.o
+
+obj-$(CONFIG_PRINTK)                 += printk_support.o
+printk_support-y	             := printk_ringbuffer.o
+printk_support-$(CONFIG_SYSCTL)	     += sysctl.o
diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h
index 9f3ed2fdb721..6b1c4b399845 100644
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
@@ -4,6 +4,12 @@
  */
 #include <linux/percpu.h>
 
+#if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL)
+void __init printk_sysctl_init(void);
+#else
+#define printk_sysctl_init() do { } while (0)
+#endif
+
 #ifdef CONFIG_PRINTK
 
 /* Flags for a single printk record. */
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index cbc35d586afb..dbb44086ba65 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3202,6 +3202,7 @@ static int __init printk_late_init(void)
 	ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "printk:online",
 					console_cpu_notify, NULL);
 	WARN_ON(ret < 0);
+	printk_sysctl_init();
 	return 0;
 }
 late_initcall(printk_late_init);
diff --git a/kernel/printk/sysctl.c b/kernel/printk/sysctl.c
new file mode 100644
index 000000000000..653ae04aab7f
--- /dev/null
+++ b/kernel/printk/sysctl.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * sysctl.c: General linux system control interface
+ */
+
+#include <linux/sysctl.h>
+#include <linux/printk.h>
+#include <linux/capability.h>
+#include <linux/ratelimit.h>
+#include "internal.h"
+
+static const int ten_thousand = 10000;
+
+static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
+				void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+	if (write && !capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+}
+
+static struct ctl_table printk_sysctls[] = {
+	{
+		.procname	= "printk",
+		.data		= &console_loglevel,
+		.maxlen		= 4*sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+	{
+		.procname	= "printk_ratelimit",
+		.data		= &printk_ratelimit_state.interval,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_jiffies,
+	},
+	{
+		.procname	= "printk_ratelimit_burst",
+		.data		= &printk_ratelimit_state.burst,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+	{
+		.procname	= "printk_delay",
+		.data		= &printk_delay_msec,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= (void *)&ten_thousand,
+	},
+	{
+		.procname	= "printk_devkmsg",
+		.data		= devkmsg_log_str,
+		.maxlen		= DEVKMSG_STR_MAX_SIZE,
+		.mode		= 0644,
+		.proc_handler	= devkmsg_sysctl_set_loglvl,
+	},
+	{
+		.procname	= "dmesg_restrict",
+		.data		= &dmesg_restrict,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax_sysadmin,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+	{
+		.procname	= "kptr_restrict",
+		.data		= &kptr_restrict,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax_sysadmin,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_TWO,
+	},
+	{}
+};
+
+void __init printk_sysctl_init(void)
+{
+	register_sysctl_init("kernel", printk_sysctls);
+}
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7745c9b72bda..02ef27804601 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -907,17 +907,6 @@ static int proc_taint(struct ctl_table *table, int write,
 	return err;
 }
 
-#ifdef CONFIG_PRINTK
-static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
-				void *buffer, size_t *lenp, loff_t *ppos)
-{
-	if (write && !capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
-	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
-}
-#endif
-
 /**
  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
  * @min: pointer to minimum allowable value
@@ -2209,63 +2198,6 @@ static struct ctl_table kern_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_doulongvec_minmax,
 	},
-#if defined CONFIG_PRINTK
-	{
-		.procname	= "printk",
-		.data		= &console_loglevel,
-		.maxlen		= 4*sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
-	},
-	{
-		.procname	= "printk_ratelimit",
-		.data		= &printk_ratelimit_state.interval,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_jiffies,
-	},
-	{
-		.procname	= "printk_ratelimit_burst",
-		.data		= &printk_ratelimit_state.burst,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
-	},
-	{
-		.procname	= "printk_delay",
-		.data		= &printk_delay_msec,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= (void *)&ten_thousand,
-	},
-	{
-		.procname	= "printk_devkmsg",
-		.data		= devkmsg_log_str,
-		.maxlen		= DEVKMSG_STR_MAX_SIZE,
-		.mode		= 0644,
-		.proc_handler	= devkmsg_sysctl_set_loglvl,
-	},
-	{
-		.procname	= "dmesg_restrict",
-		.data		= &dmesg_restrict,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax_sysadmin,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
-	{
-		.procname	= "kptr_restrict",
-		.data		= &kptr_restrict,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax_sysadmin,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_TWO,
-	},
-#endif
 	{
 		.procname	= "ngroups_max",
 		.data		= (void *)&ngroups_max,
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 6/8] scsi/sg: move sg-big-buff sysctl to scsi/sg.c
  2021-11-24 23:14 [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups Luis Chamberlain
                   ` (4 preceding siblings ...)
  2021-11-24 23:14 ` [PATCH v2 5/8] printk: move printk sysctl to printk/sysctl.c Luis Chamberlain
@ 2021-11-24 23:14 ` Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 7/8] stackleak: move stack_erasing sysctl to stackleak.c Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 8/8] sysctl: share unsigned long const values Luis Chamberlain
  7 siblings, 0 replies; 11+ messages in thread
From: Luis Chamberlain @ 2021-11-24 23:14 UTC (permalink / raw)
  To: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, pmladek, senozhatsky, rostedt, john.ogness,
	dgilbert, jejb, martin.petersen, mcgrof, mcgrof, linux-scsi
  Cc: linux-fsdevel, linux-kernel

From: Xiaoming Ni <nixiaoming@huawei.com>

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 the sg-big-buff sysctl from kernel/sysctl.c to
drivers/scsi/sg.c and use register_sysctl() to register the
sysctl interface.

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
[mcgrof: commit log update]
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/scsi/sg.c | 35 ++++++++++++++++++++++++++++++++++-
 include/scsi/sg.h |  4 ----
 kernel/sysctl.c   | 12 ------------
 3 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 141099ab9092..32129bb16521 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -77,7 +77,7 @@ static int sg_proc_init(void);
 
 #define SG_DEFAULT_TIMEOUT mult_frac(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ)
 
-int sg_big_buff = SG_DEF_RESERVED_SIZE;
+static int sg_big_buff = SG_DEF_RESERVED_SIZE;
 /* N.B. This variable is readable and writeable via
    /proc/scsi/sg/def_reserved_size . Each time sg_open() is called a buffer
    of this size (or less if there is not enough memory) will be reserved
@@ -1634,6 +1634,37 @@ MODULE_PARM_DESC(scatter_elem_sz, "scatter gather element "
 MODULE_PARM_DESC(def_reserved_size, "size of buffer reserved for each fd");
 MODULE_PARM_DESC(allow_dio, "allow direct I/O (default: 0 (disallow))");
 
+#ifdef CONFIG_SYSCTL
+#include <linux/sysctl.h>
+
+static struct ctl_table sg_sysctls[] = {
+	{
+		.procname	= "sg-big-buff",
+		.data		= &sg_big_buff,
+		.maxlen		= sizeof(int),
+		.mode		= 0444,
+		.proc_handler	= proc_dointvec,
+	},
+	{}
+};
+
+static struct ctl_table_header *hdr;
+static void register_sg_sysctls(void)
+{
+	if (!hdr)
+		hdr = register_sysctl("kernel", sg_sysctls);
+}
+
+static void unregister_sg_sysctls(void)
+{
+	if (hdr)
+		unregister_sysctl_table(hdr);
+}
+#else
+#define register_sg_sysctls() do { } while (0)
+#define unregister_sg_sysctls() do { } while (0)
+#endif /* CONFIG_SYSCTL */
+
 static int __init
 init_sg(void)
 {
@@ -1666,6 +1697,7 @@ init_sg(void)
 		return 0;
 	}
 	class_destroy(sg_sysfs_class);
+	register_sg_sysctls();
 err_out:
 	unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), SG_MAX_DEVS);
 	return rc;
@@ -1674,6 +1706,7 @@ init_sg(void)
 static void __exit
 exit_sg(void)
 {
+	unregister_sg_sysctls();
 #ifdef CONFIG_SCSI_PROC_FS
 	remove_proc_subtree("scsi/sg", NULL);
 #endif				/* CONFIG_SCSI_PROC_FS */
diff --git a/include/scsi/sg.h b/include/scsi/sg.h
index 843cefb8efce..068e35d36557 100644
--- a/include/scsi/sg.h
+++ b/include/scsi/sg.h
@@ -29,10 +29,6 @@
  * For utility and test programs see: http://sg.danny.cz/sg/sg3_utils.html
  */
 
-#ifdef __KERNEL__
-extern int sg_big_buff; /* for sysctl */
-#endif
-
 
 typedef struct sg_iovec /* same structure as used by readv() Linux system */
 {                       /* call. It defines one scatter-gather element. */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 02ef27804601..a4bda4a11ea8 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -94,9 +94,6 @@
 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
 #include <linux/lockdep.h>
 #endif
-#ifdef CONFIG_CHR_DEV_SG
-#include <scsi/sg.h>
-#endif
 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
 #include <linux/stackleak.h>
 #endif
@@ -2089,15 +2086,6 @@ static struct ctl_table kern_table[] = {
 		.proc_handler	= proc_dostring,
 	},
 #endif
-#ifdef CONFIG_CHR_DEV_SG
-	{
-		.procname	= "sg-big-buff",
-		.data		= &sg_big_buff,
-		.maxlen		= sizeof (int),
-		.mode		= 0444,
-		.proc_handler	= proc_dointvec,
-	},
-#endif
 #ifdef CONFIG_BSD_PROCESS_ACCT
 	{
 		.procname	= "acct",
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 7/8] stackleak: move stack_erasing sysctl to stackleak.c
  2021-11-24 23:14 [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups Luis Chamberlain
                   ` (5 preceding siblings ...)
  2021-11-24 23:14 ` [PATCH v2 6/8] scsi/sg: move sg-big-buff sysctl to scsi/sg.c Luis Chamberlain
@ 2021-11-24 23:14 ` Luis Chamberlain
  2021-11-24 23:14 ` [PATCH v2 8/8] sysctl: share unsigned long const values Luis Chamberlain
  7 siblings, 0 replies; 11+ messages in thread
From: Luis Chamberlain @ 2021-11-24 23:14 UTC (permalink / raw)
  To: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, pmladek, senozhatsky, rostedt, john.ogness,
	dgilbert, jejb, martin.petersen, mcgrof, mcgrof, linux-scsi
  Cc: linux-fsdevel, linux-kernel

From: Xiaoming Ni <nixiaoming@huawei.com>

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 the stack_erasing sysctl from kernel/sysctl.c to
kernel/stackleak.c and use register_sysctl() to register the
sysctl interface.

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
[mcgrof: commit log update]
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 include/linux/stackleak.h |  5 -----
 kernel/stackleak.c        | 26 ++++++++++++++++++++++++--
 kernel/sysctl.c           | 14 --------------
 3 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/include/linux/stackleak.h b/include/linux/stackleak.h
index a59db2f08e76..ccaab2043fcd 100644
--- a/include/linux/stackleak.h
+++ b/include/linux/stackleak.h
@@ -23,11 +23,6 @@ static inline void stackleak_task_init(struct task_struct *t)
 # endif
 }
 
-#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
-int stack_erasing_sysctl(struct ctl_table *table, int write,
-			void *buffer, size_t *lenp, loff_t *ppos);
-#endif
-
 #else /* !CONFIG_GCC_PLUGIN_STACKLEAK */
 static inline void stackleak_task_init(struct task_struct *t) { }
 #endif
diff --git a/kernel/stackleak.c b/kernel/stackleak.c
index ce161a8e8d97..66b8af394e58 100644
--- a/kernel/stackleak.c
+++ b/kernel/stackleak.c
@@ -16,11 +16,13 @@
 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
 #include <linux/jump_label.h>
 #include <linux/sysctl.h>
+#include <linux/init.h>
 
 static DEFINE_STATIC_KEY_FALSE(stack_erasing_bypass);
 
-int stack_erasing_sysctl(struct ctl_table *table, int write,
-			void *buffer, size_t *lenp, loff_t *ppos)
+#ifdef CONFIG_SYSCTL
+static int stack_erasing_sysctl(struct ctl_table *table, int write,
+			void __user *buffer, size_t *lenp, loff_t *ppos)
 {
 	int ret = 0;
 	int state = !static_branch_unlikely(&stack_erasing_bypass);
@@ -42,6 +44,26 @@ int stack_erasing_sysctl(struct ctl_table *table, int write,
 					state ? "enabled" : "disabled");
 	return ret;
 }
+static struct ctl_table stackleak_sysctls[] = {
+	{
+		.procname	= "stack_erasing",
+		.data		= NULL,
+		.maxlen		= sizeof(int),
+		.mode		= 0600,
+		.proc_handler	= stack_erasing_sysctl,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+	{}
+};
+
+static int __init stackleak_sysctls_init(void)
+{
+	register_sysctl_init("kernel", stackleak_sysctls);
+	return 0;
+}
+late_initcall(stackleak_sysctls_init);
+#endif /* CONFIG_SYSCTL */
 
 #define skip_erasing()	static_branch_unlikely(&stack_erasing_bypass)
 #else
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index a4bda4a11ea8..5812d76ecee1 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -94,9 +94,6 @@
 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
 #include <linux/lockdep.h>
 #endif
-#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
-#include <linux/stackleak.h>
-#endif
 
 #if defined(CONFIG_SYSCTL)
 
@@ -2441,17 +2438,6 @@ static struct ctl_table kern_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_INT_MAX,
 	},
-#endif
-#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
-	{
-		.procname	= "stack_erasing",
-		.data		= NULL,
-		.maxlen		= sizeof(int),
-		.mode		= 0600,
-		.proc_handler	= stack_erasing_sysctl,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
 #endif
 	{ }
 };
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 8/8] sysctl: share unsigned long const values
  2021-11-24 23:14 [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups Luis Chamberlain
                   ` (6 preceding siblings ...)
  2021-11-24 23:14 ` [PATCH v2 7/8] stackleak: move stack_erasing sysctl to stackleak.c Luis Chamberlain
@ 2021-11-24 23:14 ` Luis Chamberlain
  7 siblings, 0 replies; 11+ messages in thread
From: Luis Chamberlain @ 2021-11-24 23:14 UTC (permalink / raw)
  To: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, pmladek, senozhatsky, rostedt, john.ogness,
	dgilbert, jejb, martin.petersen, mcgrof, mcgrof, linux-scsi
  Cc: linux-fsdevel, linux-kernel

Provide a way to share unsigned long values.
This will allow others to not have to re-invent
these values.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 fs/proc/proc_sysctl.c  | 3 +++
 include/linux/sysctl.h | 6 ++++++
 kernel/sysctl.c        | 9 +++------
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index aa743bbb8400..2b73648a19a5 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -29,6 +29,9 @@ static const struct inode_operations proc_sys_dir_operations;
 const int sysctl_vals[] = { -1, 0, 1, 2, 4, 100, 200, 1000, INT_MAX };
 EXPORT_SYMBOL(sysctl_vals);
 
+const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
+EXPORT_SYMBOL_GPL(sysctl_long_vals);
+
 /* Support for permanently empty directories */
 
 struct ctl_table sysctl_mount_point[] = {
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 7946b532e964..162aaee92daf 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -50,6 +50,12 @@ struct ctl_dir;
 
 extern const int sysctl_vals[];
 
+#define SYSCTL_LONG_ZERO	((void *)&sysctl_long_vals[0])
+#define SYSCTL_LONG_ONE		((void *)&sysctl_long_vals[1])
+#define SYSCTL_LONG_MAX		((void *)&sysctl_long_vals[2])
+
+extern const unsigned long sysctl_long_vals[];
+
 typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer,
 		size_t *lenp, loff_t *ppos);
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 5812d76ecee1..b8a3dcf7b925 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -99,9 +99,6 @@
 
 /* Constants used for minimum and  maximum */
 
-static const unsigned long zero_ul;
-static const unsigned long one_ul = 1;
-static const unsigned long long_max = LONG_MAX;
 #ifdef CONFIG_PRINTK
 static const int ten_thousand = 10000;
 #endif
@@ -2512,7 +2509,7 @@ static struct ctl_table vm_table[] = {
 		.maxlen		= sizeof(dirty_background_bytes),
 		.mode		= 0644,
 		.proc_handler	= dirty_background_bytes_handler,
-		.extra1		= (void *)&one_ul,
+		.extra1		= SYSCTL_LONG_ONE,
 	},
 	{
 		.procname	= "dirty_ratio",
@@ -2930,8 +2927,8 @@ static struct ctl_table fs_table[] = {
 		.maxlen		= sizeof(files_stat.max_files),
 		.mode		= 0644,
 		.proc_handler	= proc_doulongvec_minmax,
-		.extra1		= (void *)&zero_ul,
-		.extra2		= (void *)&long_max,
+		.extra1		= SYSCTL_LONG_ZERO,
+		.extra2		= SYSCTL_LONG_MAX,
 	},
 	{
 		.procname	= "nr_open",
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 5/8] printk: move printk sysctl to printk/sysctl.c
  2021-11-24 23:14 ` [PATCH v2 5/8] printk: move printk sysctl to printk/sysctl.c Luis Chamberlain
@ 2021-11-26 12:51   ` Petr Mladek
  2021-11-29 20:48     ` Luis Chamberlain
  0 siblings, 1 reply; 11+ messages in thread
From: Petr Mladek @ 2021-11-26 12:51 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, senozhatsky, rostedt, john.ogness, dgilbert,
	jejb, martin.petersen, mcgrof, linux-scsi, linux-fsdevel,
	linux-kernel

On Wed 2021-11-24 15:14:32, Luis Chamberlain wrote:
> From: Xiaoming Ni <nixiaoming@huawei.com>
> 
> 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 printk sysctl from kernel/sysctl.c to kernel/printk/sysctl.c.
> Use register_sysctl() to register the sysctl interface.
> 
> diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile
> index d118739874c0..f5b388e810b9 100644
> --- a/kernel/printk/Makefile
> +++ b/kernel/printk/Makefile
> @@ -2,5 +2,8 @@
>  obj-y	= printk.o
>  obj-$(CONFIG_PRINTK)	+= printk_safe.o
>  obj-$(CONFIG_A11Y_BRAILLE_CONSOLE)	+= braille.o
> -obj-$(CONFIG_PRINTK)	+= printk_ringbuffer.o
>  obj-$(CONFIG_PRINTK_INDEX)	+= index.o
> +
> +obj-$(CONFIG_PRINTK)                 += printk_support.o
> +printk_support-y	             := printk_ringbuffer.o
> +printk_support-$(CONFIG_SYSCTL)	     += sysctl.o

I have never seen this trick. It looks like a dirty hack ;-)
Anyway, I do not see it described in the documentation. I wonder
if it works only by chance.

IMHO, a cleaner solution would be to add the following
into init/Kconfig:

config BUILD_PRINTK_SYSCTL
	bool
	default (PRINTK && SYSCTL)

and then use:

obj-$(CONFIG_BUILD_PRINTK_SYSCTL)    += sysctl.o


> diff --git a/kernel/printk/sysctl.c b/kernel/printk/sysctl.c
> new file mode 100644
> index 000000000000..653ae04aab7f
> --- /dev/null
> +++ b/kernel/printk/sysctl.c
> @@ -0,0 +1,85 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * sysctl.c: General linux system control interface
> + */
> +
> +#include <linux/sysctl.h>
> +#include <linux/printk.h>
> +#include <linux/capability.h>
> +#include <linux/ratelimit.h>
> +#include "internal.h"
> +
> +static const int ten_thousand = 10000;

The patch should also remove the variable in kernel/sysctl.c.

Otherwise, it looks like a really nice clean up.

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 5/8] printk: move printk sysctl to printk/sysctl.c
  2021-11-26 12:51   ` Petr Mladek
@ 2021-11-29 20:48     ` Luis Chamberlain
  0 siblings, 0 replies; 11+ messages in thread
From: Luis Chamberlain @ 2021-11-29 20:48 UTC (permalink / raw)
  To: Petr Mladek
  Cc: akpm, keescook, yzaikin, nixiaoming, ebiederm, steve, gregkh,
	rafael, tytso, viro, senozhatsky, rostedt, john.ogness, dgilbert,
	jejb, martin.petersen, linux-scsi, linux-fsdevel, linux-kernel

On Fri, Nov 26, 2021 at 01:51:38PM +0100, Petr Mladek wrote:
> On Wed 2021-11-24 15:14:32, Luis Chamberlain wrote:
> > From: Xiaoming Ni <nixiaoming@huawei.com>
> > 
> > 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 printk sysctl from kernel/sysctl.c to kernel/printk/sysctl.c.
> > Use register_sysctl() to register the sysctl interface.
> > 
> > diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile
> > index d118739874c0..f5b388e810b9 100644
> > --- a/kernel/printk/Makefile
> > +++ b/kernel/printk/Makefile
> > @@ -2,5 +2,8 @@
> >  obj-y	= printk.o
> >  obj-$(CONFIG_PRINTK)	+= printk_safe.o
> >  obj-$(CONFIG_A11Y_BRAILLE_CONSOLE)	+= braille.o
> > -obj-$(CONFIG_PRINTK)	+= printk_ringbuffer.o
> >  obj-$(CONFIG_PRINTK_INDEX)	+= index.o
> > +
> > +obj-$(CONFIG_PRINTK)                 += printk_support.o
> > +printk_support-y	             := printk_ringbuffer.o
> > +printk_support-$(CONFIG_SYSCTL)	     += sysctl.o
> 
> I have never seen this trick. It looks like a dirty hack ;-)

It has been used in mac80211 for over a decade now :) See
net/mac80211/Makefile

> Anyway, I do not see it described in the documentation. I wonder
> if it works only by chance.
> 
> IMHO, a cleaner solution would be to add the following
> into init/Kconfig:
> 
> config BUILD_PRINTK_SYSCTL
> 	bool
> 	default (PRINTK && SYSCTL)
> 
> and then use:
> 
> obj-$(CONFIG_BUILD_PRINTK_SYSCTL)    += sysctl.o

I suppose it is a matter of taste, either way works with me,
but I think less kconfig logic is better here.

> > diff --git a/kernel/printk/sysctl.c b/kernel/printk/sysctl.c
> > new file mode 100644
> > index 000000000000..653ae04aab7f
> > --- /dev/null
> > +++ b/kernel/printk/sysctl.c
> > @@ -0,0 +1,85 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * sysctl.c: General linux system control interface
> > + */
> > +
> > +#include <linux/sysctl.h>
> > +#include <linux/printk.h>
> > +#include <linux/capability.h>
> > +#include <linux/ratelimit.h>
> > +#include "internal.h"
> > +
> > +static const int ten_thousand = 10000;
> 
> The patch should also remove the variable in kernel/sysctl.c.
> 
> Otherwise, it looks like a really nice clean up.

Ah yes that variable is now unused there. Thanks

  Luis

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-11-29 22:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24 23:14 [PATCH v2 0/8] sysctl: 3rd set of kernel/sysctl cleanups Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 1/8] firmware_loader: move firmware sysctl to its own files Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 2/8] random: move the random sysctl declarations to its own file Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 3/8] sysctl: add helper to register a sysctl mount point Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 4/8] fs: move binfmt_misc sysctl to its own file Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 5/8] printk: move printk sysctl to printk/sysctl.c Luis Chamberlain
2021-11-26 12:51   ` Petr Mladek
2021-11-29 20:48     ` Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 6/8] scsi/sg: move sg-big-buff sysctl to scsi/sg.c Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 7/8] stackleak: move stack_erasing sysctl to stackleak.c Luis Chamberlain
2021-11-24 23:14 ` [PATCH v2 8/8] sysctl: share unsigned long const values Luis Chamberlain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).