Skip to contentSkip to conversation

module: remove MODULE_VERSION() and srcversion

PATCH In review Greg Kroah-Hartman 4 participants 9 messages Jul 31 – Aug 4

Subsystems (8)
DRM drivers x86 Block layer Kbuild +4 more subsystems
lore
Share & tools
lore
#0 lore raw

v2 cover module: remove MODULE_VERSION() and srcversion

Module "versions" do not make sense as the kernel is built all at once, the "version" is the overall kernel version number, so modules can not really be described as having a unique version given that they rely on the infrastructure of the whole kernel.

So remove the version and the srcversion fields as there is no need for them anymore.

Note, for now, MODULE_VERSION() is just an "empty" define, to keep existing code building properly as the tree is slowly purged of the use of this over time. This macro will be removed entirely in the future when there are no in-tree users.

---
Changes in v2:
- remove version from struct module and the sysfs file
- amd driver THIS_MODULE->version logic removal as it's pointless.
- add second patch in series to remove srcversion
- Link to v1: https://lore.kernel.org/r/2026031341-evolve-repeater-987b@gregkh

---
Greg Kroah-Hartman (2):
module: remove MODULE_VERSION()
module: remove srcversion module attribute

 Documentation/ABI/stable/sysfs-module    | 12 -------
 arch/x86/tools/relocs.c                  |  1 -
 drivers/block/drbd/drbd_buildtag.c       |  7 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  7 +---
 include/asm-generic/vmlinux.lds.h        |  5 ---
 include/linux/module.h                   | 58 ++++++--------------------------
 kernel/module/Kconfig                    | 11 ------
 kernel/module/main.c                     | 32 ------------------
 kernel/params.c                          | 30 -----------------
 scripts/Makefile.modpost                 |  1 -
 scripts/mod/modpost.c                    | 24 -------------
 scripts/mod/modpost.h                    |  1 -
 12 files changed, 13 insertions(+), 176 deletions(-)

---
base-commit: 8ba098e6b6ff0db8edf28528d1552be261af30d4
change-id: 20260731-module_ver_remove-fd505b32b111

Best regards,

Signature · 1 line
Greg Kroah-Hartman <[email protected]>
#1 lore raw

PATCH v2 1/2 module: remove MODULE_VERSION()

Module "versions" do not make sense as the kernel is built all at once, the "version" is the overall kernel version number, so modules can not really be described as having a unique version given that they rely on the infrastructure of the whole kernel.

For now, just make this an "empty" define, to keep existing code building properly as the tree is slowly purged of the use of this over time.

This macro will be removed entirely in the future when there are no in-tree users.

Cc Luis Chamberlain <[email protected]>
Cc Petr Pavlu <[email protected]>
Cc Daniel Gomez <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Aaron Tomlin <[email protected]>
Cc Shyam Saini <[email protected]>
Cc Kees Cook <[email protected]>
Cc Thorsten Blum <[email protected]>
---
 Documentation/ABI/stable/sysfs-module    |  6 ----
 arch/x86/tools/relocs.c                  |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  7 +---
 include/asm-generic/vmlinux.lds.h        |  5 ---
 include/linux/module.h                   | 57 ++++++--------------------------
 kernel/module/main.c                     |  2 --
 kernel/params.c                          | 30 -----------------
 7 files changed, 12 insertions(+), 96 deletions(-)
Documentation/ABI/stable/sysfs-module +0 -6
index 41b1f16e8795..7a3cdd8a8d9f 100644
@@ -39,9 +39,3 @@ Date:		Jun 2005
 Description:
 		If the module source has MODULE_VERSION, this file will contain
 		the checksum of the source code.
-
-What:		/sys/module/<MODULENAME>/version
-Date:		Jun 2005
-Description:
-		If the module source has MODULE_VERSION, this file will contain
-		the version of the source code.
arch/x86/tools/relocs.c +0 -1
index e5a2b9a912d1..1426ddcb3a89 100644
@@ -81,7 +81,6 @@ static const char * const	sym_regex_kernel[S_NSYMTYPES] = {
 	"__(start|stop)___ksymtab(_gpl)?|"
 	"__(start|stop)___kcrctab(_gpl)?|"
 	"__(start|stop)___param|"
-	"__(start|stop)___modver|"
 	"__(start|stop)___bug_table|"
 	"__tracedata_(start|end)|"
 	"__(start|stop)_notes|"
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -6
index 9e8f7d2b898c..a1ca1bc27f93 100644
@@ -677,12 +677,7 @@ static int amdgpu_virt_write_vf2pf_data(struct amdgpu_device *adev)
 	vf2pf_info->header.size = sizeof(struct amd_sriov_msg_vf2pf_info);
 	vf2pf_info->header.version = AMD_SRIOV_MSG_FW_VRAM_VF2PF_VER;
 
-#ifdef MODULE
-	if (THIS_MODULE->version != NULL)
-		strscpy(vf2pf_info->driver_version, THIS_MODULE->version);
-	else
-#endif
-		strscpy(vf2pf_info->driver_version, "N/A");
+	strscpy(vf2pf_info->driver_version, "N/A");
 
 	vf2pf_info->pf2vf_version_required = 0; // no requirement, guest understands all
 	vf2pf_info->driver_cert = 0;
include/asm-generic/vmlinux.lds.h +0 -5
index 5659f4b5a125..80bc90ec9ee1 100644
@@ -544,11 +544,6 @@
 		BOUNDED_SECTION_BY(__param, ___param)			\
 	}								\
 									\
