Skip to contentSkip to conversation

module fs or how to not break everything at once

RFC Adam J. Richter 2 participants 2 messages Nov 22, 2002

lore
Share & tools
lore
#0 lore raw
Quoted 19 lines · Roman Zippel
Quoted 2 lines · Adam J. Richter

I meant "what real advantage does a _filesystem_ interface
give you?"

- more flexibility, you get a lot for free from libfs.c and other parts of the kernel. Check how small the modfs example is, much more isn't needed.
- no extra syscalls needed, which might have to be emulated by 64bit system. Module objects are normal files, why waste a syscall if you can just write() them to the kernel?

Quoted 7 lines

Thanks for the pointer. Looking at your mini-loader, it seems
to me that you could eliminate your modules.lds script if you would split module-init.c into module-init.c and module-finish.c, which would simplify the ability to link multiple modules together or have a module with multiple module_init() functions if we used the definition of module_init() that is used for kernel objects (more on this below).

Quoted 3 lines

The linker script will not go away, it makes the loader a _lot_ easier and I want to keep it this way. Multiple module_init() calls won't happen, don't even try it.

How does one script and one .o make the loader "a _lot_ easier"
than with two .o's?

You cannot determine technical merit ex cathedra. Obviously
you can do whatever you want with your own tree, but if you can't convince someone is basically a proponent of moving as much of the module support into user level as possible (and a moderate proponent of filesystem interfaces), then how likely do you think it is that you will convince others?

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Synchronizing multiple insmod is needed in user space anyway, this doesn't make the kernel side more complex.

Then a module_init function that may cause another module to
be loaded can deadlock. I'll have to think about whether that is a problem.

The user space locking should of course be a bit more intelligent than one big lock.

You would have provided more details you had thought this
through. Maybe you never need to do anything from a module_init function that loads another module, but, if you do, then there may not be an answer in the form of a user space locking policy, and it may necessitate moving many elements back into the kernel, such as this one:

[...]

Quoted 3 lines

The kernel doesn't need the dependency information, they can stay as well in user space. The checks currently done don't have to be done in the kernel.

That is intriguing, although it depends on whether on that user
space locking scheme working.

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

That's a mostly user space problem and I'd rather do this right, why should I keep invalid symbols?

My point was just about being resiliant against, say, someone
accidentally hitting a control-C or a kill signal during one of these programs, such as during an aborted shutdown. However, now that you mention it, it would be useful for developers to have an rmmod option to retain symbols for debugging a bad memory reference that happens after a module has been unloaded.

Quoted 3 lines

I want to keep the kernel implementation simple, this would only bloat it. Cleaning up after a signal shouldn't bother the kernel (at least as far as modfs is concerned).

User level programs cannot catch SIGKILL. I was not talking about
adding anything to the kernel.

Quoted 9 lines
Quoted 8 lines

Even if you don't want to support circular dependencies
(loading multiple .o's together) or multiple module_{init,exit} functions, having insmod load separate modules for the init and non-init parts will shrink the kernel code. It would be nice for insmod to be able to do ELF section manipulations like this also to implement things like having .exit{,func} sections that insmod could drop if it were given a flag to load the module "permanently."

Quoted 4 lines

The point of the linker script is to avoid that the loader has to play around with the sections. If you want to get rid of init data, put it at the end and truncate() it when you're done. This is trivial to do with a module fs.

If insmod knows what size to truncate the module to, then it
has at least a little code dealing with certain sections. Theoretically, it should also determine that the extable contains no pointers into .init (although in practice I believe that that is always true right now).

Small modules can potentially be allocated with kmalloc rather
than vmalloc for better memory efficiency and, I believe, so that they can live in the kernel's 4MB huge page on architectures that support it, eliminating their TLB utilization. If you allocate the init and non-init modules separately, the non-init module will more often be small enough to be allocated this way (also true of the init module, but we probably don't care much about that).

In addition to missing opportunities to use kmalloc,
implementing a truncation to a non-zero size in your modfs requires additional code, including a vmalloc_shrink (I think Keith Owens posted one). I was not aware that you even were going to provide files for writing the module's contents. That seems unnecessary. Even if you don't want a system call interface for copying the module's contents in, why can't insmod just lseek and write /dev/kmem?

[...]

Quoted 10 lines
Quoted 4 lines

