Re: How to unload a buggy LKM without rebooting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 18, 2002 at 10:01:00AM +0530, Nagaraj wrote:
> > I am debugging a kernel module. Any error in it is easy to make
> > the module unloadable ( complaining: Device or resource busy).
> > Is there anyway to unload a sick LKM without rebooting?
> When u r developing the module, dont use 
> MOD_INC_USE_COUNT and DEC counts.
> 
> When ur application crashes, it wont complain about
> module being busy. 
> 
> Once ur module is entirely tested, u keep these
> in open and closes.
> 
> However this is not a solution if ur module itself 
> has some bugs and lets say crashes during 
> init_module().
> 
> How do we cleanup such things ??? 

MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT are incorrect on SMP. That is,
if they are called from the module, there is a race condition.

Thus owner member was introduced to all kinds of structures that have
some methods or callbacks on them, like inodes, files and such. It's the
generic kernel function that calls MOD_(INC|DEC)_USE_COUNT on the owner.
So if you miscount these structures, you get your module miscounted too.

I have seen many really strange failures when I miscounted inodes or
files. So if the bug is of this sort, the kernel will self destruct in
few seconds anyway.

Anyway, such module may be unloaded using kgdb, or maybe even gdb on
/proc/kcore - you zero out the counter manually. Or you can write
a simple module, that will zero the count (it will only have the init
function, which will return error at the end, so nothing will be actualy
loaded).

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux