LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   When insmodding I get a "function not implemented" message (https://www.linuxquestions.org/questions/programming-9/when-insmodding-i-get-a-function-not-implemented-message-874875/)

eantoranz 04-13-2011 06:17 PM

When insmodding I get a "function not implemented" message
 
Hi!

I have built a module to load it on a UML instance running a different kernel from the one I'm running on the host host. I have built the module against the headers for the kernel I'm using on the guest but when I try to insmod the module (on the guest, of course), I get a "function not implemented" message.

Can insmod be a little more verbose about the function that is not implemented? I tried running strace on the insmod but the error comes from init_module so not much more information is available:

Code:

open("r5r.ko", O_RDONLY)                = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\1\0\3\0\1\0\0\0\0\0\0\0\0\0\0\0\220"..., 16384) = 12605
read(3, ""..., 3779)                    = 0
close(3)                                = 0
init_module(0x804a060, 12605, "chunkSize=65536 algorithm=ls dis"...) = -1 ENOSYS (Function not implemented)
write(2, "insmod: error inserting 'r5r.ko':"..., 62insmod: error inserting 'r5r.ko': -1 Function not implemented
) = 62
exit_group(1)                          = ?

I tried to list all symbols defined in the running kernel (/proc/kallsyms) and then trying to find the symbols defined in the module with nm and checking which are missing from kallsyms but there are too many so I think it's a problem with my method to find them... can you tell me another hack for it?

Code:

$ nm r5r.ko | while read a b c; do if [ "$c" == "" ]; then simbolo=$b; else simbolo=$c; fi; lineas=$( grep $simbolo simbolos.txt | wc -l ); if [ $lineas == 0 ]; then echo Symbol $simbolo is not defined; fi; done
Symbol Queue is not defined
Symbol ____versions is not defined
Symbol __mod_algorithm56 is not defined
Symbol __mod_algorithmtype55 is not defined
Symbol __mod_author26 is not defined
Symbol __mod_capacity60 is not defined
Symbol __mod_capacitytype59 is not defined
Symbol __mod_chunkSize54 is not defined
Symbol __mod_chunkSizetype53 is not defined
Symbol __mod_description27 is not defined
Symbol __mod_diskFiles58 is not defined
Symbol __mod_diskFilestype57 is not defined
Symbol __mod_license25 is not defined
Symbol __mod_srcversion54 is not defined
Symbol __mod_vermagic5 is not defined
Symbol __module_depends is not defined
Symbol __param_algorithm is not defined
Symbol __param_arr_diskFiles is not defined
Symbol __param_capacity is not defined
Symbol __param_chunkSize is not defined
Symbol __param_diskFiles is not defined
Symbol __param_str_algorithm is not defined
Symbol __param_str_capacity is not defined
Symbol __param_str_chunkSize is not defined
Symbol __param_str_diskFiles is not defined
Symbol __this_module is not defined
Symbol algor is not defined
Symbol algorithm is not defined
Symbol chunkSize is not defined
Symbol cleanup_module is not defined
Symbol closeOpenFiles is not defined
Symbol diskFiles is not defined
Symbol diskNum is not defined
Symbol loadedChunk is not defined
Symbol majorNumber is not defined
Symbol param_array_ops is not defined
Symbol param_ops_charp is not defined
Symbol param_ops_int is not defined
Symbol r5r_loadChunkFromDisk is not defined
Symbol r5r_ops is not defined
Symbol r5r_request is not defined

Thanks in advance for any help you could provide.

Aquarius_Girl 04-15-2011 03:24 AM

Don't you get an option, while compiling the kernel, named "Enable loadable module support"?

eantoranz 04-15-2011 08:12 AM

Anisha, thanks for your feedback.

Well, well.... very interesting stuff from the module side. I don't know if the kernel I'm playing with was built with module support because I downloaded it from internet.... now, I just checked and lsmod on the UML guest shows this:

Code:

# lsmod
Opening /proc/modules: No such file or directory

And the file modules is not present on the /proc fs, indeed. Does that mean support for modules was not included when building that kernel?

Now, another thing I noticed is that when you build stuff like modules for the kernel, ARCH=um has to be set, right? So I tried building my module with ARCH=um included in the make command and now I get a lot of errors:

Code:

$ LANG=en make
make -C /lib/modules/2.6.38-2-generic/build M=/home/antoranz/proyectos/r5r/module modules ARCH=um
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-2-generic'
  CC [M]  /home/antoranz/proyectos/r5r/module/r5r.o
In file included from /usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/vm86.h:130,
                from /usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/processor.h:10,
                from include/linux/prefetch.h:14,
                from include/linux/list.h:7,
                from include/linux/module.h:9,
                from /home/antoranz/proyectos/r5r/module/r5r.c:8:
/usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/ptrace.h: In function 'user_mode':
/usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/ptrace.h:164: error: 'SEGMENT_RPL_MASK' undeclared (first use in this function)
/usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/ptrace.h:164: error: (Each undeclared identifier is reported only once
/usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/ptrace.h:164: error: for each function it appears in.)
/usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/ptrace.h:164: error: 'USER_RPL' undeclared (first use in this function)
/usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/ptrace.h: In function 'user_mode_vm':
/usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/ptrace.h:173: error: 'SEGMENT_RPL_MASK' undeclared (first use in this function)
/usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/ptrace.h:174: error: 'USER_RPL' undeclared (first use in this function)
In file included from /usr/src/linux-headers-2.6.38-2-generic/arch/um/include/asm/thread_info.h:12,
                from include/linux/thread_info.h:56,
                from /usr/src/linux-headers-2.6.38-2-generic/arch/um/include/asm/current.h:9,
                from /usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/processor.h:15,
                from include/linux/prefetch.h:14,
                from include/linux/list.h:7,
                from include/linux/module.h:9,
                from /home/antoranz/proyectos/r5r/module/r5r.c:8:
/usr/src/linux-headers-2.6.38-2-generic/arch/um/include/asm/page.h: At top level:
/usr/src/linux-headers-2.6.38-2-generic/arch/um/include/asm/page.h:14: warning: "PAGE_SIZE" redefined
/usr/src/linux-headers-2.6.38-2-generic/arch/x86/include/asm/page_types.h:8: note: this is the location of the previous definition
/usr/src/linux-headers-2.6.38-2-generic/arch/um/include/asm/page.h:22: fatal error: sysdep/vm-flags.h: No such file or directory
compilation terminated.
make[2]: *** [/home/antoranz/proyectos/r5r/module/r5r.o] Error 1
make[1]: *** [_module_/home/antoranz/proyectos/r5r/module] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-2-generic'
make: *** [all] Error 2

I think there are more lessons to be learned before I'm able to load my module.

---------- Post added 04-15-11 at 10:12 AM ----------

Keep in mind I'm building the module on the host, not the UML guest.

Aquarius_Girl 04-15-2011 08:26 AM

Quote:

Originally Posted by eantoranz (Post 4325421)
And the file modules is not present on the /proc fs, indeed. Does that mean support for modules was not included when building that kernel?

I have read, that the option of "support for loadable modules" is enabled by default, on distributions like OpenSuse, which I think is true, since I never faced any such problems before. I did guess that you must have downloaded the kernel from the net, anyway, now instead of wasting further time by "guessing" things, I think it is better to recompile the kernel ensuring that that option is enabled, just to be sure.

Quote:

Keep in mind I'm building the module on the host, not the UML guest.
I can't comment anything on this issue.

P.S.
lsmod works fine on Slackware 13.1 (default kernel)
and /proc/modules is also present here.

eantoranz 04-15-2011 08:29 AM

Yes... sounds like I'll have to get my hands dirty and build my own kernel for UML. :-)

I'll feedback after I do it during the weekend. Thanks for your help!

eantoranz 04-15-2011 07:39 PM

Well, well. I have already rebuilt the UML kernel by hand (2.6.38.3, by the way) and apparently the one I downloaded off internet didn't have module support built in because in the one I created I do have it.... so after rebuilding my module against the 2.6.38.3 source I was able to load it.... and now the UML kernel is facing an infinite loop after insmodding so I guess I have to start learning how to debug kernel modules. :-)

Anisha, as usual, very very helpful! Thanks!

Aquarius_Girl 04-15-2011 08:44 PM

Quote:

Originally Posted by eantoranz (Post 4325959)
and now the UML kernel is facing an infinite loop after insmodding so I guess I have to start learning how to debug kernel modules.

You've put some loops in the kernel module? or you re not able to rmmod it? Anyway, new thread for a new question, BTW, the Kernel debugger is called KDB and its links has been included in the sticky in the Kernel section, if you need it.

Quote:

Originally Posted by eantoranz (Post 4325959)
Anisha, as usual, very very helpful! Thanks!

I am happy I could help.

eantoranz 04-15-2011 09:36 PM

It's a module problem.


All times are GMT -5. The time now is 11:31 PM.