-	/* Built-in module versions. */					\
-	__modver : AT(ADDR(__modver) - LOAD_OFFSET) {			\
-		BOUNDED_SECTION_BY(__modver, ___modver)			\
-	}								\
-									\
 	KCFI_TRAPS							\
 									\
 	RO_EXCEPTION_TABLE						\
include/linux/module.h +11 -46

76 lines not on this page · raw message

kernel/module/main.c +0 -2
index 46dd8d25a605..da8be9788d13 100644
@@ -602,7 +602,6 @@ static const struct module_attribute modinfo_##field = {              \
 	.free = free_modinfo_##field,                                 \
 };
 
-MODINFO_ATTR(version);
 MODINFO_ATTR(srcversion);
 
 static void setup_modinfo_import_ns(struct module *mod, const char *s)
@@ -1084,7 +1083,6 @@ static const struct module_attribute modinfo_taint =
 
 const struct module_attribute *const modinfo_attrs[] = {
 	&module_uevent,
-	&modinfo_version,
 	&modinfo_srcversion,
 	&modinfo_import_ns,
 	&modinfo_initstate,
kernel/params.c +0 -30
index a668863a4bb6..6c5a1eb22b25 100644
@@ -837,35 +837,6 @@ static void __init param_sysfs_builtin(void)
 	}
 }
 
-ssize_t __modver_version_show(const struct module_attribute *mattr,
-			      struct module_kobject *mk, char *buf)
-{
-	const struct module_version_attribute *vattr =
-		container_of_const(mattr, struct module_version_attribute, mattr);
-
-	return scnprintf(buf, PAGE_SIZE, "%s\n", vattr->version);
-}
-
-extern const struct module_version_attribute __start___modver[];
-extern const struct module_version_attribute __stop___modver[];
-
-static void __init version_sysfs_builtin(void)
-{
-	const struct module_version_attribute *vattr;
-	struct module_kobject *mk;
-	int err;
-
-	for (vattr = __start___modver; vattr < __stop___modver; vattr++) {
-		mk = lookup_or_create_module_kobject(vattr->module_name);
-		if (mk) {
-			err = sysfs_create_file(&mk->kobj, &vattr->mattr.attr);
-			WARN_ON_ONCE(err);
-			kobject_uevent(&mk->kobj, KOBJ_ADD);
-			kobject_put(&mk->kobj);
-		}
-	}
-}
-
 /* module-related sysfs stuff */
 
 static ssize_t module_attr_show(struct kobject *kobj,
@@ -968,7 +939,6 @@ static int __init param_sysfs_builtin_init(void)
 	if (!module_kset)
 		return -ENOMEM;
 
-	version_sysfs_builtin();
 	param_sysfs_builtin();
 
 	return 0;
Signature · 1 line
2.55.0
#5 lore raw

PATCH v2 2/2 module: remove srcversion module attribute

In reply to Greg Kroah-Hartman

Now that module versions are gone, there is no need for srcversion either. So drop the logic for this from both the kernel and the helper module tools.

Cc Luis Chamberlain <[email protected]>
Cc Petr Pavlu <[email protected]>
Cc Daniel Gomez <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Aaron Tomlin <[email protected]>
Cc Shyam Saini <[email protected]>
Cc Kees Cook <[email protected]>
Cc Thorsten Blum <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 Documentation/ABI/stable/sysfs-module |  6 ------
 drivers/block/drbd/drbd_buildtag.c    |  7 +------
 include/linux/module.h                |  1 -
 kernel/module/Kconfig                 | 11 -----------
 kernel/module/main.c                  | 30 ------------------------------
 scripts/Makefile.modpost              |  1 -
 scripts/mod/modpost.c                 | 24 ------------------------
 scripts/mod/modpost.h                 |  1 -
 8 files changed, 1 insertion(+), 80 deletions(-)
Documentation/ABI/stable/sysfs-module +0 -6
index 7a3cdd8a8d9f..5c028af9921a 100644
@@ -33,9 +33,3 @@ Description:
 		Note: If the module is built into the kernel, or if the
 		CONFIG_MODULE_UNLOAD kernel configuration value is not enabled,
 		this file will not be present.
-
-What:		/sys/module/<MODULENAME>/srcversion
-Date:		Jun 2005
-Description:
-		If the module source has MODULE_VERSION, this file will contain
-		the checksum of the source code.
drivers/block/drbd/drbd_buildtag.c +1 -6
index cd0389488f63..22f1e842f9ce 100644
@@ -10,13 +10,8 @@ const char *drbd_buildtag(void)
 
 	static char buildtag[38] = "\0uilt-in";
 
-	if (buildtag[0] == 0) {
-#ifdef MODULE
-		sprintf(buildtag, "srcversion: %-24s", THIS_MODULE->srcversion);
-#else
+	if (buildtag[0] == 0)
 		buildtag[0] = 'b';
-#endif
-	}
 
 	return buildtag;
 }
