Search code examples
kernel-modulenetfilter

Some question about kernel object


I'm writing a kernel object (.ko file, which is usually device driver) of Linux.
I have to use some mechanism to protect the critical section in this project, but I'm quite confused about the kernel object.

After using insmodto insert my module into the kernel, I can't find the process of the module by using the command ps -A.
Does this mean the IRQ will evoke the module processes so that I have to use mutex to synchronize them?

In addition
It's a little unclear so that I would like to specify the question. This kernel object is for packet filtering, it's based on netfilter.
My confusion is: will every packet start a process of my module so that I have to use mutex to synchronize them, or some other things will happen when the packets arrive my local NIC?


Solution

  • Unless you start a kthread in your module there will be nothing listed in ps -A as far as I know. Kernel objects will not start any processes, in fact the functions which insert and remove modules are ran in an interrupt context (If I'm not mastaken).

    Anyway, I'm assuming you've programmed a bunch of callbacks, registered them with Netfilters and every time a packet is processed by the kernel these callbacks will be called. And this is what you mean by "a packet starting a process". Well, no because netfilter's registered callbacks are also ran from an interrupt context, thus there is no process notion here. What it means is that, depending in which hook point (local in, local out, forward...) you've registered the callback , every packet may trigger an interrupt. This is why in my personal opinion you should try to make your code do as little as possible in a netfilter hook.

    Finally, you cannot use mutexes nor semaphores in interrupt context because that will lock entire Kernel. If you really need to synchronize something in interrupt context you should look at something called spin locks http://www.mjmwired.net/kernel/Documentation/spinlocks.txt .

    Hope this helps.