Skip to contentSkip to conversation

module: Move sysfs support into a separate file

PATCH Superseded Aaron Tomlin 4 participants 14 messages Feb 9, 2022 – Feb 17, 2022

Subsystems (3)

v5 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 11/13 module: Move sysfs support into a separate file

No functional change.

This patch migrates module sysfs support out of core code into kernel/module/sysfs.c. In addition simple code refactoring to make this possible.

---
 kernel/module/Makefile   |   1 +
 kernel/module/internal.h |  24 ++
 kernel/module/main.c     | 458 +--------------------------------------
 kernel/module/sysfs.c    | 425 ++++++++++++++++++++++++++++++++++++
 4 files changed, 453 insertions(+), 455 deletions(-)
 create mode 100644 kernel/module/sysfs.c
kernel/module/Makefile +1 -0
index c6be08060252..c30141c37eb3 100644
@@ -14,4 +14,5 @@ obj-$(CONFIG_STRICT_MODULE_RWX) += strict_rwx.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o
 obj-$(CONFIG_KALLSYMS) += kallsyms.o
 obj-$(CONFIG_PROC_FS) += procfs.o
+obj-$(CONFIG_SYSFS) += sysfs.o
 endif
kernel/module/internal.h +24 -0
index b67ce836746a..52d30bf6d6b0 100644
@@ -35,6 +35,9 @@
 extern struct mutex module_mutex;
 extern struct list_head modules;
 
+extern struct module_attribute *modinfo_attrs[];
+extern size_t modinfo_attrs_count;
+
 /* Provided by the linker */
 extern const struct kernel_symbol __start___ksymtab[];
 extern const struct kernel_symbol __stop___ksymtab[];
@@ -206,3 +209,24 @@ static inline char *find_kallsyms_symbol(struct module *mod, unsigned long addr,
 	return NULL;
 }
 #endif /* CONFIG_KALLSYMS */
+
+#ifdef CONFIG_SYSFS
+int mod_sysfs_setup(struct module *mod, const struct load_info *info,
+			   struct kernel_param *kparam, unsigned int num_params);
+void mod_sysfs_fini(struct module *mod);
+void module_remove_modinfo_attrs(struct module *mod, int end);
+void del_usage_links(struct module *mod);
+void init_param_lock(struct module *mod);
+#else /* !CONFIG_SYSFS */
+static int mod_sysfs_setup(struct module *mod,
+			   const struct load_info *info,
+			   struct kernel_param *kparam,
+			   unsigned int num_params)
+{
+	return 0;
+}
+static inline void mod_sysfs_fini(struct module *mod) { }
+static inline void module_remove_modinfo_attrs(struct module *mod, int end) { }
+static inline void del_usage_links(struct module *mod) { }
+static inline void init_param_lock(struct module *mod) { }
+#endif /* CONFIG_SYSFS */
kernel/module/main.c +3 -455

483 lines not on this page · raw message

kernel/module/sysfs.c new file +425 -0

425 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 12/13 module: Move kdb_modules list out of core code

No functional change.

This patch migrates kdb_modules list to core kdb code since the list of added/or loaded modules is no longer private.

---
 kernel/debug/kdb/kdb_main.c | 5 +++++
 kernel/module/internal.h    | 1 +
 kernel/module/main.c        | 4 ----
 3 files changed, 6 insertions(+), 4 deletions(-)
kernel/debug/kdb/kdb_main.c +5 -0
index 0852a537dad4..f101f5f078f4 100644
@@ -59,6 +59,11 @@ EXPORT_SYMBOL(kdb_grepping_flag);
 int kdb_grep_leading;
 int kdb_grep_trailing;
 
+#ifdef CONFIG_MODULES
+extern struct list_head modules;
+struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */
+#endif /* CONFIG_MODULES */
+
 /*
  * Kernel debugger state flags
  */
kernel/module/internal.h +1 -0
index 52d30bf6d6b0..c49b4900b30b 100644
@@ -225,6 +225,7 @@ static int mod_sysfs_setup(struct module *mod,
 {
 	return 0;
 }
+
 static inline void mod_sysfs_fini(struct module *mod) { }
 static inline void module_remove_modinfo_attrs(struct module *mod, int end) { }
 static inline void del_usage_links(struct module *mod) { }
kernel/module/main.c +0 -4
index c2255954b7df..519c5335f7a6 100644
@@ -105,10 +105,6 @@ static void mod_update_bounds(struct module *mod)
 		__mod_update_bounds(mod->init_layout.base, mod->init_layout.size);
 }
 
