TODO.modules revision 1.21
11.21Spgoyette/* $NetBSD: TODO.modules,v 1.21 2019/12/08 15:51:49 pgoyette Exp $ */
21.1Spgoyette
31.1SpgoyetteSome notes on the limitations of our current (as of 7.99.35) module
41.1Spgoyettesubsystem.  This list was triggered by an Email exchange between
51.1Spgoyettechristos and pgoyette.
61.1Spgoyette
71.7Schristos 1. Builtin drivers can't depend on modularized drivers (the modularized
81.7Schristos    drivers are attempted to load as builtins).
91.1Spgoyette
101.1Spgoyette	The assumption is that dependencies are loaded before those
111.1Spgoyette	modules which depend on them.  At load time, a module's
121.1Spgoyette	undefined global symbols are resolved;  if any symbols can't
131.1Spgoyette	be resolved, the load fails.  Similarly, if a module is
141.1Spgoyette	included in (built-into) the kernel, all of its symbols must
151.1Spgoyette	be resolvable by the linker, otherwise the link fails.
161.1Spgoyette
171.1Spgoyette	There are ways around this (such as, having the parent
181.1Spgoyette	module's initialization command recursively call the module
191.5Spgoyette	load code), but they're often gross hacks.
201.5Spgoyette
211.5Spgoyette	Another alternative (which is used by ppp) is to provide a
221.5Spgoyette	"registration" mechanism for the "child" modules, and then when
231.5Spgoyette	the need for a specific child module is encountered, use
241.5Spgoyette	module_autoload() to load the child module.  Of course, this
251.5Spgoyette	requires that the parent module know about all potentially
261.5Spgoyette	loadable children.
271.1Spgoyette
281.7Schristos 2. Currently, config(1) has no way to "no define" drivers
291.7Schristos	XXX: I don't think this is true anymore. I think we can
301.7Schristos	undefine drivers now, see MODULAR in amd64, which does
311.7Schristos	no ath* and no select sppp*
321.7Schristos
331.7Schristos 3. It is not always obvious by their names which drivers/options
341.7Schristos    correspond to which modules.
351.7Schristos
361.7Schristos 4. Right now critical drivers that would need to be pre-loaded (ffs,
371.7Schristos    exec_elf64) are still built-in so that we don't need to alter the boot
381.7Schristos    blocks to boot.
391.1Spgoyette
401.1Spgoyette	This was a conscious decision by core@ some years ago.  It is
411.1Spgoyette	not a requirement that ffs or exec_* be built-in.  The only
421.1Spgoyette	requirement is that the root file-system's module must be
431.1Spgoyette	available when the module subsystem is initialized, in order
441.1Spgoyette	to load other modules.  This can be accomplished by having the
451.1Spgoyette	boot loader "push" the module at boot time.  (It used to do
461.1Spgoyette	this in all cases; currently the "push" only occurs if the
471.1Spgoyette	booted filesystem is not ffs.)
481.1Spgoyette
491.7Schristos 5. Not all parent bus drivers are capable of rescan, so some drivers
501.7Schristos    just have to be built-in.
511.1Spgoyette
521.7Schristos 6. Many (most?) drivers are not yet modularized
531.1Spgoyette
541.7Schristos 7. There's currently no provisions for autoconfig to figure out which
551.7Schristos    modules are needed, and thus to load the required modules.
561.1Spgoyette
571.1Spgoyette	In the "normal" built-in world, autoconfigure can only ask
581.1Spgoyette	existing drivers if they're willing to manage (ie, attach) a
591.1Spgoyette	device.  Removing the built-in drivers tends to limit the
601.1Spgoyette	availability of possible managers.  There's currently no
611.1Spgoyette	mechanism for identifying and loading drivers based on what
621.1Spgoyette	devices might be found.
631.1Spgoyette
641.7Schristos 8. Even for existing modules, there are "surprise" dependencies with
651.7Schristos    code that has not yet been modularized.
661.2Spgoyette
671.2Spgoyette	For example, even though the bpf code has been modularized,
681.2Spgoyette	there is some shared code in bpf_filter.c which is needed by
691.2Spgoyette	both ipfilter and ppp.  ipf is already modularized, but ppp
701.2Spgoyette	is not.  Thus, even though bpf_filter is modular, it MUST be
711.2Spgoyette	included as a built-in module if you also have ppp in your
721.2Spgoyette	configuration.
731.2Spgoyette
741.2Spgoyette	Another example is sysmon_taskq module.  It is required by
751.2Spgoyette	other parts of the sysmon subsystem, including the
761.2Spgoyette	"sysmon_power" module.  Unfortunately, even though the
771.2Spgoyette	sysmon_power code is modularized, it is referenced by the
781.2Spgoyette	acpi code which has not been modularized.  Therefore, if your
791.2Spgoyette	configuration has acpi, then you must include the "sysmon_power"
801.14Spgoyette	module built-in the kernel.  And therefore you also need to
811.2Spgoyette	have "sysmon_taskq" and "sysmon" built-in since "sysmon_power"
821.2Spgoyette	rerefences them.
831.2Spgoyette
841.7Schristos 9. As a corollary to #8 above, having dependencies on modules from code
851.7Schristos    which has not been modularized makes it extremely difficult to test
861.7Schristos    the module code adequately.  Testing of module code should include
871.7Schristos    both testing-as-a-built-in module and testing-as-a-loaded-module, and
881.7Schristos    all dependencies need to be identified.
891.7Schristos
901.7Schristos10. The current /stand/$ARCH/$VERSION/modules/ hierarchy won't scale as
911.7Schristos    we get more and more modules.  There are hundreds of potential device
921.7Schristos    driver modules.
931.7Schristos
941.7Schristos11. There currently isn't any good way to handle attachment-specific
951.7Schristos    modules.  The build infrastructure (ie, sys/modules/Makefile) doesn't
961.7Schristos    readily lend itself to bus-specific modules irrespective of $ARCH,
971.7Schristos    and maintaining distrib/sets/lists/modules/* is awkward at best.
981.7Schristos
991.7Schristos    Furthermore, devices such as ld(4), which can attach to a large set
1001.7Schristos    of parent devices, need to be modified.  The parent devices need to
1011.8Swiz    provide a common attribute (for example, ld_bus), and the ld driver
1021.7Schristos    should attach to that attribute rather than to each parent.  But
1031.7Schristos    currently, config(1) doesn't handle this - it doesn't allow an
1041.7Schristos    attribute to be used as the device tree's pseudo-root. The current
1051.7Schristos    directory structure where driver foo is split between ic/foo.c
1061.7Schristos    and bus1/foo_bus1.c ... busn/foo_busn.c is annoying. It would be
1071.7Schristos    better to switch to the FreeBSD model which puts all the driver
1081.7Schristos    files in one directory.
1091.6Spgoyette
1101.7Schristos12. Item #11 gets even murkier when a particular parent can provide more
1111.7Schristos    than one attribute.
1121.9Spgoyette
1131.9Spgoyette13. It seems that we might want some additional sets-lists "attributes"
1141.9Spgoyette    to control contents of distributions.  As an example, many of our
1151.9Spgoyette    architectures have PCI bus capabilities, but not all.  It is rather
1161.9Spgoyette    painful to need to maintain individual architectures' modules/md_*
1171.9Spgoyette    sets lists, especially when we already have to conditionalize the
1181.9Spgoyette    build of the modules based on architecture.  If we had a single
1191.9Spgoyette    "attribute" for PCI-bus-capable, the same attribute could be used to
1201.9Spgoyette    select which modules to build and which modules from modules/mi to
1211.9Spgoyette    include in the release.  (This is not limited to PCI;  recently we
1221.9Spgoyette    encounter similar issues with spkr aka spkr_synth module.)
1231.10Spgoyette
1241.10Spgoyette14. As has been pointed out more than once, the current method of storing
1251.10Spgoyette    modules in a version-specific subdirectory of /stand is sub-optimal
1261.10Spgoyette    and leads to much difficulty and/or confusion.  A better mechanism of
1271.10Spgoyette    associating a kernel and its modules needs to be developed.  Some
1281.10Spgoyette    have suggested having a top-level directory (say, /netbsd) with a
1291.10Spgoyette    kernel and its modules at /netbsd/kernel and /netbsd/modules/...
1301.10Spgoyette    Whatever new mechanism we arrive at will probably require changes to
1311.10Spgoyette    installation procedures and bootstrap code, and will need to handle
1321.10Spgoyette    both the new and old mechanisms for compatability.
1331.11Spgoyette
1341.11Spgoyette    One additional option mentioned is to be able to specify, at boot
1351.11Spgoyette    loader time, an alternate value for the os-release portion of the
1361.11Spgoyette    default module path,  i.e. /stand/$MACHINE/$ALT-RELEASE/modules/
1371.11Spgoyette
1381.13Spgoyette    The following statement regarding this issue was previously issued
1391.13Spgoyette    by the "core" group:
1401.13Spgoyette
1411.13Spgoyette    Date: Fri, 27 Jul 2012 08:02:56 +0200
1421.13Spgoyette    From: <redacted>
1431.13Spgoyette    To: <redacted>
1441.13Spgoyette    Subject: Core statement on directory naming for kernel modules
1451.13Spgoyette
1461.13Spgoyette    The core group would also like to see the following changes in
1471.13Spgoyette    the near future:
1481.13Spgoyette
1491.13Spgoyette       Implementation of the scheme described by Luke Mewburn in
1501.13Spgoyette       <http://mail-index.NetBSD.org/current-users/2009/05/10/msg009372.html>
1511.13Spgoyette       to allow a kernel and its modules to be kept together.
1521.13Spgoyette       Changes to config(1) to extend the existing notion of whether or not
1531.13Spgoyette       an option is built-in to the kernel, to three states: built-in, not
1541.13Spgoyette       built-in but loadable as a module, entirely excluded and not even
1551.13Spgoyette       loadable as a module.
1561.13Spgoyette
1571.13Spgoyette
1581.12Spgoyette15. The existing config(5) framework provides an excellent mechanism
1591.12Spgoyette    for managing the content of kernels.  Unfortunately, this mechanism
1601.12Spgoyette    does not apply for modules, and instead we need to manually manage
1611.12Spgoyette    a list of files to include in the module, the set of compiler
1621.12Spgoyette    definitions with which to build those files, and also the set of
1631.12Spgoyette    other modules on which a module depends.  We really need a common
1641.12Spgoyette    mechanism to define and build modules, whether they are included as
1651.12Spgoyette    "built-in" modules or as separately-loadable modules.
1661.14Spgoyette
1671.15Spgoyette    (From John Nemeth) Some sort of mechanism for a (driver) module
1681.15Spgoyette    to declare the list of vendor/product/other tuples that it can
1691.15Spgoyette    handle would be nice.  Perhaps this would go in the module's .plist
1701.15Spgoyette    file?  (See #17 below.)  Then drivers that scan for children might
1711.15Spgoyette    be able to search the modules directory for an "appropriate" module
1721.15Spgoyette    for each child, and auto-load.
1731.15Spgoyette
1741.14Spgoyette16. PR kern/52821 exposes another limitation of config(1) WRT modules.
1751.14Spgoyette    Here, an explicit device attachment is required, because we cannot
1761.14Spgoyette    rely on all kernel configs to contain the attribute at which the
1771.14Spgoyette    modular driver wants to attach.  Unfortunately, the explicit
1781.14Spgoyette    attachment causes conflicts with built-in drivers.  (See the PR for
1791.14Spgoyette    more details.)
1801.15Spgoyette
1811.15Spgoyette17. (From John Nemeth) It would be potentially useful if a "push" from
1821.15Spgoyette    the bootloader could also load-and-push a module's .plist (if it
1831.15Spgoyette    exists.
1841.15Spgoyette
1851.15Spgoyette18. (From John Nemeth) Some sort of schema for a module to declare the
1861.15Spgoyette    options (or other things?) that the module understands.  This could
1871.15Spgoyette    result in a module-options editor to manipulate the .plist 
1881.15Spgoyette
1891.15Spgoyette19. (From John Nemeth) Currently, the order of module initialization is
1901.15Spgoyette    based on module classes and declared dependencies.  It might be
1911.15Spgoyette    useful to have additional classes (or sub-classes) with additional
1921.15Spgoyette    invocations of module_class_init(), and it might be useful to have a
1931.15Spgoyette    non-dependency mechanism to provide "IF module-A and module-B are
1941.15Spgoyette    BOTH present, module-A needs to be initialized before module-B".
1951.16Spgoyette
1961.16Spgoyette20. (Long-ago memory rises to the surface) Note that currently there is
1971.16Spgoyette    nothing that requires a module's name to correspond in any way with
1981.16Spgoyette    the name of file from which the module is loaded.  Thus, it is
1991.16Spgoyette    possible to attempt to access device /dev/x, discover that there is
2001.16Spgoyette    no such device so we autoload /stand/.../x/x.kmod and initialize
2011.16Spgoyette    the module loaded, even if the loaded module is for some other
2021.16Spgoyette    device entirely!
2031.17Spgoyette
2041.17Spgoyette21. We currently do not support "weak" symbols in the in-kernel linker.
2051.17Spgoyette    It would take some serious thought to get such support right.  For
2061.17Spgoyette    example, consider module A with a weak reference to symbol S which
2071.17Spgoyette    is defined in module B.  If module B is loaded first, and then
2081.17Spgoyette    module A, the symbol gets resolved.  But if module A is loaded first,
2091.17Spgoyette    the symbol won't be resolved.  If we subsequently load module B, we
2101.17Spgoyette    would have to "go back" and re-run the linker for module A.
2111.18Spgoyette
2121.18Spgoyette    Additional difficulties arise when the module which defines the
2131.18Spgoyette    weak symbol gets unloaded.  Then, you would need to re-run the
2141.18Spgoyette    linker and _unresolve_ the weak symbol which is no longer defined.
2151.19Spgoyette
2161.19Spgoyette22. A fairly large number of modules still require a maximum warning
2171.19Spgoyette    level of WARNS=3 due to signed-vs-unsigned integer comparisons.  We
2181.19Spgoyette    really ought to clean these up.  (I haven't looked at them in any
2191.19Spgoyette    detail, but I have to wonder how code that compiles cleanly in a
2201.19Spgoyette    normal kernel has these issues when compiled in a module, when both
2211.19Spgoyette    are done with WARNS=5).
2221.20Spgoyette
2231.20Spgoyette23. The current process of "load all the emulation/exec modules in case
2241.20Spgoyette    one of them might handle the image currently being exec'd" isn't
2251.20Spgoyette    really cool.  (See sys/kern/kern_exec.c?)  It ends up auto-loading
2261.20Spgoyette    a whole bunch of modules, involving file-system access, just to have
2271.20Spgoyette    most of the modules getting unloaded a few seconds later.  We don't
2281.20Spgoyette    have any way to identify which module is needed for which image (ie,
2291.20Spgoyette    we can't determine that an image needs compat_linux vs some other
2301.20Spgoyette    module).
2311.21Spgoyette
2321.21Spgoyette24. Details are no longer remembered, but there are some issues with
2331.21Spgoyette    building xen-variant modules (on amd4, and likely i386).  In some
2341.21Spgoyette    cases, wrong headers are included (because a XEN-related #define
2351.21Spgoyette    is missing), but even if you add the definition some headers get
2361.21Spgoyette    included in the wrong order.  On particular fallout from this is
2371.21Spgoyette    the inability to have a compat version of x86_64 cpu-microcode
2381.21Spgoyette    module.
239