Take the 2-minute tour ×

I am a beginner of kernel programming. I just need some inspiration. I know I can write some functions in the kernel source, rebuild and reboot the kernel. The codes might be some hardware driver controlling the hardware. But how can our user space program use those functions? I know through syscall the user space program can communicate with kernel space, and the loadable kernel module can also use the functions defined in kernel source code. But how can our user program achieve this?

PS： Now I am learning qemu-kvm. I know qemu is a user space program and kvm is kernel. I just want to figure out how qemu program uses kvm.

I know this is a very basic linux kernel programming problem but it confuses me for a long time. Can someone give me a hint? :>

share|improve this question
Means of kernel/userspace communication aside from syscalls are the /proc filesystem and device files in /dev. –  Niklas B. Apr 14 '12 at 22:48
I guess that qemu-kvm uses netlink to communicate kernel <=> user space. –  strkol Apr 14 '12 at 22:49
@strkol: What's netlink? –  Niklas B. Apr 14 '12 at 22:50
Think about it as a socket communication between kernel and user space. Check people.ee.ethz.ch/~arkeller/linux/… for more information. –  strkol Apr 14 '12 at 22:52
@strkol: Thanks for the link and the explanation :) –  Niklas B. Apr 14 '12 at 22:56
show 4 more comments

1 Answer

up vote 2 down vote accepted

You shouldn't insert a new syscall if you are programming a driver. New syscalls are usually a bad idea, you should have a very good reason to do it, and a hardware driver is not good one. You have to register your driver as char device, block device or network device. I recommend you the "Linux Device Driver" book (which is legally available on the Internet) to see examples of different type of drivers.

And about your question of how you can call a function in the kernel from userspace... there is no direct way to do it, you can't link userspace code with the kernel like you do with a library. First, you have to register your function as syscall and then call the syscall with the syscall() function.

Here is a good howto explaining it: http://www.tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/

share|improve this answer
add comment

Your Answer


