views:

225

answers:

4

Hello,

What are the ways to communicate with a kernel module from user space? By communication i mean sending information and commands between the module and a user space process.

I currently know of two way:

  1. open/close/read/write/ioctl on published device node.
  2. read/write on exported and hooked /proc file.

More specifically, can someone advice the best way to communicate with a kernel module that does not actually drives any hardware and therefore should not be littering /dev with stub nodes that exists solely for ioctl calls? I mostly need to check its various status variables and send it a block of data with a request type tag and see if the request succeeded.

Inso.

+1  A: 

Third one is add a new syscall, but the two you have written are the preferred ones, I think. I've found this document that might help, but I still think this option is unadvised: http://www.csee.umbc.edu/courses/undergraduate/CMSC421/fall02/burt/projects/howto_add_systemcall.html

Another acceptable option might be sharing memory.

fortran
I know about replacing a syscall by patching the table, but how do i add a new one?
Inso Reiges
I think I read about that in Linux Device Drivers book once, let me take a look...
fortran
Adding new syscalls is strongly discouraged by kernel developers. In newer kernels they have deliberately made it more difficult.
Eric Seppanen
@Eric yes, that's the idea I had... I just wanted to show that the option was still there, but remarking that the other options are better.
fortran
+2  A: 

You could also read/write from /dev device nodes.

IMHO, /dev is already littered with stuff and adding your own nodes there isn't a big issue. Don't forget that you can have lots of ioctl codes for a single device node, and the ioctl paramters are passed by reference so can be as big as you like.

Artelius
+3  A: 

There's also the /sys filesystem (sysfs):

Sysfs exports information about devices and drivers from the kernel device model to userspace, and is also used for configuration.

(from Wikipedia)

UncleZeiv
+1  A: 

Netlink sockets are designed for that kind of requirements, too...

Also see

filofel
I've never heard about netlink socket interface, thanks.
Inso Reiges