Difficulty loading updated driver (loadable kernel module)

Latest response

I have custom pcie hardware and driver. When I remake the driver, I'm having difficulty loading the correct, newly built driver (loadable kernel module).

Specifically, the only way I've been able to make sure the correct, newly built module was loaded has been to reboot my RHEL 7 after the build. I would prefer to be able to remove and re-insert it.

Note that this module consists of two separate .ko files, call them funkyone.ko and funkytwo.ko. Note that funkytwo.ko has some EXPORT_SYMBOL functions that are called by funkyone.ko. If they aren't already loaded, I use "sudo modprobe funkyone", which loads not only funkyone.ko but also the funkytwo.ko referenced by funkyone.ko.

Note that part of the build process is to "install" them to the /lib/modules/.../kernel/drivers/char folder.

Note that when the physical computer is rebooted, both modules are automatically loaded. So if I do a make with install, and then reboot, the subsequent behavior under test confirms that the loaded modules are indeed the recently built ones.

HOWEVER... If I do "sudo rmmod funkyone" followed by "lsmod | grep funky", I see that both have been removed. I then make and install after the rmmod. I then do "sudo modprobe funkyone" again, expecting the newly built .ko's to be loaded. However, testing behavior shows me that they are NOT, and that the loaded modules are the one prior to the make and install. This turns out to be the case even if I first manually delete them from the /lib/modules/.../kernel/drivers/char folder and do a make clean, which should leave no old copies around to have been loaded. It's as if the rmmod, proven to work by by lsmod, isn't really removing them but leaving them on the sidelines cached somewhere to be reloaded.

Note, I've tried insmod instead of modprobe, with the same results.

Help, please!

Responses

SOLVED.

Let me change my example names from funkyone.ko and funkytwo.ko to funkyone.ko and wierdtwo.ko.

When I did "sudo modprobe funkyone.ko", it loaded BOTH funkyone.ko and wierdtwo.ko, due to external references. I confirmed they were both loaded by using "lsmod | grep funky". This got the funkyone.ko line because the driver name started with "funky". This also got the wierdtwo.ko line because that driver had a reference with funkyone.ko and therefore "funky" was also on that line.

When I did "sudo rmmod funkyone.ko", they both went away and "lsmod | grep funky" showed nothing. However, they did NOT both go away. wierdtwo.ko remained loaded. The reference with funkyone.ko did go away, and so that line in the lsmod output no longer had "funky" on the line. Therefore, "lsmod | grep funky" no longer showed it. In my ignorance, since the modprobe of funkyone.ko loaded both drivers, I though the rmmod of funkyone.ko was removing both. Wrong.

As a result, I was never actually removing wierdtwo.ko. That's why the only way I could get the behavior of wierdtwo.ko to change was to reboot. That definitely removed it!

I discovered this while working on a separate driver wierdoh.ko. I did "lsmod | grep wierd" and discovered that wierdtwo.ko was still loaded. I separately rmmod'd it, and things began to behave as I expected.

The lesson I learned are: (1) Even though modprobe might load two inter-referencing drivers, rmmod doesn't remove them both. And (2) doing "lsmod | grep pattern" won't catch the other driver if the reference is now gone.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.