include/linux/module.h +0 -1
index 209b6a388be7..cafb99479966 100644
@@ -377,7 +377,6 @@ struct module {
 	/* Sysfs stuff. */
 	struct module_kobject mkobj;
 	struct module_attribute *modinfo_attrs;
-	const char *srcversion;
 	const char *imported_namespaces;
 	struct kobject *holders_dir;
 
kernel/module/Kconfig +0 -11
index 43b1bb01fd27..e27f12778e24 100644
@@ -238,17 +238,6 @@ config BASIC_MODVERSIONS
 
 endif # MODVERSIONS
 
-config MODULE_SRCVERSION_ALL
-	bool "Source checksum for all modules"
-	help
-	  Modules which contain a MODULE_VERSION get an extra "srcversion"
-	  field inserted into their modinfo section, which contains a
-	  sum of the source files which made it.  This helps maintainers
-	  see exactly which source was used to build a module (since
-	  others sometimes change the module source without updating
-	  the version).  With this option, such a "srcversion" field
-	  will be created for all modules.  If unsure, say N.
-
 config MODULE_SIG
 	bool "Module signature verification"
 	select MODULE_SIG_FORMAT
kernel/module/main.c +0 -30
index da8be9788d13..5f590ce90f2d 100644
@@ -575,35 +575,6 @@ bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
 
 #endif /* CONFIG_SMP */
 
-#define MODINFO_ATTR(field)	\
-static void setup_modinfo_##field(struct module *mod, const char *s)  \
-{                                                                     \
-	mod->field = kstrdup(s, GFP_KERNEL);                          \
-}                                                                     \
-static ssize_t show_modinfo_##field(const struct module_attribute *mattr, \
-			struct module_kobject *mk, char *buffer)      \
-{                                                                     \
-	return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field);  \
-}                                                                     \
-static int modinfo_##field##_exists(struct module *mod)               \
-{                                                                     \
-	return mod->field != NULL;                                    \
-}                                                                     \
-static void free_modinfo_##field(struct module *mod)                  \
-{                                                                     \
-	kfree(mod->field);                                            \
-	mod->field = NULL;                                            \
-}                                                                     \
-static const struct module_attribute modinfo_##field = {              \
-	.attr = { .name = __stringify(field), .mode = 0444 },         \
-	.show = show_modinfo_##field,                                 \
-	.setup = setup_modinfo_##field,                               \
-	.test = modinfo_##field##_exists,                             \
-	.free = free_modinfo_##field,                                 \
-};
-
-MODINFO_ATTR(srcversion);
-
 static void setup_modinfo_import_ns(struct module *mod, const char *s)
 {
 	mod->imported_namespaces = NULL;
@@ -1083,7 +1054,6 @@ static const struct module_attribute modinfo_taint =
 
 const struct module_attribute *const modinfo_attrs[] = {
 	&module_uevent,
-	&modinfo_srcversion,
 	&modinfo_import_ns,
 	&modinfo_initstate,
 	&modinfo_coresize,
scripts/Makefile.modpost +0 -1
index d7d45067d08b..b6c1467cf527 100644
@@ -45,7 +45,6 @@ modpost-args =										\
 	$(if $(CONFIG_MODVERSIONS),-m)							\
 	$(if $(CONFIG_BASIC_MODVERSIONS),-b)						\
 	$(if $(CONFIG_EXTENDED_MODVERSIONS),-x)						\
-	$(if $(CONFIG_MODULE_SRCVERSION_ALL),-a)					\
 	$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E)					\
 	$(if $(KBUILD_MODPOST_WARN),-w)							\
 	$(if $(KBUILD_NSDEPS),-d modules.nsdeps)					\
scripts/mod/modpost.c +0 -24
index a7b72a81d248..2e969be7f414 100644
@@ -33,8 +33,6 @@
 static bool module_enabled;
 /* Are we using CONFIG_MODVERSIONS? */
 static bool modversions;
-/* Is CONFIG_MODULE_SRCVERSION_ALL set? */
-static bool all_versions;
 /* Is CONFIG_BASIC_MODVERSIONS set? */
 static bool basic_modversions;
 /* Is CONFIG_EXTENDED_MODVERSIONS set? */
@@ -1584,7 +1582,6 @@ static void mod_set_crcs(struct module *mod)
 static void read_symbols(const char *modname)
 {
 	const char *symname;
-	char *version;
 	char *license;
 	char *namespace;
 	struct module *mod;
@@ -1645,13 +1642,6 @@ static void read_symbols(const char *modname)
 
 	check_sec_ref(mod, &info);
 
-	if (!mod->is_vmlinux) {
-		version = get_modinfo(&info, "version");
-		if (version || all_versions)
-			get_src_version(mod->name, mod->srcversion,
-					sizeof(mod->srcversion) - 1);
-	}
-
 	parse_elf_finish(&info);
 
 	if (modversions) {
@@ -2035,15 +2025,6 @@ static void add_depends(struct buffer *b, struct module *mod)
 	buf_printf(b, "\");\n");
 }
 
-static void add_srcversion(struct buffer *b, struct module *mod)
-{
-	if (mod->srcversion[0]) {
-		buf_printf(b, "\n");
-		buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
-			   mod->srcversion);
-	}
-}
-
 static void write_buf(struct buffer *b, const char *fname)
 {
 	FILE *file;
@@ -2149,8 +2130,6 @@ static void write_mod_c_file(struct module *mod)
 		free(alias);
 	}
 
-	add_srcversion(&buf, mod);
-
 	ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);
 	if (ret >= sizeof(fname)) {
 		error("%s: too long path was truncated\n", fname);
@@ -2327,9 +2306,6 @@ int main(int argc, char **argv)
 		case 'o':
 			dump_write = optarg;
 			break;
-		case 'a':
-			all_versions = true;
-			break;
 		case 'T':
 			files_source = optarg;
 			break;
scripts/mod/modpost.h +0 -1
index 2aecb8f25c87..2c2f1d2b4021 100644
@@ -126,7 +126,6 @@ struct module {
 	bool seen;
 	bool has_init;
 	bool has_cleanup;
-	char	     srcversion[25];
 	// Missing namespace dependencies
 	struct list_head missing_namespaces;
 	// Actual imported namespaces
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH v2 1/2] module: remove MODULE_VERSION()

In reply to Greg Kroah-Hartman
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] Immediate, unphased removal of the `/sys/module/*/version` sysfs ABI and `modinfo` version…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Immediate, unphased removal of the /sys/module/*/version sysfs ABI and modinfo version outputs. --

--- Patch [1]: [PATCH v2 1/2] module: remove MODULE_VERSION() --- commit b77f8591ff850600dbc1da5c9c2f45e06be183fe
Author: Greg Kroah-Hartman <[email protected]>

module: remove MODULE_VERSION()

This commit removes the MODULE_VERSION macro and its associated sysfs attributes. It redefines the macro to be empty to keep existing code building while it is phased out, as module versions do not make sense in a unified build.

Cc Luis Chamberlain <[email protected]>
Cc Petr Pavlu <[email protected]>
Cc Daniel Gomez <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Aaron Tomlin <[email protected]>
Cc Shyam Saini <[email protected]>
Cc Kees Cook <[email protected]>
Cc Thorsten Blum <[email protected]>

[ ... ]

Quoted 4 lines
include/linux/module.h +0 -0
index 7566815fabbe8..209b6a388be7c 100644

[ ... ]

Quoted 11 lines
include/linux/module.h +0 -11
-#if defined(MODULE) || !defined(CONFIG_SYSFS)
-#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
-#else
-#define MODULE_VERSION(_version)					\
-	MODULE_INFO(version, _version);					\
-	static const struct module_version_attribute __modver_attr	\
-		__used __section("__modver")				\
-		__aligned(__alignof__(struct module_version_attribute)) \
-		= {							\
-			.mattr	= {					\
-				.attr	= {				\

include/linux/module.h struct module_kobject *lookup_or_create_module_kobject(const char *name); · line 261

Quoted 10 lines
include/linux/module.h +1 -9
-					.name	= "version",		\
-					.mode	= S_IRUGO,		\
-				},					\
-				.show	= __modver_version_show,	\
-			},						\
-			.module_name	= KBUILD_MODNAME,		\
-			.version	= _version,			\
-		}
-#endif
+#define MODULE_VERSION(_version)

[Severity: Critical]
Does redefining this macro to empty immediately prevent the version tag from being embedded in the .modinfo section of all loadable modules? Could this cause a regression for userspace tools like modinfo that might rely on extracting this information?

[ ... ]

Quoted 4 lines
kernel/module/main.c +0 -0
index 46dd8d25a6058..da8be9788d130 100644

[ ... ]

kernel/module/main.c static const struct module_attribute modinfo_taint = · line 1087

Quoted 5 lines
kernel/module/main.c +0 -1
@@ -1084,7 +1083,6 @@ static const struct module_attribute modinfo_taint =
 
 const struct module_attribute *const modinfo_attrs[] = {
 	&module_uevent,
-	&modinfo_version,

[Severity: Critical]
By removing this attribute, does this immediately break the loadable module sysfs interface at /sys/module/module_name/version? Would it be safer to provide a backward-compatible stub or deprecation period before completely removing this stable ABI, to avoid regressions in userspace scripts?

Quoted 3 lines
kernel/module/main.c +0 -0
 	&modinfo_srcversion,
 	&modinfo_import_ns,
 	&modinfo_initstate,

[ ... ]

Quoted 4 lines
kernel/params.c +0 -0
index a668863a4bb63..6c5a1eb22b257 100644

[ ... ]

Quoted 17 lines
kernel/params.c +0 -17
-static void __init version_sysfs_builtin(void)
-{
-	const struct module_version_attribute *vattr;
-	struct module_kobject *mk;
-	int err;
-
-	for (vattr = __start___modver; vattr < __stop___modver; vattr++) {
-		mk = lookup_or_create_module_kobject(vattr->module_name);
-		if (mk) {
-			err = sysfs_create_file(&mk->kobj, &vattr->mattr.attr);
-			WARN_ON_ONCE(err);
-			kobject_uevent(&mk->kobj, KOBJ_ADD);
-			kobject_put(&mk->kobj);
-		}
-	}
-}
-

[ ... ]

kernel/params.c static int __init param_sysfs_builtin_init(void) · line 971

Quoted 5 lines
kernel/params.c +0 -1
@@ -968,7 +939,6 @@ static int __init param_sysfs_builtin_init(void)
 	if (!module_kset)
 		return -ENOMEM;
 
-	version_sysfs_builtin();

[Severity: Critical]
Does the removal of this function and its call immediately drop the sysfs version node for all built-in modules? Could this cause hardware inventory scripts or udev rules to fail with ENOENT when they expect the file to exist?

Quoted 3 lines
kernel/params.c +0 -0
 	param_sysfs_builtin();
 
 	return 0;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#6 lore raw

Re: [PATCH v2 2/2] module: remove srcversion module attribute

In reply to Greg Kroah-Hartman
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Low] Incomplete feature removal leaves `sumversion.c` as entirely dead code that is still compiled.…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Low] Incomplete feature removal leaves sumversion.c as entirely dead code that is still compiled.
- [Low] The -a command-line option was not removed from the getopt string, causing silent failures if passed.
- [Low] DRBD modules unconditionally report their version string as "built-in" even when dynamically loaded. --

--- Patch [2]: [PATCH v2 2/2] module: remove srcversion module attribute --- commit 461ecb5f73545c4d962415cbd1b5ef67b64b2f0a
Author: Greg Kroah-Hartman <[email protected]>

module: remove srcversion module attribute

This commit removes the srcversion module attribute from the kernel and the helper module tools. Since module versions are no longer used, the associated logic is dropped.

Quoted 9 lines
drivers/block/drbd/drbd_buildtag.c +0 -1
index cd0389488f63e..22f1e842f9ced 100644
@@ -10,13 +10,8 @@ const char *drbd_buildtag(void)
 
 	static char buildtag[38] = "\0uilt-in";
 
-	if (buildtag[0] == 0) {

drivers/block/drbd/drbd_buildtag.c const char *drbd_buildtag(void) · line 17

Quoted 10 lines
drivers/block/drbd/drbd_buildtag.c +1 -5
-#ifdef MODULE
-		sprintf(buildtag, "srcversion: %-24s", THIS_MODULE->srcversion);
-#else
+	if (buildtag[0] == 0)
 		buildtag[0] = 'b';
-#endif
-	}
 
 	return buildtag;
 }

[Severity: Low]
With the removal of the conditional logic in drbd_buildtag(), will this unconditionally report the DRBD module version string as "built-in" even when it is dynamically loaded?

[ ... ]

Quoted 4 lines
scripts/mod/modpost.c +0 -0
index a7b72a81d2482..2e969be7f414c 100644

[ ... ]

scripts/mod/modpost.c int main(int argc, char **argv) · line 2311

Quoted 10 lines
scripts/mod/modpost.c +0 -3
@@ -2327,9 +2306,6 @@ int main(int argc, char **argv)
 		case 'o':
 			dump_write = optarg;
 			break;
-		case 'a':
-			all_versions = true;
-			break;
 		case 'T':
 			files_source = optarg;
 			break;

[Severity: Low]
Should the 'a' flag also be removed from the getopt() option string earlier in main()?

scripts/mod/modpost.c:main() {
    ...
	while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:xb")) != -1) {
    ...
}

If the deprecated -a flag is passed to modpost, getopt considers it valid and returns 'a'. Since the switch statement no longer has a case for 'a', it falls through to the default case and silently calls exit(1) without emitting an invalid option error message.

[ ... ]

scripts/mod/modpost.h struct module { · line 131

Quoted 12 lines
scripts/mod/modpost.h +0 -1
index 2aecb8f25c87e..2c2f1d2b40211 100644
@@ -126,7 +126,6 @@ struct module {
 	bool seen;
 	bool has_init;
 	bool has_cleanup;
-	char	     srcversion[25];
 	// Missing namespace dependencies
 	struct list_head missing_namespaces;
 	// Actual imported namespaces

[Severity: Low]
Since the srcversion feature is being removed, should scripts/mod/sumversion.c also be deleted and removed from modpost-objs in scripts/mod/Makefile?

The file appears to be dead code now that its only entry point get_src_version() is never called, though the function declaration still remains further down in scripts/mod/modpost.h.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#3 lore raw

Re: [PATCH v2 1/2] module: remove MODULE_VERSION()

In reply to [email protected]
Quoted 2 lines · On Fri, Jul 31, 2026 at 01:18:54PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Immediate, unphased removal of the /sys/module/*/version sysfs ABI and modinfo version outputs.

