Re: [PATCH 3/4] mm: replace rw_semaphore with atomic_t in vma_lock

Davidlohr Bueso
2024-11-12T00:52:42Z

On Mon, 11 Nov 2024, Suren Baghdasaryan wrote:

>@@ -787,7 +893,10 @@ static inline void vma_start_write(struct vm_area_struct *vma)
> * we should use WRITE_ONCE() for cleanliness and to keep KCSAN happy.
> */
> WRITE_ONCE(vma->vm_lock_seq, mm_lock_seq);
>- up_write(&vma->vm_lock.lock);
>+ /* Write barrier to ensure vm_lock_seq change is visible before count */
>+ smp_wmb();
>+ rwsem_release(&vma->vm_lock.dep_map, _RET_IP_);
>+ atomic_set(&vma->vm_lock.count, VMA_LOCK_UNLOCKED);

Too many barriers here. Just do atomic_set_release and remove that
smp_wmb(). And what you are doing is really ensuring nothing leaks out
of the critical region, so that comment should also be more generic.

I would expect regression testing to catch this sort of thing.

...

> #ifdef CONFIG_PER_VMA_LOCK
>+ struct wait_queue_head vma_writer_wait;

You might want to use rcuwait here instead, which is much more
optimized for the single waiter requirement vmas have.

Thanks,
Davidlohr