xref: /netbsd-src/doc/TODO.modules (revision 6584ea569e012fd0ff81a624a9d9a99240aa01aa)
1*6584ea56Sandvar/* $NetBSD: TODO.modules,v 1.24 2021/08/09 20:49:08 andvar Exp $ */
2a26f51deSpgoyette
3a26f51deSpgoyetteSome notes on the limitations of our current (as of 7.99.35) module
4a26f51deSpgoyettesubsystem.  This list was triggered by an Email exchange between
5a26f51deSpgoyettechristos and pgoyette.
6a26f51deSpgoyette
7a26f51deSpgoyette 1. Builtin drivers can't depend on modularized drivers (the modularized
8a26f51deSpgoyette    drivers are attempted to load as builtins).
9a26f51deSpgoyette
10a26f51deSpgoyette	The assumption is that dependencies are loaded before those
11a26f51deSpgoyette	modules which depend on them.  At load time, a module's
12a26f51deSpgoyette	undefined global symbols are resolved;  if any symbols can't
13a26f51deSpgoyette	be resolved, the load fails.  Similarly, if a module is
14a26f51deSpgoyette	included in (built-into) the kernel, all of its symbols must
15a26f51deSpgoyette	be resolvable by the linker, otherwise the link fails.
16a26f51deSpgoyette
17a26f51deSpgoyette	There are ways around this (such as, having the parent
18a26f51deSpgoyette	module's initialization command recursively call the module
1983e4431eSpgoyette	load code), but they're often gross hacks.
2083e4431eSpgoyette
2183e4431eSpgoyette	Another alternative (which is used by ppp) is to provide a
2283e4431eSpgoyette	"registration" mechanism for the "child" modules, and then when
2383e4431eSpgoyette	the need for a specific child module is encountered, use
2483e4431eSpgoyette	module_autoload() to load the child module.  Of course, this
2583e4431eSpgoyette	requires that the parent module know about all potentially
2683e4431eSpgoyette	loadable children.
27a26f51deSpgoyette
28a26f51deSpgoyette 2. Currently, config(1) has no way to "no define" drivers
29dd3883cdSchristos	XXX: I don't think this is true anymore. I think we can
30dd3883cdSchristos	undefine drivers now, see MODULAR in amd64, which does
31dd3883cdSchristos	no ath* and no select sppp*
32a26f51deSpgoyette
33a26f51deSpgoyette 3. It is not always obvious by their names which drivers/options
34a26f51deSpgoyette    correspond to which modules.
35a26f51deSpgoyette
36a26f51deSpgoyette 4. Right now critical drivers that would need to be pre-loaded (ffs,
37a26f51deSpgoyette    exec_elf64) are still built-in so that we don't need to alter the boot
38a26f51deSpgoyette    blocks to boot.
39a26f51deSpgoyette
40a26f51deSpgoyette	This was a conscious decision by core@ some years ago.  It is
41a26f51deSpgoyette	not a requirement that ffs or exec_* be built-in.  The only
42a26f51deSpgoyette	requirement is that the root file-system's module must be
43a26f51deSpgoyette	available when the module subsystem is initialized, in order
44a26f51deSpgoyette	to load other modules.  This can be accomplished by having the
45a26f51deSpgoyette	boot loader "push" the module at boot time.  (It used to do
46a26f51deSpgoyette	this in all cases; currently the "push" only occurs if the
47a26f51deSpgoyette	booted filesystem is not ffs.)
48a26f51deSpgoyette
49a26f51deSpgoyette 5. Not all parent bus drivers are capable of rescan, so some drivers
50a26f51deSpgoyette    just have to be built-in.
51a26f51deSpgoyette
52a26f51deSpgoyette 6. Many (most?) drivers are not yet modularized
53a26f51deSpgoyette
54a26f51deSpgoyette 7. There's currently no provisions for autoconfig to figure out which
55a26f51deSpgoyette    modules are needed, and thus to load the required modules.
56a26f51deSpgoyette
57a26f51deSpgoyette	In the "normal" built-in world, autoconfigure can only ask
58a26f51deSpgoyette	existing drivers if they're willing to manage (ie, attach) a
59a26f51deSpgoyette	device.  Removing the built-in drivers tends to limit the
60a26f51deSpgoyette	availability of possible managers.  There's currently no
61a26f51deSpgoyette	mechanism for identifying and loading drivers based on what
62a26f51deSpgoyette	devices might be found.
63a26f51deSpgoyette
64d1fb7510Spgoyette 8. Even for existing modules, there are "surprise" dependencies with
65d1fb7510Spgoyette    code that has not yet been modularized.
66d1fb7510Spgoyette
67d1fb7510Spgoyette	For example, even though the bpf code has been modularized,
68d1fb7510Spgoyette	there is some shared code in bpf_filter.c which is needed by
69d1fb7510Spgoyette	both ipfilter and ppp.  ipf is already modularized, but ppp
70d1fb7510Spgoyette	is not.  Thus, even though bpf_filter is modular, it MUST be
71d1fb7510Spgoyette	included as a built-in module if you also have ppp in your
72d1fb7510Spgoyette	configuration.
73d1fb7510Spgoyette
74d1fb7510Spgoyette	Another example is sysmon_taskq module.  It is required by
75d1fb7510Spgoyette	other parts of the sysmon subsystem, including the
76d1fb7510Spgoyette	"sysmon_power" module.  Unfortunately, even though the
77d1fb7510Spgoyette	sysmon_power code is modularized, it is referenced by the
78d1fb7510Spgoyette	acpi code which has not been modularized.  Therefore, if your
79d1fb7510Spgoyette	configuration has acpi, then you must include the "sysmon_power"
807dd71e32Spgoyette	module built-in the kernel.  And therefore you also need to
81d1fb7510Spgoyette	have "sysmon_taskq" and "sysmon" built-in since "sysmon_power"
82d1fb7510Spgoyette	rerefences them.
83d1fb7510Spgoyette
84d1fb7510Spgoyette 9. As a corollary to #8 above, having dependencies on modules from code
85d1fb7510Spgoyette    which has not been modularized makes it extremely difficult to test
86d1fb7510Spgoyette    the module code adequately.  Testing of module code should include
87d1fb7510Spgoyette    both testing-as-a-built-in module and testing-as-a-loaded-module, and
88d1fb7510Spgoyette    all dependencies need to be identified.
895c61d9f8Spgoyette
903bed3657Spgoyette10. The current /stand/$ARCH/$VERSION/modules/ hierarchy won't scale as
913bed3657Spgoyette    we get more and more modules.  There are hundreds of potential device
923bed3657Spgoyette    driver modules.
933bed3657Spgoyette
943bed3657Spgoyette11. There currently isn't any good way to handle attachment-specific
953bed3657Spgoyette    modules.  The build infrastructure (ie, sys/modules/Makefile) doesn't
963bed3657Spgoyette    readily lend itself to bus-specific modules irrespective of $ARCH,
973bed3657Spgoyette    and maintaining distrib/sets/lists/modules/* is awkward at best.
983bed3657Spgoyette
993bed3657Spgoyette    Furthermore, devices such as ld(4), which can attach to a large set
1003bed3657Spgoyette    of parent devices, need to be modified.  The parent devices need to
10184771e7bSwiz    provide a common attribute (for example, ld_bus), and the ld driver
1023bed3657Spgoyette    should attach to that attribute rather than to each parent.  But
1033bed3657Spgoyette    currently, config(1) doesn't handle this - it doesn't allow an
104dd3883cdSchristos    attribute to be used as the device tree's pseudo-root. The current
105dd3883cdSchristos    directory structure where driver foo is split between ic/foo.c
106dd3883cdSchristos    and bus1/foo_bus1.c ... busn/foo_busn.c is annoying. It would be
107dd3883cdSchristos    better to switch to the FreeBSD model which puts all the driver
108dd3883cdSchristos    files in one directory.
1093bed3657Spgoyette
1103bed3657Spgoyette12. Item #11 gets even murkier when a particular parent can provide more
1113bed3657Spgoyette    than one attribute.
112d442c428Spgoyette
113d442c428Spgoyette13. It seems that we might want some additional sets-lists "attributes"
114d442c428Spgoyette    to control contents of distributions.  As an example, many of our
115d442c428Spgoyette    architectures have PCI bus capabilities, but not all.  It is rather
116d442c428Spgoyette    painful to need to maintain individual architectures' modules/md_*
117d442c428Spgoyette    sets lists, especially when we already have to conditionalize the
118d442c428Spgoyette    build of the modules based on architecture.  If we had a single
119d442c428Spgoyette    "attribute" for PCI-bus-capable, the same attribute could be used to
120d442c428Spgoyette    select which modules to build and which modules from modules/mi to
121d442c428Spgoyette    include in the release.  (This is not limited to PCI;  recently we
122d442c428Spgoyette    encounter similar issues with spkr aka spkr_synth module.)
12319c83516Spgoyette
12419c83516Spgoyette14. As has been pointed out more than once, the current method of storing
12519c83516Spgoyette    modules in a version-specific subdirectory of /stand is sub-optimal
12619c83516Spgoyette    and leads to much difficulty and/or confusion.  A better mechanism of
12719c83516Spgoyette    associating a kernel and its modules needs to be developed.  Some
12819c83516Spgoyette    have suggested having a top-level directory (say, /netbsd) with a
12919c83516Spgoyette    kernel and its modules at /netbsd/kernel and /netbsd/modules/...
13019c83516Spgoyette    Whatever new mechanism we arrive at will probably require changes to
13119c83516Spgoyette    installation procedures and bootstrap code, and will need to handle
132*6584ea56Sandvar    both the new and old mechanisms for compatibility.
13334fb8cb6Spgoyette
13434fb8cb6Spgoyette    One additional option mentioned is to be able to specify, at boot
13534fb8cb6Spgoyette    loader time, an alternate value for the os-release portion of the
13634fb8cb6Spgoyette    default module path,  i.e. /stand/$MACHINE/$ALT-RELEASE/modules/
13734fb8cb6Spgoyette
138ea63cbf5Spgoyette    The following statement regarding this issue was previously issued
139ea63cbf5Spgoyette    by the "core" group:
140ea63cbf5Spgoyette
141ea63cbf5Spgoyette    Date: Fri, 27 Jul 2012 08:02:56 +0200
142ea63cbf5Spgoyette    From: <redacted>
143ea63cbf5Spgoyette    To: <redacted>
144ea63cbf5Spgoyette    Subject: Core statement on directory naming for kernel modules
145ea63cbf5Spgoyette
146ea63cbf5Spgoyette    The core group would also like to see the following changes in
147ea63cbf5Spgoyette    the near future:
148ea63cbf5Spgoyette
149ea63cbf5Spgoyette       Implementation of the scheme described by Luke Mewburn in
150ea63cbf5Spgoyette       <http://mail-index.NetBSD.org/current-users/2009/05/10/msg009372.html>
151ea63cbf5Spgoyette       to allow a kernel and its modules to be kept together.
152ea63cbf5Spgoyette       Changes to config(1) to extend the existing notion of whether or not
153ea63cbf5Spgoyette       an option is built-in to the kernel, to three states: built-in, not
154ea63cbf5Spgoyette       built-in but loadable as a module, entirely excluded and not even
155ea63cbf5Spgoyette       loadable as a module.
156ea63cbf5Spgoyette
157ea63cbf5Spgoyette
1586828875eSpgoyette15. The existing config(5) framework provides an excellent mechanism
1596828875eSpgoyette    for managing the content of kernels.  Unfortunately, this mechanism
1606828875eSpgoyette    does not apply for modules, and instead we need to manually manage
1616828875eSpgoyette    a list of files to include in the module, the set of compiler
1626828875eSpgoyette    definitions with which to build those files, and also the set of
1636828875eSpgoyette    other modules on which a module depends.  We really need a common
1646828875eSpgoyette    mechanism to define and build modules, whether they are included as
1656828875eSpgoyette    "built-in" modules or as separately-loadable modules.
1667dd71e32Spgoyette
1673510fa3aSpgoyette    (From John Nemeth) Some sort of mechanism for a (driver) module
1683510fa3aSpgoyette    to declare the list of vendor/product/other tuples that it can
1693510fa3aSpgoyette    handle would be nice.  Perhaps this would go in the module's .plist
1703510fa3aSpgoyette    file?  (See #17 below.)  Then drivers that scan for children might
1713510fa3aSpgoyette    be able to search the modules directory for an "appropriate" module
1723510fa3aSpgoyette    for each child, and auto-load.
1733510fa3aSpgoyette
1747dd71e32Spgoyette16. PR kern/52821 exposes another limitation of config(1) WRT modules.
1757dd71e32Spgoyette    Here, an explicit device attachment is required, because we cannot
1767dd71e32Spgoyette    rely on all kernel configs to contain the attribute at which the
1777dd71e32Spgoyette    modular driver wants to attach.  Unfortunately, the explicit
1787dd71e32Spgoyette    attachment causes conflicts with built-in drivers.  (See the PR for
1797dd71e32Spgoyette    more details.)
1803510fa3aSpgoyette
1813510fa3aSpgoyette17. (From John Nemeth) It would be potentially useful if a "push" from
1823510fa3aSpgoyette    the bootloader could also load-and-push a module's .plist (if it
1833510fa3aSpgoyette    exists.
1843510fa3aSpgoyette
1853510fa3aSpgoyette18. (From John Nemeth) Some sort of schema for a module to declare the
1863510fa3aSpgoyette    options (or other things?) that the module understands.  This could
1873510fa3aSpgoyette    result in a module-options editor to manipulate the .plist
1883510fa3aSpgoyette
1893510fa3aSpgoyette19. (From John Nemeth) Currently, the order of module initialization is
1903510fa3aSpgoyette    based on module classes and declared dependencies.  It might be
1913510fa3aSpgoyette    useful to have additional classes (or sub-classes) with additional
1923510fa3aSpgoyette    invocations of module_class_init(), and it might be useful to have a
1933510fa3aSpgoyette    non-dependency mechanism to provide "IF module-A and module-B are
1943510fa3aSpgoyette    BOTH present, module-A needs to be initialized before module-B".
1952cfa8ac5Spgoyette
1962cfa8ac5Spgoyette20. (Long-ago memory rises to the surface) Note that currently there is
1972cfa8ac5Spgoyette    nothing that requires a module's name to correspond in any way with
1982cfa8ac5Spgoyette    the name of file from which the module is loaded.  Thus, it is
1992cfa8ac5Spgoyette    possible to attempt to access device /dev/x, discover that there is
2002cfa8ac5Spgoyette    no such device so we autoload /stand/.../x/x.kmod and initialize
2012cfa8ac5Spgoyette    the module loaded, even if the loaded module is for some other
2022cfa8ac5Spgoyette    device entirely!
2032d3b79fcSpgoyette
2042d3b79fcSpgoyette21. We currently do not support "weak" symbols in the in-kernel linker.
2052d3b79fcSpgoyette    It would take some serious thought to get such support right.  For
2062d3b79fcSpgoyette    example, consider module A with a weak reference to symbol S which
2072d3b79fcSpgoyette    is defined in module B.  If module B is loaded first, and then
2082d3b79fcSpgoyette    module A, the symbol gets resolved.  But if module A is loaded first,
2092d3b79fcSpgoyette    the symbol won't be resolved.  If we subsequently load module B, we
2102d3b79fcSpgoyette    would have to "go back" and re-run the linker for module A.
211714733c8Spgoyette
212714733c8Spgoyette    Additional difficulties arise when the module which defines the
213714733c8Spgoyette    weak symbol gets unloaded.  Then, you would need to re-run the
214714733c8Spgoyette    linker and _unresolve_ the weak symbol which is no longer defined.
215759c9ce3Spgoyette
216759c9ce3Spgoyette22. A fairly large number of modules still require a maximum warning
217759c9ce3Spgoyette    level of WARNS=3 due to signed-vs-unsigned integer comparisons.  We
218759c9ce3Spgoyette    really ought to clean these up.  (I haven't looked at them in any
219759c9ce3Spgoyette    detail, but I have to wonder how code that compiles cleanly in a
220759c9ce3Spgoyette    normal kernel has these issues when compiled in a module, when both
221759c9ce3Spgoyette    are done with WARNS=5).
222949406f2Spgoyette
223949406f2Spgoyette23. The current process of "load all the emulation/exec modules in case
224949406f2Spgoyette    one of them might handle the image currently being exec'd" isn't
225949406f2Spgoyette    really cool.  (See sys/kern/kern_exec.c?)  It ends up auto-loading
226949406f2Spgoyette    a whole bunch of modules, involving file-system access, just to have
227949406f2Spgoyette    most of the modules getting unloaded a few seconds later.  We don't
228949406f2Spgoyette    have any way to identify which module is needed for which image (ie,
229949406f2Spgoyette    we can't determine that an image needs compat_linux vs some other
230949406f2Spgoyette    module).
2319ad866d2Spgoyette
2329ad866d2Spgoyette24. Details are no longer remembered, but there are some issues with
2339ad866d2Spgoyette    building xen-variant modules (on amd4, and likely i386).  In some
2349ad866d2Spgoyette    cases, wrong headers are included (because a XEN-related #define
2359ad866d2Spgoyette    is missing), but even if you add the definition some headers get
236d72c2724Spgoyette    included in the wrong order.  One particular fallout from this is
2379ad866d2Spgoyette    the inability to have a compat version of x86_64 cpu-microcode
238d72c2724Spgoyette    module.  PR port-xen/53130
239d72c2724Spgoyette
240d72c2724Spgoyette    This is likely to be fixed by Chuck Silvers on 2020-07-04 which
241d72c2724Spgoyette    removed the differences between the xen and non-xen module ABIs.
242f23451e7Spgoyette    As of 2021-05-28 the cpu-microcode functionality has once again
243f23451e7Spgoyette    been enabled for i386 and amd64 compat_60 modules.
244