-#ifdef CONFIG_KGDB_KDB
-struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */
-#endif /* CONFIG_KGDB_KDB */
-
 static void module_assert_mutex_or_preempt(void)
 {
 #ifdef CONFIG_LOCKDEP
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 12/13] module: Move kdb_modules list out of core code

Le 09/02/2022 à 18:11, Aaron Tomlin a écrit :

Quoted 18 lines

No functional change.

This patch migrates kdb_modules list to core kdb code since the list of added/or loaded modules is no longer private.

---
  kernel/debug/kdb/kdb_main.c | 5 +++++
  kernel/module/internal.h    | 1 +
  kernel/module/main.c        | 4 ----
  3 files changed, 6 insertions(+), 4 deletions(-)
kernel/debug/kdb/kdb_main.c +0 -0
index 0852a537dad4..f101f5f078f4 100644

kernel/debug/kdb/kdb_main.c EXPORT_SYMBOL(kdb_grepping_flag); · line 63

Quoted 5 lines
kernel/debug/kdb/kdb_main.c +2 -0
@@ -59,6 +59,11 @@ EXPORT_SYMBOL(kdb_grepping_flag);
  int kdb_grep_leading;
  int kdb_grep_trailing;
 
+#ifdef CONFIG_MODULES
+extern struct list_head modules;

Should go in module.h

kernel/debug/kdb/kdb_main.c EXPORT_SYMBOL(kdb_grepping_flag); · line 64

Quoted 1 line
kernel/debug/kdb/kdb_main.c +1 -0
+struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */

Should be static and should be removed from kernel/debug/kdb/kdb_private.h

Quoted 10 lines
kernel/debug/kdb/kdb_main.c +2 -0
+#endif /* CONFIG_MODULES */
+
  /*
   * Kernel debugger state flags
   */
kernel/module/internal.h +0 -0
index 52d30bf6d6b0..c49b4900b30b 100644

