Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Currently I am using Wind River Linux distribution OS with kernel version 2.6.27.39 and Wind River version pne-3. After loading of my kernel module, I found it was permanent in the kernel using lsmod (for ex see below Ref 1). When I tried to remove, it was displaying as “ERROR: Removing 'hsl_module': Device or resource busy”. For your information, the same module is working fine with the Wind River pne-2 Linux Distribution OS with kernel version 2.6.21.
From the kernel source, I came to know that only possibility of showing permanent is “if there is non-availability of cleanup_module with the availability of init_module”.
But in my case, cleanup module also available in memory, after loading the module. I used to check using the file in /proc/kallsyms for the availability of cleanup module in memory.
Thanks for reading. Prompt reply is expected to identify the root cause.
Ref 1:
Module Size Used by
hsl_module 530454 0 [permanent]
Doubting of compiler flags regarding memory optimizations
hsl module has some dependency on another modules. But, I am sure that there is no problem with dependency because I have done a sample module having the same instructions used in hsl init and cleanup module and its working fine. Currently I have doubts on Makefile and the compiler flags used. I had the thought that some optimization was done during compilation which lead to discarding of the cleanup module from the memory.
Identified the reason but not solution still - need your assistance
After more debugging, I have identified root cause for the problem. The problem is, in the executable file(.ko) created, does not have ".rela.init.text and .rela.exit.text" in section headers which are responsible for starting address of init module and cleanup module correspondingly, used by the kernel for linking and relocation during loading of kernel module. But still I am searching for solution because I don't know the exact flag to be specified during compilation to get those section headers.
For your information, I have used the command 'readelf -a <file>.ko' to get the headers and symbol table of the executable created.
Define 'USE_IMMEDIATE' to get rid of this permanent issue
Thanks for your suggestion. Finally, I identified the solution for the permanent issued I faced after loading my kernel module. The solution is the kernel macro; 'USE_IMMEDIATE' has to be defined (to be given as -DUSE_IMMEDIATE along with compiler flags) during compilation of my module. Actually, I don't know much deep about the usage of this kernel macro and how it resolves the issue, but one thing I came to know that it was used during module relocation while inserting the module. If anyone help me to get know much about it, then it will be fine. Also, for your information, I have used my own Makefile for compilation of kernel loadable modules. So, I have to add myself this macro to get rid of this permanent issue. Another fine solution is, you can make use of kernel build Makefile itself (if linux kernel version is above 2.4) to build your kernel loadable modules. Because it itself include all default macros and flags needed for compilation of your module. I have specified below the sample Makefile for compiling kernel loadable modules with kernel build Makefile.
Reference:
obj-m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.