2002-12-23 13:30:30

by Adam J. Richter

[permalink] [raw]
Subject: RFC/Preliminary patch - simpler raceless module unloading

Here is a completely untested patch to illustrate a simpler
way to raceless module unloading. Code that uses this scheme does
not have to deal with the possibilty of try_module_get failing, and,
if all users of the old mechanism are converted, we will be able
to delete the new most fundamental type of locking primitive code
in kernel/module.c.

I've kept this code mostly separated in <linux/module_rwsem.h>
and kernel/module_rwsem.c so that it will not necessitate pulling
<linux/module.h> into more include files and it should be more
portable across different module loading schems.

The basic theory of operation is that the data structure for
looking up a given type of driver by name or number should be
protected by an rw_semaphore (e.g., registering a file system type,
finding a file system type by name). When a driver is registered, it
call register_module_rwsem to associate to tell the module system that
it needs to acquire a write lock on the given rwsem before attempting
to remove the module (or checking its reference count for that
purpose). The get_foo_driver_by_name(name) and put_foo_driver(driver)
routines take a read lock on the rw_semaphore (or assume that they are
called with the read lock held) while they look up the driver and
manipulate its module reference count. register_foo_driver a takes a
write lock on the rw_semaphore (or requires the caller to be holding a
write lock on it). unregister_foo_driver assumes that the caller
already holds a write lock on the semaphore because sys_delete_module
already acquirs all of the rwsem's that were registered for a given
module by register_module_rwsem. As a result, no attempt to look
up a driver by name or modify its reference count can overlap
with the part of sys_delete_module that checks the module reference
count through completion of the module's unload routine.

I plan to port net_device, filesystem, file_operations,
block_device_operations, and device_driver to use it. So if what
I've described above is too verbose, it should become clearer once
I post some ports of code to it.

--
Adam J. Richter __ ______________ 575 Oroville Road
[email protected] \ / Milpitas, California 95035
+1 408 309-6081 | g g d r a s i l United States of America
"Free Software For The Rest Of Us."


Attachments:
(No filename) (2.30 kB)
mod_rwsems.diff (6.83 kB)
Download all attachments

2002-12-23 14:58:19

by Adam J. Richter

[permalink] [raw]
Subject: Re: RFC/Preliminary patch - simpler raceless module unloading

I wrote:
> I plan to port net_device, filesystem, file_operations,
> block_device_operations, and device_driver to use it. So if what
> I've described above is too verbose, it should become clearer once
> I post some ports of code to it.

Here is a preliminary port of fs/filesystems.c, although I have
not done the clean-ups it enables. I am running it now and have verified
that I can at least load and unload a filesystem module and that I'm
still prevented from unloading a filesystem module that is in use.

Adam J. Richter __ ______________ 575 Oroville Road
[email protected] \ / Milpitas, California 95035
+1 408 309-6081 | g g d r a s i l United States of America
"Free Software For The Rest Of Us."


Attachments:
(No filename) (780.00 B)
fs.diff (3.91 kB)
Download all attachments