0

I have a kernel module modA.ko that depends upon exported symbols.

exported_func1(void)
exported_func2(void)

And I have two other modules modB.ko and modC.ko that has the definitions for exported functions separately. Function signature is the same but functionality is different. Only one of the modB.ko or modC.ko is supposed to be loaded at the same time. Every time the kbuild determines that modA.ko is dependent on modB.ko. I don't want that. I want to dynamically load the appropriate modules before using modA.ko according to the need. Is there a way to force the kernel build system to not add dependencies just for this particular module.

I am using Buildroot to build the Linux image but no dependencies are defined in buildroot-config for these modules. In the Buildroot output/, both modB.ko and modC.ko have exported functions listed in the .symvers files.

0andriy
  • 4,183
  • 1
  • 24
  • 37
weja
  • 13
  • 5
  • Would it be possible for modB.ko and modC.ko to depend on a "registration" function exported by modA.ko to set some callback function pointers that implement the functionality of exported_func1 and exported_func2? In other words, is it possible to reverse the direction of the dependency? – Ian Abbott Nov 02 '20 at 13:04
  • If you cannot reverse the dependencies, you can look-up the values of symbols exported by other loaded modules using the `symbol_get(x)` macro, e.g.: `my_func1_ptr = symbol_get(exported_func1);`. If the symbol is found (`my_func1_ptr` is non-null), the call should be paired with a call to `symbol_put(my_func1_ptr);` when the symbol is no longer required (for example when unloading the module). – Ian Abbott Nov 02 '20 at 13:26
  • "Every time the kbuild determines that `modA.ko` is dependent on `modB.ko`." - What is a problem in having such dependency from kbuild? You don't want to rebuild `modB.ko` every time you build `modA.ko`? Or what? – Tsyvarev Nov 02 '20 at 18:49
  • @Tsyvarev The question concerns module load dependencies rather than build dependencies. – Ian Abbott Nov 03 '20 at 16:33
  • How would depmod know what to put in the modules.symbols (and modules.symbols.bin) file if you have two modules exporting the same symbols? – Ian Abbott Nov 03 '20 at 16:39
  • I guess, it binds the one it finds first. Qs a workaround, I have disabled ModB.ko in buidroor configuration and MobA is not auto linked to ModC.ko – weja Nov 03 '20 at 16:41
  • @IanAbbott: I asked for elaboration because Kernel build system (**kbuild**) is only responsible for **building** the modules. The phrase "Every time the kbuild determines" is not quite correct: It is `depmod` utility which collects **dependencies** between modules and allows `modprobe` to load these dependencies automatically. – Tsyvarev Nov 04 '20 at 22:31
  • Answering my own "How would depmod know... ?" question above, I understand this depends on the order the modules are listed in the Makefile (and consequently listed in the "modules.order" file in the module build directory). (See description of modules.order in [Kbuild](https://www.kernel.org/doc/html/latest/kbuild/kbuild.html).) – Ian Abbott Nov 05 '20 at 10:29

0 Answers0