An advantage of allowing circular loops is that everything
would be modularized or nearly modularized with only a few changes. For example, I want to modularize CONFIG_NET (not just CONFIG_INET). However, there is a circular reference:

You're trying to move your problems to someone else - very bad idea. If you can't get modules references right, you have very likely more problems like module initialization races. Link everything together and make the initialization explicit and don't rely on that the linker/loader gets it magically right.

First of all, you can have circular references and still have
only one module_init function. That is in fact that case with the CONFIG_NET=m example that I described and you deleted from your response--not very persuasive.

Secondly, you have not shown that these really are necessarily
always problems with cicular dependencies. They are, after all, used in the built-in kernel objects.

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

#1 lore raw

Hi,

Quoted 6 lines · Adam J. Richter
Quoted 3 lines

The linker script will not go away, it makes the loader a _lot_ easier and I want to keep it this way. Multiple module_init() calls won't happen, don't even try it.

How does one script and one .o make the loader "a _lot_ easier"
than with two .o's?

Check the previous discussions about kloader support for other archs, e.g. some have special requirements for section ordering, all this work is already done by the linker, why should I duplicate this in the loader?

Quoted 8 lines
Quoted 2 lines

The user space locking should of course be a bit more intelligent than one big lock.

You would have provided more details you had thought this
through. Maybe you never need to do anything from a module_init function that loads another module, but, if you do, then there may not be an answer in the form of a user space locking policy, and it may necessitate moving many elements back into the kernel,

I'm planning to do this with a per module locking, for every module in the kernel there is a file with symbol/dependency/... information on which you can easily use flock.

Quoted 6 lines
Quoted 3 lines

I want to keep the kernel implementation simple, this would only bloat it. Cleaning up after a signal shouldn't bother the kernel (at least as far as modfs is concerned).

User level programs cannot catch SIGKILL. I was not talking about
adding anything to the kernel.

Why would you kill insmod with SIGKILL? If you do this you likely have to cleanup manually anyway (what modfs might actually make possible).

Quoted 4 lines

If insmod knows what size to truncate the module to, then it
has at least a little code dealing with certain sections. Theoretically, it should also determine that the extable contains no pointers into .init (although in practice I believe that that is always true right now).

You're trying here to assign tasks to insmod it shouldn't know about. The more insmod knows about the module layout the harder is it to change it from the kernel side and the more you loose flexibilty.
All this can be easily done by the kernel.

Quoted 8 lines

Small modules can potentially be allocated with kmalloc rather
than vmalloc for better memory efficiency and, I believe, so that they can live in the kernel's 4MB huge page on architectures that support it, eliminating their TLB utilization. If you allocate the init and non-init modules separately, the non-init module will more often be small enough to be allocated this way (also true of the init module, but we probably don't care much about that).

Quoted 7 lines

In addition to missing opportunities to use kmalloc,
implementing a truncation to a non-zero size in your modfs requires additional code, including a vmalloc_shrink (I think Keith Owens posted one). I was not aware that you even were going to provide files for writing the module's contents. That seems unnecessary. Even if you don't want a system call interface for copying the module's contents in, why can't insmod just lseek and write /dev/kmem?

Why should all these internals be exposed to insmod? Why isn't a simple 'map this file into the kernel' interface not enough? Every change in this area requires changes to insmod, now add all backward compability code and soon you get the current insmod monster.

Quoted 6 lines
Quoted 5 lines

You're trying to move your problems to someone else - very bad idea. If you can't get modules references right, you have very likely more problems like module initialization races. Link everything together and make the initialization explicit and don't rely on that the linker/loader gets it magically right.

Quoted 8 lines

First of all, you can have circular references and still have
only one module_init function. That is in fact that case with the CONFIG_NET=m example that I described and you deleted from your response--not very persuasive.

Secondly, you have not shown that these really are necessarily
always problems with cicular dependencies. They are, after all, used in the built-in kernel objects.

Why do you want to move this problem to the module tools? As I said make this dependency explicit (either by resolving them or explicit initialization) and be done with it.
You cannot easily compare it boot initialization, e.g. net/core uses subsys_initcall, so it's initialized earlier. The network was never written as module and you are trying the easy way out by pushing the complexity to someone else. Nobody else needs this feature and there are alternative ways, so I fail to see why everyone should pay for this.

bye, Roman