1 1.24 andvar /* $NetBSD: TODO.modules,v 1.24 2021/08/09 20:49:08 andvar Exp $ */ 2 1.1 pgoyette 3 1.1 pgoyette Some notes on the limitations of our current (as of 7.99.35) module 4 1.1 pgoyette subsystem. This list was triggered by an Email exchange between 5 1.1 pgoyette christos and pgoyette. 6 1.1 pgoyette 7 1.7 christos 1. Builtin drivers can't depend on modularized drivers (the modularized 8 1.7 christos drivers are attempted to load as builtins). 9 1.1 pgoyette 10 1.1 pgoyette The assumption is that dependencies are loaded before those 11 1.1 pgoyette modules which depend on them. At load time, a module's 12 1.1 pgoyette undefined global symbols are resolved; if any symbols can't 13 1.1 pgoyette be resolved, the load fails. Similarly, if a module is 14 1.1 pgoyette included in (built-into) the kernel, all of its symbols must 15 1.1 pgoyette be resolvable by the linker, otherwise the link fails. 16 1.1 pgoyette 17 1.1 pgoyette There are ways around this (such as, having the parent 18 1.1 pgoyette module's initialization command recursively call the module 19 1.5 pgoyette load code), but they're often gross hacks. 20 1.5 pgoyette 21 1.5 pgoyette Another alternative (which is used by ppp) is to provide a 22 1.5 pgoyette "registration" mechanism for the "child" modules, and then when 23 1.5 pgoyette the need for a specific child module is encountered, use 24 1.5 pgoyette module_autoload() to load the child module. Of course, this 25 1.5 pgoyette requires that the parent module know about all potentially 26 1.5 pgoyette loadable children. 27 1.1 pgoyette 28 1.7 christos 2. Currently, config(1) has no way to "no define" drivers 29 1.7 christos XXX: I don't think this is true anymore. I think we can 30 1.7 christos undefine drivers now, see MODULAR in amd64, which does 31 1.7 christos no ath* and no select sppp* 32 1.7 christos 33 1.7 christos 3. It is not always obvious by their names which drivers/options 34 1.7 christos correspond to which modules. 35 1.7 christos 36 1.7 christos 4. Right now critical drivers that would need to be pre-loaded (ffs, 37 1.7 christos exec_elf64) are still built-in so that we don't need to alter the boot 38 1.7 christos blocks to boot. 39 1.1 pgoyette 40 1.1 pgoyette This was a conscious decision by core@ some years ago. It is 41 1.1 pgoyette not a requirement that ffs or exec_* be built-in. The only 42 1.1 pgoyette requirement is that the root file-system's module must be 43 1.1 pgoyette available when the module subsystem is initialized, in order 44 1.1 pgoyette to load other modules. This can be accomplished by having the 45 1.1 pgoyette boot loader "push" the module at boot time. (It used to do 46 1.1 pgoyette this in all cases; currently the "push" only occurs if the 47 1.1 pgoyette booted filesystem is not ffs.) 48 1.1 pgoyette 49 1.7 christos 5. Not all parent bus drivers are capable of rescan, so some drivers 50 1.7 christos just have to be built-in. 51 1.1 pgoyette 52 1.7 christos 6. Many (most?) drivers are not yet modularized 53 1.1 pgoyette 54 1.7 christos 7. There's currently no provisions for autoconfig to figure out which 55 1.7 christos modules are needed, and thus to load the required modules. 56 1.1 pgoyette 57 1.1 pgoyette In the "normal" built-in world, autoconfigure can only ask 58 1.1 pgoyette existing drivers if they're willing to manage (ie, attach) a 59 1.1 pgoyette device. Removing the built-in drivers tends to limit the 60 1.1 pgoyette availability of possible managers. There's currently no 61 1.1 pgoyette mechanism for identifying and loading drivers based on what 62 1.1 pgoyette devices might be found. 63 1.1 pgoyette 64 1.7 christos 8. Even for existing modules, there are "surprise" dependencies with 65 1.7 christos code that has not yet been modularized. 66 1.2 pgoyette 67 1.2 pgoyette For example, even though the bpf code has been modularized, 68 1.2 pgoyette there is some shared code in bpf_filter.c which is needed by 69 1.2 pgoyette both ipfilter and ppp. ipf is already modularized, but ppp 70 1.2 pgoyette is not. Thus, even though bpf_filter is modular, it MUST be 71 1.2 pgoyette included as a built-in module if you also have ppp in your 72 1.2 pgoyette configuration. 73 1.2 pgoyette 74 1.2 pgoyette Another example is sysmon_taskq module. It is required by 75 1.2 pgoyette other parts of the sysmon subsystem, including the 76 1.2 pgoyette "sysmon_power" module. Unfortunately, even though the 77 1.2 pgoyette sysmon_power code is modularized, it is referenced by the 78 1.2 pgoyette acpi code which has not been modularized. Therefore, if your 79 1.2 pgoyette configuration has acpi, then you must include the "sysmon_power" 80 1.14 pgoyette module built-in the kernel. And therefore you also need to 81 1.2 pgoyette have "sysmon_taskq" and "sysmon" built-in since "sysmon_power" 82 1.2 pgoyette rerefences them. 83 1.2 pgoyette 84 1.7 christos 9. As a corollary to #8 above, having dependencies on modules from code 85 1.7 christos which has not been modularized makes it extremely difficult to test 86 1.7 christos the module code adequately. Testing of module code should include 87 1.7 christos both testing-as-a-built-in module and testing-as-a-loaded-module, and 88 1.7 christos all dependencies need to be identified. 89 1.7 christos 90 1.7 christos 10. The current /stand/$ARCH/$VERSION/modules/ hierarchy won't scale as 91 1.7 christos we get more and more modules. There are hundreds of potential device 92 1.7 christos driver modules. 93 1.7 christos 94 1.7 christos 11. There currently isn't any good way to handle attachment-specific 95 1.7 christos modules. The build infrastructure (ie, sys/modules/Makefile) doesn't 96 1.7 christos readily lend itself to bus-specific modules irrespective of $ARCH, 97 1.7 christos and maintaining distrib/sets/lists/modules/* is awkward at best. 98 1.7 christos 99 1.7 christos Furthermore, devices such as ld(4), which can attach to a large set 100 1.7 christos of parent devices, need to be modified. The parent devices need to 101 1.8 wiz provide a common attribute (for example, ld_bus), and the ld driver 102 1.7 christos should attach to that attribute rather than to each parent. But 103 1.7 christos currently, config(1) doesn't handle this - it doesn't allow an 104 1.7 christos attribute to be used as the device tree's pseudo-root. The current 105 1.7 christos directory structure where driver foo is split between ic/foo.c 106 1.7 christos and bus1/foo_bus1.c ... busn/foo_busn.c is annoying. It would be 107 1.7 christos better to switch to the FreeBSD model which puts all the driver 108 1.7 christos files in one directory. 109 1.6 pgoyette 110 1.7 christos 12. Item #11 gets even murkier when a particular parent can provide more 111 1.7 christos than one attribute. 112 1.9 pgoyette 113 1.9 pgoyette 13. It seems that we might want some additional sets-lists "attributes" 114 1.9 pgoyette to control contents of distributions. As an example, many of our 115 1.9 pgoyette architectures have PCI bus capabilities, but not all. It is rather 116 1.9 pgoyette painful to need to maintain individual architectures' modules/md_* 117 1.9 pgoyette sets lists, especially when we already have to conditionalize the 118 1.9 pgoyette build of the modules based on architecture. If we had a single 119 1.9 pgoyette "attribute" for PCI-bus-capable, the same attribute could be used to 120 1.9 pgoyette select which modules to build and which modules from modules/mi to 121 1.9 pgoyette include in the release. (This is not limited to PCI; recently we 122 1.9 pgoyette encounter similar issues with spkr aka spkr_synth module.) 123 1.10 pgoyette 124 1.10 pgoyette 14. As has been pointed out more than once, the current method of storing 125 1.10 pgoyette modules in a version-specific subdirectory of /stand is sub-optimal 126 1.10 pgoyette and leads to much difficulty and/or confusion. A better mechanism of 127 1.10 pgoyette associating a kernel and its modules needs to be developed. Some 128 1.10 pgoyette have suggested having a top-level directory (say, /netbsd) with a 129 1.10 pgoyette kernel and its modules at /netbsd/kernel and /netbsd/modules/... 130 1.10 pgoyette Whatever new mechanism we arrive at will probably require changes to 131 1.10 pgoyette installation procedures and bootstrap code, and will need to handle 132 1.24 andvar both the new and old mechanisms for compatibility. 133 1.11 pgoyette 134 1.11 pgoyette One additional option mentioned is to be able to specify, at boot 135 1.11 pgoyette loader time, an alternate value for the os-release portion of the 136 1.11 pgoyette default module path, i.e. /stand/$MACHINE/$ALT-RELEASE/modules/ 137 1.11 pgoyette 138 1.13 pgoyette The following statement regarding this issue was previously issued 139 1.13 pgoyette by the "core" group: 140 1.13 pgoyette 141 1.13 pgoyette Date: Fri, 27 Jul 2012 08:02:56 +0200 142 1.13 pgoyette From: <redacted> 143 1.13 pgoyette To: <redacted> 144 1.13 pgoyette Subject: Core statement on directory naming for kernel modules 145 1.13 pgoyette 146 1.13 pgoyette The core group would also like to see the following changes in 147 1.13 pgoyette the near future: 148 1.13 pgoyette 149 1.13 pgoyette Implementation of the scheme described by Luke Mewburn in 150 1.13 pgoyette <http://mail-index.NetBSD.org/current-users/2009/05/10/msg009372.html> 151 1.13 pgoyette to allow a kernel and its modules to be kept together. 152 1.13 pgoyette Changes to config(1) to extend the existing notion of whether or not 153 1.13 pgoyette an option is built-in to the kernel, to three states: built-in, not 154 1.13 pgoyette built-in but loadable as a module, entirely excluded and not even 155 1.13 pgoyette loadable as a module. 156 1.13 pgoyette 157 1.13 pgoyette 158 1.12 pgoyette 15. The existing config(5) framework provides an excellent mechanism 159 1.12 pgoyette for managing the content of kernels. Unfortunately, this mechanism 160 1.12 pgoyette does not apply for modules, and instead we need to manually manage 161 1.12 pgoyette a list of files to include in the module, the set of compiler 162 1.12 pgoyette definitions with which to build those files, and also the set of 163 1.12 pgoyette other modules on which a module depends. We really need a common 164 1.12 pgoyette mechanism to define and build modules, whether they are included as 165 1.12 pgoyette "built-in" modules or as separately-loadable modules. 166 1.14 pgoyette 167 1.15 pgoyette (From John Nemeth) Some sort of mechanism for a (driver) module 168 1.15 pgoyette to declare the list of vendor/product/other tuples that it can 169 1.15 pgoyette handle would be nice. Perhaps this would go in the module's .plist 170 1.15 pgoyette file? (See #17 below.) Then drivers that scan for children might 171 1.15 pgoyette be able to search the modules directory for an "appropriate" module 172 1.15 pgoyette for each child, and auto-load. 173 1.15 pgoyette 174 1.14 pgoyette 16. PR kern/52821 exposes another limitation of config(1) WRT modules. 175 1.14 pgoyette Here, an explicit device attachment is required, because we cannot 176 1.14 pgoyette rely on all kernel configs to contain the attribute at which the 177 1.14 pgoyette modular driver wants to attach. Unfortunately, the explicit 178 1.14 pgoyette attachment causes conflicts with built-in drivers. (See the PR for 179 1.14 pgoyette more details.) 180 1.15 pgoyette 181 1.15 pgoyette 17. (From John Nemeth) It would be potentially useful if a "push" from 182 1.15 pgoyette the bootloader could also load-and-push a module's .plist (if it 183 1.15 pgoyette exists. 184 1.15 pgoyette 185 1.15 pgoyette 18. (From John Nemeth) Some sort of schema for a module to declare the 186 1.15 pgoyette options (or other things?) that the module understands. This could 187 1.15 pgoyette result in a module-options editor to manipulate the .plist 188 1.15 pgoyette 189 1.15 pgoyette 19. (From John Nemeth) Currently, the order of module initialization is 190 1.15 pgoyette based on module classes and declared dependencies. It might be 191 1.15 pgoyette useful to have additional classes (or sub-classes) with additional 192 1.15 pgoyette invocations of module_class_init(), and it might be useful to have a 193 1.15 pgoyette non-dependency mechanism to provide "IF module-A and module-B are 194 1.15 pgoyette BOTH present, module-A needs to be initialized before module-B". 195 1.16 pgoyette 196 1.16 pgoyette 20. (Long-ago memory rises to the surface) Note that currently there is 197 1.16 pgoyette nothing that requires a module's name to correspond in any way with 198 1.16 pgoyette the name of file from which the module is loaded. Thus, it is 199 1.16 pgoyette possible to attempt to access device /dev/x, discover that there is 200 1.16 pgoyette no such device so we autoload /stand/.../x/x.kmod and initialize 201 1.16 pgoyette the module loaded, even if the loaded module is for some other 202 1.16 pgoyette device entirely! 203 1.17 pgoyette 204 1.17 pgoyette 21. We currently do not support "weak" symbols in the in-kernel linker. 205 1.17 pgoyette It would take some serious thought to get such support right. For 206 1.17 pgoyette example, consider module A with a weak reference to symbol S which 207 1.17 pgoyette is defined in module B. If module B is loaded first, and then 208 1.17 pgoyette module A, the symbol gets resolved. But if module A is loaded first, 209 1.17 pgoyette the symbol won't be resolved. If we subsequently load module B, we 210 1.17 pgoyette would have to "go back" and re-run the linker for module A. 211 1.18 pgoyette 212 1.18 pgoyette Additional difficulties arise when the module which defines the 213 1.18 pgoyette weak symbol gets unloaded. Then, you would need to re-run the 214 1.18 pgoyette linker and _unresolve_ the weak symbol which is no longer defined. 215 1.19 pgoyette 216 1.19 pgoyette 22. A fairly large number of modules still require a maximum warning 217 1.19 pgoyette level of WARNS=3 due to signed-vs-unsigned integer comparisons. We 218 1.19 pgoyette really ought to clean these up. (I haven't looked at them in any 219 1.19 pgoyette detail, but I have to wonder how code that compiles cleanly in a 220 1.19 pgoyette normal kernel has these issues when compiled in a module, when both 221 1.19 pgoyette are done with WARNS=5). 222 1.20 pgoyette 223 1.20 pgoyette 23. The current process of "load all the emulation/exec modules in case 224 1.20 pgoyette one of them might handle the image currently being exec'd" isn't 225 1.20 pgoyette really cool. (See sys/kern/kern_exec.c?) It ends up auto-loading 226 1.20 pgoyette a whole bunch of modules, involving file-system access, just to have 227 1.20 pgoyette most of the modules getting unloaded a few seconds later. We don't 228 1.20 pgoyette have any way to identify which module is needed for which image (ie, 229 1.20 pgoyette we can't determine that an image needs compat_linux vs some other 230 1.20 pgoyette module). 231 1.21 pgoyette 232 1.21 pgoyette 24. Details are no longer remembered, but there are some issues with 233 1.21 pgoyette building xen-variant modules (on amd4, and likely i386). In some 234 1.21 pgoyette cases, wrong headers are included (because a XEN-related #define 235 1.21 pgoyette is missing), but even if you add the definition some headers get 236 1.22 pgoyette included in the wrong order. One particular fallout from this is 237 1.21 pgoyette the inability to have a compat version of x86_64 cpu-microcode 238 1.22 pgoyette module. PR port-xen/53130 239 1.22 pgoyette 240 1.22 pgoyette This is likely to be fixed by Chuck Silvers on 2020-07-04 which 241 1.22 pgoyette removed the differences between the xen and non-xen module ABIs. 242 1.23 pgoyette As of 2021-05-28 the cpu-microcode functionality has once again 243 1.23 pgoyette been enabled for i386 and amd64 compat_60 modules. 244