kernel/module/internal.h static int mod_sysfs_setup(struct module *mod, · line 228

Quoted 4 lines
kernel/module/internal.h +1 -0
@@ -225,6 +225,7 @@ static int mod_sysfs_setup(struct module *mod,
  {
  	return 0;
  }
+

This should go in previous patch if needed (patch 11 sysfs)

Quoted 18 lines
kernel/module/internal.h +0 -0
  static inline void mod_sysfs_fini(struct module *mod) { }
  static inline void module_remove_modinfo_attrs(struct module *mod, int end) { }
  static inline void del_usage_links(struct module *mod) { }
kernel/module/main.c +0 -4
index c2255954b7df..519c5335f7a6 100644
@@ -105,10 +105,6 @@ static void mod_update_bounds(struct module *mod)
  		__mod_update_bounds(mod->init_layout.base, mod->init_layout.size);
  }
 
-#ifdef CONFIG_KGDB_KDB
-struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */
-#endif /* CONFIG_KGDB_KDB */
-
  static void module_assert_mutex_or_preempt(void)
  {
  #ifdef CONFIG_LOCKDEP
#3 lore raw

Re: [PATCH v5 12/13] module: Move kdb_modules list out of core code

Quoted 8 lines · Christophe Leroy
Quoted 8 lines
kernel/debug/kdb/kdb_main.c +0 -0
index 0852a537dad4..f101f5f078f4 100644
@@ -59,6 +59,11 @@ EXPORT_SYMBOL(kdb_grepping_flag);
  int kdb_grep_leading;
  int kdb_grep_trailing;
 
Quoted 4 lines

kernel/debug/kdb/kdb_main.c EXPORT_SYMBOL(kdb_grepping_flag); · line 63

Quoted 2 lines
kernel/debug/kdb/kdb_main.c +2 -0
+#ifdef CONFIG_MODULES
+extern struct list_head modules;

Should go in module.h

I disagree. Let's keep it restricted somewhat. The list of loaded/or added modules is not widely used.

Quoted 3 lines

kernel/debug/kdb/kdb_main.c EXPORT_SYMBOL(kdb_grepping_flag); · line 64

Quoted 1 line
kernel/debug/kdb/kdb_main.c +1 -0
+struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */

Should be static and should be removed from kernel/debug/kdb/kdb_private.h

Agreed. It is only used in kernel/debug/kdb/kdb_main.c.

Quoted 11 lines

kernel/module/internal.h static int mod_sysfs_setup(struct module *mod, · line 228

Quoted 9 lines
kernel/module/internal.h +1 -0
index 52d30bf6d6b0..c49b4900b30b 100644
@@ -225,6 +225,7 @@ static int mod_sysfs_setup(struct module *mod,
  {
      return 0;
  }
+

This should go in previous patch if needed (patch 11 sysfs)

Agreed.

Kind regards,

Signature · 1 line
Aaron Tomlin
#4 lore raw

PATCH v5 13/13 module: Move version support into a separate file

In reply to Aaron Tomlin

No functional change.

This patch migrates module version support out of core code into kernel/module/version.c. In addition simple code refactoring to make this possible.

---
 kernel/module/Makefile   |   1 +
 kernel/module/internal.h |  50 +++++++++++++
 kernel/module/main.c     | 150 +--------------------------------------
 kernel/module/version.c  | 110 ++++++++++++++++++++++++++++
 4 files changed, 163 insertions(+), 148 deletions(-)
 create mode 100644 kernel/module/version.c
kernel/module/Makefile +1 -0
index c30141c37eb3..1f111aa47e88 100644
@@ -15,4 +15,5 @@ obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o
 obj-$(CONFIG_KALLSYMS) += kallsyms.o
 obj-$(CONFIG_PROC_FS) += procfs.o
 obj-$(CONFIG_SYSFS) += sysfs.o
+obj-$(CONFIG_MODVERSIONS) += version.o
 endif
kernel/module/internal.h +50 -0

60 lines not on this page · raw message

kernel/module/main.c +2 -148

177 lines not on this page · raw message

kernel/module/version.c new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v5 13/13] module: Move version support into a separate file

Le 09/02/2022 à 18:11, Aaron Tomlin a écrit :

Quoted 6 lines

No functional change.

This patch migrates module version support out of core code into kernel/module/version.c. In addition simple code refactoring to make this possible.

Quoted 8 lines
---
  kernel/module/Makefile   |   1 +
  kernel/module/internal.h |  50 +++++++++++++
  kernel/module/main.c     | 150 +--------------------------------------
  kernel/module/version.c  | 110 ++++++++++++++++++++++++++++
  4 files changed, 163 insertions(+), 148 deletions(-)

create mode 100644 kernel/module/version.c

Sparse reports:

CHECK kernel/module/version.c
kernel/module/version.c:103:6: warning: symbol 'module_layout' was not declared. Should it be static?

Checkpatch:

total: 0 errors, 2 warnings, 3 checks, 337 lines checked

Note that everywhere you get a warning for alignment not matching open parenthesis, first action should be to check if we really need it to be on two lines. When it's shorted than 100 chars it is usually better to keep it on a single line.

Quoted 17 lines
kernel/module/Makefile +1 -0
index c30141c37eb3..1f111aa47e88 100644
@@ -15,4 +15,5 @@ obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o
  obj-$(CONFIG_KALLSYMS) += kallsyms.o
  obj-$(CONFIG_PROC_FS) += procfs.o
  obj-$(CONFIG_SYSFS) += sysfs.o
+obj-$(CONFIG_MODVERSIONS) += version.o
  endif
kernel/module/internal.h +0 -0
index c49b4900b30b..475a66aa42f2 100644
@@ -71,7 +71,31 @@ struct load_info {
  	} index;

kernel/module/internal.h struct load_info { · line 81

Quoted 10 lines
kernel/module/internal.h +8 -0
  };
 
+struct symsearch {
+	const struct kernel_symbol *start, *stop;
+	const s32 *crcs;
+	enum mod_license {
+		NOT_GPL_ONLY,
+		GPL_ONLY,
+	} license;
+};

Why don't leave this in main.c ?

Quoted 115 lines
kernel/module/internal.h +42 -0
+
+struct find_symbol_arg {
+	/* Input */
+	const char *name;
+	bool gplok;
+	bool warn;
+
+	/* Output */
+	struct module *owner;
+	const s32 *crc;
+	const struct kernel_symbol *sym;
+	enum mod_license license;
+};
+
  int mod_verify_sig(const void *mod, struct load_info *info);
+int try_to_force_load(struct module *mod, const char *reason);
+bool find_symbol(struct find_symbol_arg *fsa);
  struct module *find_module_all(const char *name, size_t len, bool even_unformed);
  unsigned long kernel_symbol_value(const struct kernel_symbol *sym);
  int cmp_name(const void *name, const void *sym);
@@ -231,3 +255,29 @@ static inline void module_remove_modinfo_attrs(struct module *mod, int end) { }
  static inline void del_usage_links(struct module *mod) { }
  static inline void init_param_lock(struct module *mod) { }
  #endif /* CONFIG_SYSFS */
+
+#ifdef CONFIG_MODVERSIONS
+int check_version(const struct load_info *info,
+		  const char *symname, struct module *mod, const s32 *crc);
+int check_modstruct_version(const struct load_info *info, struct module *mod);
+int same_magic(const char *amagic, const char *bmagic, bool has_crcs);
+#else /* !CONFIG_MODVERSIONS */
+static inline int check_version(const struct load_info *info,
+				const char *symname,
+				struct module *mod,
+				const s32 *crc)
+{
+	return 1;
+}
+
+static inline int check_modstruct_version(const struct load_info *info,
+					  struct module *mod)
+{
+	return 1;
+}
+
+static inline int same_magic(const char *amagic, const char *bmagic, bool has_crcs)
+{
+	return strcmp(amagic, bmagic) == 0;
+}
+#endif /* CONFIG_MODVERSIONS */
kernel/module/version.c new file +58 -0
new file mode 100644
index 000000000000..10a1490d1b9e
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Module version support
+ *
+ * Copyright (C) 2008 Rusty Russell
+ */
+
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/printk.h>
+#include "internal.h"
+
+static u32 resolve_rel_crc(const s32 *crc)
+{
+	return *(u32 *)((void *)crc + *crc);
+}
+
+int check_version(const struct load_info *info,
+			 const char *symname,
+			 struct module *mod,
+			 const s32 *crc)
+{
+	Elf_Shdr *sechdrs = info->sechdrs;
+	unsigned int versindex = info->index.vers;
+	unsigned int i, num_versions;
+	struct modversion_info *versions;
+
+	/* Exporting module didn't supply crcs?  OK, we're already tainted. */
+	if (!crc)
+		return 1;
+
+	/* No versions at all?  modprobe --force does this. */
+	if (versindex == 0)
+		return try_to_force_load(mod, symname) == 0;
+
+	versions = (void *) sechdrs[versindex].sh_addr;
+	num_versions = sechdrs[versindex].sh_size
+		/ sizeof(struct modversion_info);
+
+	for (i = 0; i < num_versions; i++) {
+		u32 crcval;
+
+		if (strcmp(versions[i].name, symname) != 0)
+			continue;
+
+		if (IS_ENABLED(CONFIG_MODULE_REL_CRCS))
+			crcval = resolve_rel_crc(crc);
+		else
+			crcval = *crc;
+		if (versions[i].crc == crcval)
+			return 1;
+		pr_debug("Found checksum %X vs module %lX\n",
+			 crcval, versions[i].crc);
+		goto bad_version;
+	}
+
+	/* Broken toolchain. Warn once, then let it go.. */
+	pr_warn_once("%s: no symbol version for %s\n", info->name, symname);

kernel/module/version.c line 68

Quoted 10 lines
kernel/module/version.c new file +10 -0
+	return 1;
+
+bad_version:
+	pr_warn("%s: disagrees about version of symbol %s\n",
+	       info->name, symname);
+	return 0;
+}
+
+inline int check_modstruct_version(const struct load_info *info,
+					  struct module *mod)

inline is pointless for a non static function

Quoted 12 lines
kernel/module/version.c new file +12 -0
+{
+	struct find_symbol_arg fsa = {
+		.name	= "module_layout",
+		.gplok	= true,
+	};
+
+	/*
+	 * Since this should be found in kernel (which can't be removed), no
+	 * locking is necessary -- use preempt_disable() to placate lockdep.
+	 */
+	preempt_disable();
+	if (!find_symbol(&fsa)) {

kernel/module/version.c line 90

Quoted 10 lines
kernel/module/version.c new file +10 -0
+		preempt_enable();
+		BUG();
+	}
+	preempt_enable();
+	return check_version(info, "module_layout", mod, fsa.crc);
+}
+
+/* First part is kernel version, which we ignore if module has crcs. */
+inline int same_magic(const char *amagic, const char *bmagic,
+			     bool has_crcs)

Same, not point for inline keyword here.

Quoted 20 lines
kernel/module/version.c new file +20 -0
+{
+	if (has_crcs) {
+		amagic += strcspn(amagic, " ");
+		bmagic += strcspn(bmagic, " ");
+	}
+	return strcmp(amagic, bmagic) == 0;
+}
+
+/*
+ * Generate the signature for all relevant module structures here.
+ * If these change, we don't want to try to parse the module.
+ */
+void module_layout(struct module *mod,
+		   struct modversion_info *ver,
+		   struct kernel_param *kp,
+		   struct kernel_symbol *ks,
+		   struct tracepoint * const *tp)
+{
+}
+EXPORT_SYMBOL(module_layout);
#6 lore raw

Re: [PATCH v5 13/13] module: Move version support into a separate file

Quoted 18 lines · Christophe Leroy
Quoted 6 lines · Aaron Tomlin

No functional change.

This patch migrates module version support out of core code into kernel/module/version.c. In addition simple code refactoring to make this possible.

Quoted 8 lines
---
  kernel/module/Makefile   |   1 +
  kernel/module/internal.h |  50 +++++++++++++
  kernel/module/main.c     | 150 +--------------------------------------
  kernel/module/version.c  | 110 ++++++++++++++++++++++++++++
  4 files changed, 163 insertions(+), 148 deletions(-)

create mode 100644 kernel/module/version.c

Quoted 5 lines

Sparse reports:

CHECK kernel/module/version.c
kernel/module/version.c:103:6: warning: symbol 'module_layout' was not declared. Should it be static?

The function module_layout() does not appear to be used. So, I've decided to remove it.

Quoted 3 lines

Checkpatch:

total: 0 errors, 2 warnings, 3 checks, 337 lines checked

Ok.

Quoted 10 lines

kernel/module/internal.h struct load_info { · line 81

Quoted 8 lines
kernel/module/internal.h +8 -0
+struct symsearch {
+    const struct kernel_symbol *start, *stop;
+    const s32 *crcs;
+    enum mod_license {
+        NOT_GPL_ONLY,
+        GPL_ONLY,
+    } license;
+};

Why don't leave this in main.c ?

Yes, struct 'symsearch' is not used outside of kernel/module/main.c.

Quoted 4 lines

kernel/module/version.c line 68

Quoted 2 lines
kernel/module/version.c new file +2 -0
+inline int check_modstruct_version(const struct load_info *info,
+                      struct module *mod)

inline is pointless for a non static function

This was an unfortunate oversight.

Quoted 4 lines

kernel/module/version.c line 90

Quoted 2 lines
kernel/module/version.c new file +2 -0
+inline int same_magic(const char *amagic, const char *bmagic,
+                 bool has_crcs)

Same, not point for inline keyword here.

Agreed.

Kind regards,

Signature · 1 line
Aaron Tomlin
#7 lore raw

Re: [PATCH v5 13/13] module: Move version support into a separate file

Le 13/02/2022 à 19:03, Aaron Tomlin a écrit :

Quoted 19 lines · Christophe Leroy
Quoted 18 lines · Aaron Tomlin
Quoted 14 lines

No functional change.

This patch migrates module version support out of core code into kernel/module/version.c. In addition simple code refactoring to make this possible.

---
   kernel/module/Makefile   |   1 +
   kernel/module/internal.h |  50 +++++++++++++
   kernel/module/main.c     | 150 +--------------------------------------
   kernel/module/version.c  | 110 ++++++++++++++++++++++++++++
   4 files changed, 163 insertions(+), 148 deletions(-)

create mode 100644 kernel/module/version.c

Quoted 8 lines
Quoted 5 lines

Sparse reports:

CHECK kernel/module/version.c
kernel/module/version.c:103:6: warning: symbol 'module_layout' was not declared. Should it be static?

The function module_layout() does not appear to be used. So, I've decided to remove it.

I'm not sure you can do that.

From commit 8c8ef42aee8f ("module: include other structures in module
version check") I understand that module_layout is there for some signature.

Quoted 37 lines
Quoted 4 lines

Checkpatch:

total: 0 errors, 2 warnings, 3 checks, 337 lines checked

Ok.

Quoted 10 lines

kernel/module/internal.h struct load_info { · line 81

Quoted 8 lines
kernel/module/internal.h +8 -0
+struct symsearch {
+    const struct kernel_symbol *start, *stop;
+    const s32 *crcs;
+    enum mod_license {
+        NOT_GPL_ONLY,
+        GPL_ONLY,
+    } license;
+};

Why don't leave this in main.c ?

Yes, struct 'symsearch' is not used outside of kernel/module/main.c.

Quoted 4 lines

kernel/module/version.c line 68

Quoted 2 lines
kernel/module/version.c new file +2 -0
+inline int check_modstruct_version(const struct load_info *info,
+                      struct module *mod)

inline is pointless for a non static function

This was an unfortunate oversight.

Quoted 4 lines

kernel/module/version.c line 90

Quoted 2 lines
kernel/module/version.c new file +2 -0
+inline int same_magic(const char *amagic, const char *bmagic,
+                 bool has_crcs)

Same, not point for inline keyword here.

Agreed.

Kind regards,

reviewer
#8 lore raw

Re: [PATCH v5 13/13] module: Move version support into a separate file

Quoted 4 lines · Christophe Leroy

I'm not sure you can do that.

From commit 8c8ef42aee8f ("module: include other structures in module
version check") I understand that module_layout is there for some signature.

Hi Christophe,

I see. In which case, if I understand correctly, we'd have to ignore the report from Sparse. I will add a comment to hopefully suggest against removal.

Kind regards,

Signature · 1 line
Aaron Tomlin
#9 lore raw

Re: [PATCH v5 13/13] module: Move version support into a separate file

Le 15/02/2022 à 16:05, Aaron Tomlin a écrit :

Quoted 13 lines · Christophe Leroy
Quoted 4 lines

I'm not sure you can do that.

From commit 8c8ef42aee8f ("module: include other structures in module
version check") I understand that module_layout is there for some signature.

Hi Christophe,

I see. In which case, if I understand correctly, we'd have to ignore the report from Sparse. I will add a comment to hopefully suggest against removal.

I would add the function's prototype in internal.h to shut up sparse.

Christophe

maintainer
#10 lore raw

Re: [PATCH v5 13/13] module: Move version support into a separate file

In reply to Aaron Tomlin
Quoted 11 lines
Quoted 10 lines

kernel/module/internal.h struct load_info { · line 81

Quoted 8 lines
kernel/module/internal.h +8 -0
+struct symsearch {
+    const struct kernel_symbol *start, *stop;
+    const s32 *crcs;
+    enum mod_license {
+        NOT_GPL_ONLY,
+        GPL_ONLY,
+    } license;
+};

Why don't leave this in main.c ?

Quoted 1 line

Yes, struct 'symsearch' is not used outside of kernel/module/main.c.

It is not, but "struct find_symbol_arg", which you moved, uses "enum mod_license" defined above, so you can either leave it as it is, or carve "enum mod_license" definition out.

Miroslav

#11 lore raw

Re: [PATCH v5 13/13] module: Move version support into a separate file

Quoted 3 lines · Miroslav Benes

It is not, but "struct find_symbol_arg", which you moved, uses "enum mod_license" defined above, so you can either leave it as it is, or carve "enum mod_license" definition out.

Hi Miroslav,

I've done this already for v6. I hope to share the latest version for review shortly.

Kind regards,

Signature · 1 line
Aaron Tomlin
#12 lore raw
In reply to Aaron Tomlin

Le 09/02/2022 à 18:11, Aaron Tomlin a écrit :

Quoted 6 lines

No functional change.

This patch migrates module sysfs support out of core code into kernel/module/sysfs.c. In addition simple code refactoring to make this possible.

Quoted 8 lines
---
  kernel/module/Makefile   |   1 +
  kernel/module/internal.h |  24 ++
  kernel/module/main.c     | 458 +--------------------------------------
  kernel/module/sysfs.c    | 425 ++++++++++++++++++++++++++++++++++++
  4 files changed, 453 insertions(+), 455 deletions(-)

create mode 100644 kernel/module/sysfs.c

Checkpatch:

total: 0 errors, 2 warnings, 10 checks, 946 lines checked

Quoted 16 lines
kernel/module/Makefile +1 -0
index c6be08060252..c30141c37eb3 100644
@@ -14,4 +14,5 @@ obj-$(CONFIG_STRICT_MODULE_RWX) += strict_rwx.o
  obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o
  obj-$(CONFIG_KALLSYMS) += kallsyms.o
  obj-$(CONFIG_PROC_FS) += procfs.o
+obj-$(CONFIG_SYSFS) += sysfs.o
  endif
kernel/module/internal.h +0 -0
index b67ce836746a..52d30bf6d6b0 100644

kernel/module/internal.h line 39

Quoted 5 lines
kernel/module/internal.h +2 -0
@@ -35,6 +35,9 @@
  extern struct mutex module_mutex;
  extern struct list_head modules;
 
+extern struct module_attribute *modinfo_attrs[];
+extern size_t modinfo_attrs_count;

Can't this come in sysfs.c as well ?

Quoted 6 lines
kernel/module/internal.h +1 -0
+
  /* Provided by the linker */
  extern const struct kernel_symbol __start___ksymtab[];
  extern const struct kernel_symbol __stop___ksymtab[];
@@ -206,3 +209,24 @@ static inline char *find_kallsyms_symbol(struct module *mod, unsigned long addr,
  	return NULL;

kernel/module/internal.h static inline char *find_kallsyms_symbol(struct module *mod, unsigned long addr, · line 219

Quoted 10 lines
kernel/module/internal.h +8 -0
  }
  #endif /* CONFIG_KALLSYMS */
+
+#ifdef CONFIG_SYSFS
+int mod_sysfs_setup(struct module *mod, const struct load_info *info,
+			   struct kernel_param *kparam, unsigned int num_params);
+void mod_sysfs_fini(struct module *mod);
+void module_remove_modinfo_attrs(struct module *mod, int end);
+void del_usage_links(struct module *mod);
+void init_param_lock(struct module *mod);

Why don't we move mod_sysfs_teardown() here as well ?

It looks strange to move mod_sysfs_setup() and not mod_sysfs_teardown()

Quoted 13 lines
kernel/module/internal.h +13 -0
+#else /* !CONFIG_SYSFS */
+static int mod_sysfs_setup(struct module *mod,
+			   const struct load_info *info,
+			   struct kernel_param *kparam,
+			   unsigned int num_params)
+{
+	return 0;
+}
+static inline void mod_sysfs_fini(struct module *mod) { }
+static inline void module_remove_modinfo_attrs(struct module *mod, int end) { }
+static inline void del_usage_links(struct module *mod) { }
+static inline void init_param_lock(struct module *mod) { }
+#endif /* CONFIG_SYSFS */
#13 lore raw
Quoted 3 lines · Christophe Leroy

Checkpatch:

total: 0 errors, 2 warnings, 10 checks, 946 lines checked

Ok.

Quoted 8 lines
Quoted 8 lines
kernel/module/internal.h +0 -0
index b67ce836746a..52d30bf6d6b0 100644
@@ -35,6 +35,9 @@
  extern struct mutex module_mutex;
  extern struct list_head modules;
 
Quoted 4 lines

kernel/module/internal.h line 39

Quoted 2 lines
kernel/module/internal.h +2 -0
+extern struct module_attribute *modinfo_attrs[];
+extern size_t modinfo_attrs_count;

Can't this come in sysfs.c as well ?

No.

Quoted 9 lines

kernel/module/internal.h static inline char *find_kallsyms_symbol(struct module *mod, unsigned long addr, · line 219

Quoted 7 lines
kernel/module/internal.h +7 -0
+#ifdef CONFIG_SYSFS
+int mod_sysfs_setup(struct module *mod, const struct load_info *info,
+               struct kernel_param *kparam, unsigned int num_params);
+void mod_sysfs_fini(struct module *mod);
+void module_remove_modinfo_attrs(struct module *mod, int end);
+void del_usage_links(struct module *mod);
+void init_param_lock(struct module *mod);

Why don't we move mod_sysfs_teardown() here as well ?

Agreed.

Kind regards,

Signature · 1 line
Aaron Tomlin