Multiple user processes accessing kernel linked li

2019-08-22 06:39发布

问题:

I have 10 user space application which could invoke the same system call to kernel. For example 10 user space program could invoke bind system call.

Upon receiving the system call, my code in the kernel would insert a data in linked list I created in the kernel space. I am using kernel linked list to add, remove and traverse node. I am also locking the node before writing to prevent the scenario where the list is not corrupted when accessed simultaneously by different user space processes.

I am concerned that when any of these 10 processes invokes system call to the kernel space, the corresponding the kernel thread of a user process doesn't know how to access the custom list head and update the list.

The reasoning behind this concerns is that the system call are not atmoic, i.e 10 user application can be started at a same time but there is no guarantee that the one that was started first is going to run and complete first. How does the corresponding kernel thread know which kernel list to update which can also be updated by 9 other kernel thread.

In nutshell, Is my concern valid? if yes, how do I make sure that the same kernel linked list can be accessed by the kernel threads without any issues of concurrency and race condition issues? Do I need to create a shared linked list inside kernel so that the kernel thread/user process that it needs to get access to the specific list and update that only? If my concern is valid please provide me information how to implemented shared kernel linked list?