Re: [PATCH] locking/rwsem: Remove unnessary check in rwsem_down_read_slowpath()

From: Tang Yizhou
Date: Fri Nov 10 2023 - 12:46:35 EST


On Thu, Nov 9, 2023 at 11:17 AM Haifeng Xu <haifeng.xu@xxxxxxxxxx> wrote:
>
> reader writer reader
>
> acquire
> release
> rwsem_write_trylock
> set RWSEM_WRITER_LOCKED
> rwsem_down_read_slowpath
> set owner
>
> If prev lock holder is a reader, when it releases the lock, the owner isn't cleared(CONFIG_DEBUG_RWSEMS isn't enabled).
> A writer comes and can set the RWSEM_WRITER_LOCKED bit succsessfully, then a new reader run into slow path, before
> the writer set the owner, the new reader will see that both the RWSEM_READER_OWNED bit and RWSEM_WRITER_LOCKED bit are
> set.
>

For the above example, it won't cause a problem. When the writer
successfully sets RWSEM_WRITER_LOCKED, the reader, when reading rcnt
through rwsem_down_read_slowpath(), will see that rcnt is 0 and will
jump to the queue label.

Thanks,
Tang