In Linux kernel, to store the memory regions of a process, Linux uses both a linked list and a red-black tree. find_vma is a function which locates the first memory region whose vm_end field is greater than the passed address through red black tree. However, I find it there is has no protection (like a lock) for the red black tree inside find_vma(). What if another thread calls rb_erase function to delete some element on the tree at the same?
Yes , find_vma function call is protected from concurrent access via semaphore. In scheduler also function is used with semaphore calls.
2209 down_read(&mm->mmap_sem);
2210 vma = find_vma(mm, start);
....
up_read(&mm->mmap_sem);
mmap_sem is used to protect this function call which is a read-write semaphore.
struct rw_semaphore mmap_sem; defined inside struct mm_struct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With