Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inter-module communication in Linux kernel

Tags:

linux

kernel

I have two Linux kernel modules, one of which may provide some function to another. But use of that function is not essential, the second module may (and should) work even if the first module is not present.

If I just export the function from the first module and use it in second module, the second module depends on that symbol and can't be loaded without first module.

One of the solutions is to have user script that looks into /proc/kallsym for the function in the first module, and if it's present there, the script passes its address as a parameter to the second module, which then makes pointer out of it. But I don't like that solution for obvious reasons.

If there more correct and elegant solution that will allow second module go get address of some symbol in the first module, but avoid hard dependency ?

like image 821
Eugene Avatar asked Mar 29 '13 08:03

Eugene


2 Answers

Finally I've found the solution: kernel has symbol_get() and symbol_put() which give me the opportunity to lookup arbitrary symbol in another module (it needs to be exported, of course) and prevent module from unloading while I'm using its symbol.

like image 61
Eugene Avatar answered Oct 11 '22 09:10

Eugene


I think if module B depends on module A, the module B can not be successfully loaded without module A is loaded first.

In fact, only after module A inserted first, the symbols which module B needed which exported from module A will appear in the /proc/kallsym file.

The solution to your situation: in module B, module_init() function should have some codes to check the module A is already there or not, if not, load A first. i.e. Using request_module() to load A, or create a more fancy method to using try_then_request_module().

like image 40
tian_yufeng Avatar answered Oct 11 '22 09:10

tian_yufeng