Heh, that is intentional! :)

maintainer
#7 lore raw

Re: [PATCH v2 2/2] module: remove srcversion module attribute

In reply to Greg Kroah-Hartman
Quoted 3 lines · Greg Kroah-Hartman

Now that module versions are gone, there is no need for srcversion either. So drop the logic for this from both the kernel and the helper module tools.

This explanation seems somewhat misleading to me, given that MODULE_SRCVERSION_ALL exists. IMO the main motivation for removing srcversion should be that it has nowadays been replaced by build IDs.

I suggest something like the following:

"""
The srcversion modinfo field was primarily used to identify binaries. Nowadays, modules contain a build ID, which is the standard mechanism for this purpose. The information is exposed via /sys/module/<module>/notes/.note.gnu.build-id.

Drop the logic for srcversion from both the kernel and modpost. """

Lucas also recently added support for modinfo to print build IDs [1].

Quoted 45 lines
Cc Luis Chamberlain <[email protected]>
Cc Petr Pavlu <[email protected]>
Cc Daniel Gomez <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Aaron Tomlin <[email protected]>
Cc Shyam Saini <[email protected]>
Cc Kees Cook <[email protected]>
Cc Thorsten Blum <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 Documentation/ABI/stable/sysfs-module |  6 ------
 drivers/block/drbd/drbd_buildtag.c    |  7 +------
 include/linux/module.h                |  1 -
 kernel/module/Kconfig                 | 11 -----------
 kernel/module/main.c                  | 30 ------------------------------
 scripts/Makefile.modpost              |  1 -
 scripts/mod/modpost.c                 | 24 ------------------------
 scripts/mod/modpost.h                 |  1 -
 8 files changed, 1 insertion(+), 80 deletions(-)
