On 3/16/26 11:03 AM, Greg Kroah-Hartman wrote:
> On Mon, Mar 16, 2026 at 10:37:38AM +0100, Petr Pavlu wrote:
>> On 3/13/26 3:20 PM, Greg Kroah-Hartman wrote:
>>> 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.
>>
>> I share a similar sentiment that module versions set by MODULE_VERSION()
>> are not particularly useful for in-tree modules and the macro is often
>> used unnecessarily. However, I don't think this patch takes the best
>> approach to phase it out.
>>
>> The file Documentation/ABI/stable/sysfs-module documents
>> /sys/module/<MODULENAME>/version as a stable ABI. Searching for
>> '^MODULE_VERSION' in v7.0-rc4 shows 600 uses of the macro. My concern is
>> that if any of these modules has a userspace part that checks the
>> version, this patch could potentially break users' systems.
> 
> sysfs use is ALWAYS "if the file is not there, the userspace tool should
> keep working".  How would userspace every do something different if a
> module version flag is not there, that is not how a kernel driver should
> ever be attempting to communicate with userspace as to what the api is,
> or is not.
> 
> And as the module version does not even work for any stable kernel
> release, it's kind of proof that userspace does not rely on this.

Makes sense. I have now also reviewed updates of MODULE_VERSION()
invocations going back 5 years and my impression is that removing this
macro should be generally safe.

New instances of MODULE_VERSION() are typically introduced when a new
driver is added to the codebase.

There were numerous commits where MODULE_VERSION() is removed with the
argument that it is unnecessary for in-tree modules and that the main
kernel version should be used instead. This suggest that there is
already a broader consensus that module versions are not particularly
useful, at least not for in-tree modules.

There was a limited number of cases where a per-module version is
actually updated. Examples:

ea7af9454815 ("platform/x86: dell_rbu: Bump version")
93d09773d1a5 ("xz: add RISC-V BCJ filter")
98d5b61ef5fa ("coda: bump module version to 7.2")
8cb5d216ab33 ("char: xillybus: Move class-related functions to new 
xillybus_class.c")
74f46a0524f8 ("scsi: fnic: Turn off FDMI ACTIVE flags on link down")
6cd379f75f42 ("ata: pata_hpt3x2n: pass base DPLL frequency to 
hpt3x2n_pci_clock()")
47adef20e67d ("pata: ixp4xx: Rewrite to use device tree")

(The last three commits are indirect updates, where the module contains
MODULE_VERSION(DRV_VERSION); and DRV_VERSION is updated.)

Most of these version bumps do not seem particularly noteworthy. Only
commit 98d5b61ef5fa appears somewhat interesting with the description:

    coda: bump module version to 7.2

    Helps with tracking which patches have been propagated upstream and if
    users are running the latest known version.

> 
>> I believe it would be safer to start by removing individual uses of
>> MODULE_VERSION(). That way, we can also learn if we're missing any use
>> cases for having module versions.
> 
> Sure, I'll make up a patch to drop all 700 uses, but how is that much
> different?  :)

The end result is ultimately the same. The kernel will no longer have
any uses of MODULE_VERSION() or its implementation.

The difference is that by removing the uses of MODULE_VERSION() first,
the maintainers of the relevant code will be properly informed about
this change, rather than being told afterwards, when they will no longer
have a chance to provide any feedback.

Another aspect is that MODULE_VERSION() still appears useful for
external modules. Sure, we won't keep this macro if all uses in the
kernel are removed and these external modules will need to replace it
with a different mechanism. However, changing MODULE_VERSION() now to
only a dummy implementation can silently break version tracking for
these modules, which is not ideal.

If I end up being the only one who prefers removing the invocations of
this macro first, then please at least CC a few more lists on v2 of the
patch, such as driver-core and netdev, as well as the authors of the
recent version-bump commits that I identified above.

> 
>> The original patch "Add a MODULE_VERSION macro" [1] from 2004 doesn't
>> say much about the motivation for adding module versions, but it does
>> mention that they should be accessible via sysfs.
> 
> That was because we were just exporting all of the module information in
> sysfs, not due to us attempting to do anything special with that info in
> userspace other than "hey we have an attribute, let's export it!"
> 
>> That was implemented
>> a year later in commit c988d2b28454 ("[PATCH] modules: add version and
>> srcversion to sysfs") [2], which primarily discusses use cases related
>> to DKMS, and to administrators + tech support needing to know what is
>> actually loaded on the system. For the latter, I believe srcversion (or
>> something similar) should be sufficient.
> 
> And does dkms actually do anything with this sysfs value?  At quick
> glance, I couldn't see anything.

I'm not familiar with DKMS. From a quick look, it parses both the
version and srcversion, although it calls modinfo and doesn't read the
values from sysfs. See get_module_verinfo() and compare_module_version()
in dkms.in [1].

[1] 
https://github.com/dkms-project/dkms/blob/2c35ae1d32eb6377ef8e8dd7e15427d56b63828d/dkms.in#L983

-- 
Thanks,
Petr

Reply via email to