Saturday, March 27, 2021

Communication method between user space and kernel space and how those are implemented

 There are couple of well known methods to communicate from user space to kernel space.

  • Virtual file system like  /proc, /sys, configfs, /debugfs
  • Standard system call like read(),write(), open(), close(), fork()
  • ioctl for char drivers. With copy_to_user and copy_from_user
  • netlink socket
  • Use udev and uevent based event mechanisim from kernel space to user space.  Read more https://stackoverflow.com/a/23149574/775964
  • Sending signal from kernal space to user space thread. Full example at https://embetronicx.com/tutorials/linux/device-drivers/sending-signal-from-linux-device-driver-to-user-space/
  • Using common memory which can be used by user space/kernel space both like ION memory or DMABuf  read more here https://lwn.net/Articles/480055

Above listed all method's implemetation use below method to invoke any remote procedure call from user space memory to kernel space memory.

Until some time back, linux used to implement system calls on all x86 platforms using software interrupts. To execute a system call, user process will copy desired system call number to %eax and will execute 'int 0x80'. This will generate software interrupt 0x80 and an interrupt service routine will be called. For interrupt 0x80, this routine is an "all system calls handling" routine. This routine will execute in ring 0. This routine, as defined in the file /usr/src/linux/arch/i386/kernel/entry.S, will save the current state and call appropriate system call handler based on the value in %eax.

 this software interrupt method was much slower on Pentium IV processors. To solve this issue, Linus implemented an alternative system call mechanism to take advantage of SYSENTER/SYSEXIT instructions provided by all Pentium II+ processors.

Read more at http://articles.manugarg.com/systemcallinlinux2_6.html

No comments:

Post a Comment