Documentation/ABI/stable/sysfs-module +0 -6
index 7a3cdd8a8d9f..5c028af9921a 100644
@@ -33,9 +33,3 @@ Description:
 		Note: If the module is built into the kernel, or if the
 		CONFIG_MODULE_UNLOAD kernel configuration value is not enabled,
 		this file will not be present.
-
-What:		/sys/module/<MODULENAME>/srcversion
-Date:		Jun 2005
-Description:
-		If the module source has MODULE_VERSION, this file will contain
-		the checksum of the source code.
drivers/block/drbd/drbd_buildtag.c +0 -1
index cd0389488f63..22f1e842f9ce 100644
@@ -10,13 +10,8 @@ const char *drbd_buildtag(void)
 
 	static char buildtag[38] = "\0uilt-in";
 
-	if (buildtag[0] == 0) {

drivers/block/drbd/drbd_buildtag.c const char *drbd_buildtag(void) · line 17

Quoted 10 lines
drivers/block/drbd/drbd_buildtag.c +1 -5
-#ifdef MODULE
-		sprintf(buildtag, "srcversion: %-24s", THIS_MODULE->srcversion);
-#else
+	if (buildtag[0] == 0)
 		buildtag[0] = 'b';
-#endif
-	}
 
 	return buildtag;
 }

