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:58:10AM -0700, KONG, Gangfeng wrote:
> At 10:01 AM 9/18/2002 +0530, Nagaraj wrote:
> 
> >From: "KONG, Gangfeng" <gkong@IPRG.nokia.com>:
> >> Hi,
> >>
> >> 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?
> >>
> >> Thanks
> >> GF
> >>
> >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().
> 
> Hi,
> 
> Unfortunately, my LKM is not a driver, it's extended kernel functions.
> Some memory error does happen in init_module(). I have fixed the errors,
> but every time has to reboot. I also tried to rename the LKM as john
> suggested, also doesn't work. It looks like kmem_cache_xxx functions
> keeping error status, can not self recovery.

Wait...a...moment. What is the interface to these functions? As kernel
itself is staticaly linked, these functions may either be available by
resolving from other module - in which case the calling module holds the
count just by having the names resolved, or function pointers must be in
some structure - in which case the structure must have properly used
owner field. 

Anyway, if the module screws up and cannot be unloaded, you need to
somehow need to change kernels idea of what may be unloaded. There is
a function, that, if defined, is called to tell if the module is busy.
So you can define this function to always claim module can be unloaded
during development.

Note, that if you fail to clean up things (like mem caches) in the cleanup
function, module won't load again, because some init may fail.

Also note, that unloading a module while you fail to remove all
references to it will lead to OOPS or panic sooner or later.

Consider developing the module under the user-mode-linux.
It allows to debug all the arch-independent stuff in a user-mode
process, so you just reboot the user-mode kernel (which may have almost
empty rc scripts) instead of the whole system. In addition, it's
possible to debug it using gdb (though some internal magic is involved
there). As you say that it's not a driver, this might very well be an
option for you.

-------------------------------------------------------------------------------
						 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