ritesh ghosh
BAN USERi think by i2c_transfer() if the device is connected by i2c, else outl/b() if its i/o mapped memory
- ritesh ghosh May 17, 2013it is correct, linux kernel is a single process and a monolithic kernel, but with moduled approach, also the kernel process itself can get preempted
- ritesh ghosh May 17, 2013how to make it SMP safe in user space?
in kthread context we could have used spin_lock(), but in user space what is the method to do SMP safe when we run pthread?
In kernel context, we should loop (although not recommended) through task_struct list and check whose pid matches and then check the flags of it. If its CLONE_VM | CLONE_FS | CLONE_FILE | CLONE_SIGHNDL - it means these resources are shared, so that is a thread. Else, if its only SIGCHLD, its a process.
- ritesh ghosh May 17, 2013my opinion regarding the first qstn:
fork() - it does call clone() inside it but with the flag as SIGCHLD i.e. clone(SIGCHLD, 0). So, none of the resources are shared. But, copied to child on COW basis.
pthread() - is a POSIX wrapper for clone() system call to create a thread, in this case clone is called like clone( CLONE_VM | CLONE_FS | CLONE_FILE | CLONE_SIGHNDL). So, address space, open files, file system handlers, signal handlers are shared.
vfork() - is also calling clone() similar to fork(), only difference is process address space is not copied to child and execution of parent is suspended till the execution of child. They used it before COW was introduced.
Interesting thing is all of them are calling clone() because linux kernel actually does not differentiate between process and thread except the flags - all are tasks.
one of the major requirement in system call implementation is to check the validity of user parameter pointer passed as argument, kernel should not blindly follow the user pointer as the user pointer can play tricks in many ways. Major concerns are: 1. it should be a pointer from that process address space - so that it cant get into some other process address space. 2. it should be a pointer from user space - it should not trick to play with a kernel space pointer. 3. it should not bypass memory access restrictions.
- ritesh ghosh May 22, 2013that is why copy_from_user() is performed. It is blocking and process sleeps until page fault handler can bring the page from swap file to physical memory.