THIS_MODULE->srcversion could be replaced with module_buildid(THIS_MODULE). I'll leave it to the DRBD maintainers to decide what they prefer.

Quoted 21 lines
include/linux/module.h +0 -1
index 209b6a388be7..cafb99479966 100644
@@ -377,7 +377,6 @@ struct module {
 	/* Sysfs stuff. */
 	struct module_kobject mkobj;
 	struct module_attribute *modinfo_attrs;
-	const char *srcversion;
 	const char *imported_namespaces;
 	struct kobject *holders_dir;
 
kernel/module/Kconfig +0 -1
index 43b1bb01fd27..e27f12778e24 100644
@@ -238,17 +238,6 @@ config BASIC_MODVERSIONS
 
 endif # MODVERSIONS
 
-config MODULE_SRCVERSION_ALL

kernel/module/Kconfig config BASIC_MODVERSIONS · line 251

Quoted 10 lines
kernel/module/Kconfig +0 -10
-	bool "Source checksum for all modules"
-	help
-	  Modules which contain a MODULE_VERSION get an extra "srcversion"
-	  field inserted into their modinfo section, which contains a
-	  sum of the source files which made it.  This helps maintainers
-	  see exactly which source was used to build a module (since
-	  others sometimes change the module source without updating
-	  the version).  With this option, such a "srcversion" field
-	  will be created for all modules.  If unsure, say N.
-

Various default and test configs set MODULE_SRCVERSION_ALL=y, which should be removed.

linux> git grep CONFIG_MODULE_SRCVERSION_ALL arch/arm/configs/imx_v6_v7_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/arm/configs/omap2plus_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/arm/configs/pxa_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/bigsur_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/decstation_64_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/decstation_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/decstation_r4k_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/ip22_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/ip27_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/ip28_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/ip30_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/malta_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/malta_kvm_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/malta_qemu_32r6_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/maltaaprp_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/maltasmvp_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/maltasmvp_eva_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/maltaup_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/maltaup_xpa_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/mtx1_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/pic32mzda_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/mips/configs/sb1250_swarm_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/powerpc/configs/g5_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/powerpc/configs/powernv_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/powerpc/configs/ppc64_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/powerpc/configs/ppc64e_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/powerpc/configs/ppc6xx_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/powerpc/configs/tqm8xx_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/s390/configs/debug_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/s390/configs/defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/sh/configs/magicpanelr2_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y arch/sparc/configs/sparc64_defconfig:CONFIG_MODULE_SRCVERSION_ALL=y tools/testing/selftests/bpf/config:CONFIG_MODULE_SRCVERSION_ALL=y

Quoted 85 lines
kernel/module/Kconfig +0 -0
 config MODULE_SIG
 	bool "Module signature verification"
 	select MODULE_SIG_FORMAT
kernel/module/main.c +0 -30
index da8be9788d13..5f590ce90f2d 100644
@@ -575,35 +575,6 @@ bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
 
 #endif /* CONFIG_SMP */
 
-#define MODINFO_ATTR(field)	\
-static void setup_modinfo_##field(struct module *mod, const char *s)  \
-{                                                                     \
-	mod->field = kstrdup(s, GFP_KERNEL);                          \
-}                                                                     \
-static ssize_t show_modinfo_##field(const struct module_attribute *mattr, \
-			struct module_kobject *mk, char *buffer)      \
-{                                                                     \
-	return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field);  \
-}                                                                     \
-static int modinfo_##field##_exists(struct module *mod)               \
-{                                                                     \
-	return mod->field != NULL;                                    \
-}                                                                     \
-static void free_modinfo_##field(struct module *mod)                  \
-{                                                                     \
-	kfree(mod->field);                                            \
-	mod->field = NULL;                                            \
-}                                                                     \
-static const struct module_attribute modinfo_##field = {              \
-	.attr = { .name = __stringify(field), .mode = 0444 },         \
-	.show = show_modinfo_##field,                                 \
-	.setup = setup_modinfo_##field,                               \
-	.test = modinfo_##field##_exists,                             \
-	.free = free_modinfo_##field,                                 \
-};
-
-MODINFO_ATTR(srcversion);
-
 static void setup_modinfo_import_ns(struct module *mod, const char *s)
 {
 	mod->imported_namespaces = NULL;
@@ -1083,7 +1054,6 @@ static const struct module_attribute modinfo_taint =
 
 const struct module_attribute *const modinfo_attrs[] = {
 	&module_uevent,
-	&modinfo_srcversion,
 	&modinfo_import_ns,
 	&modinfo_initstate,
 	&modinfo_coresize,
scripts/Makefile.modpost +0 -1
index d7d45067d08b..b6c1467cf527 100644
@@ -45,7 +45,6 @@ modpost-args =										\
 	$(if $(CONFIG_MODVERSIONS),-m)							\
 	$(if $(CONFIG_BASIC_MODVERSIONS),-b)						\
 	$(if $(CONFIG_EXTENDED_MODVERSIONS),-x)						\
-	$(if $(CONFIG_MODULE_SRCVERSION_ALL),-a)					\
 	$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E)					\
 	$(if $(KBUILD_MODPOST_WARN),-w)							\
 	$(if $(KBUILD_NSDEPS),-d modules.nsdeps)					\
scripts/mod/modpost.c +0 -3
index a7b72a81d248..2e969be7f414 100644
@@ -33,8 +33,6 @@
 static bool module_enabled;
 /* Are we using CONFIG_MODVERSIONS? */
 static bool modversions;
-/* Is CONFIG_MODULE_SRCVERSION_ALL set? */
-static bool all_versions;
 /* Is CONFIG_BASIC_MODVERSIONS set? */
 static bool basic_modversions;
 /* Is CONFIG_EXTENDED_MODVERSIONS set? */
@@ -1584,7 +1582,6 @@ static void mod_set_crcs(struct module *mod)
 static void read_symbols(const char *modname)
 {
 	const char *symname;
-	char *version;
 	char *license;
 	char *namespace;
 	struct module *mod;

scripts/mod/modpost.c static void read_symbols(const char *modname) · line 1654

Quoted 10 lines
scripts/mod/modpost.c +0 -7
@@ -1645,13 +1642,6 @@ static void read_symbols(const char *modname)
 
 	check_sec_ref(mod, &info);
 
-	if (!mod->is_vmlinux) {
-		version = get_modinfo(&info, "version");
-		if (version || all_versions)
-			get_src_version(mod->name, mod->srcversion,
-					sizeof(mod->srcversion) - 1);
-	}
-

Sashiko correctly points out [2] that, with the removal of the get_src_version() call in modpost.c, the entire scripts/mod/sumversion.c can be removed.

Additionally, since sumversion.c was the only external caller of get_basename(), read_text_file(), get_line() in modpost.c, these functions can now optionally be made static.

Quoted 29 lines
scripts/mod/modpost.c +0 -11
 	parse_elf_finish(&info);
 
 	if (modversions) {
@@ -2035,15 +2025,6 @@ static void add_depends(struct buffer *b, struct module *mod)
 	buf_printf(b, "\");\n");
 }
 
-static void add_srcversion(struct buffer *b, struct module *mod)
-{
-	if (mod->srcversion[0]) {
-		buf_printf(b, "\n");
-		buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
-			   mod->srcversion);
-	}
-}
-
 static void write_buf(struct buffer *b, const char *fname)
 {
 	FILE *file;
@@ -2149,8 +2130,6 @@ static void write_mod_c_file(struct module *mod)
 		free(alias);
 	}
 
-	add_srcversion(&buf, mod);
-
 	ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);
 	if (ret >= sizeof(fname)) {
 		error("%s: too long path was truncated\n", fname);

scripts/mod/modpost.c int main(int argc, char **argv) · line 2311

Quoted 9 lines
scripts/mod/modpost.c +0 -3
@@ -2327,9 +2306,6 @@ int main(int argc, char **argv)
 		case 'o':
 			dump_write = optarg;
 			break;
-		case 'a':
-			all_versions = true;
-			break;
 		case 'T':
 			files_source = optarg;
 			break;

Sashiko correctly notes that the 'a' character should be removed from the preceding getopt() call.

scripts/mod/modpost.h struct module { · line 131

Quoted 13 lines
scripts/mod/modpost.h +0 -1
index 2aecb8f25c87..2c2f1d2b4021 100644
@@ -126,7 +126,6 @@ struct module {
 	bool seen;
 	bool has_init;
 	bool has_cleanup;
-	char	     srcversion[25];
 	// Missing namespace dependencies
 	struct list_head missing_namespaces;
 	// Actual imported namespaces

[1] https://github.com/kmod-project/kmod/commit/dc1fe2572a41eec540f8309d8a62043ce60c9f33
[2] https://lore.kernel.org/linux-modules/[email protected]/

Signature · 2 lines
Thanks,
Petr
Reviewed-by on v2 1/2
#4 lore raw

Re: [PATCH v2 1/2] module: remove MODULE_VERSION()

In reply to Greg Kroah-Hartman
Quoted 11 lines · Greg Kroah-Hartman

Module "versions" do not make sense as the kernel is built all at once, the "version" is the overall kernel version number, so modules can not really be described as having a unique version given that they rely on the infrastructure of the whole kernel.

For now, just make this an "empty" define, to keep existing code building properly as the tree is slowly purged of the use of this over time.

This macro will be removed entirely in the future when there are no in-tree users.

Looks good: