Re: [PATCH RFC 7/7] libfs: Re-arrange locking in offset_iterate_dir()

From: Jan Kara
Date: Mon Feb 19 2024 - 13:06:57 EST


On Fri 16-02-24 11:33:18, Liam R. Howlett wrote:
> * Jan Kara <jack@xxxxxxx> [240216 05:15]:
> > > If you have other examples you think are unsafe then I can have a look
> > > at them as well.
> >
> > I'm currently not aware of any but I'll let you know if I find some.
> > Missing xas/mas_pause() seems really easy.
>
> What if we convert the rcu_read_lock() to a mas_read_lock() or
> xas_read_lock() and we can check to ensure the state isn't being locked
> without being in the 'parked' state (paused or otherwise)?
>
> mas_read_lock(struct ma_state *mas) {
> assert(!mas_active(mas));
> rcu_read_lock();
> }
>
> Would that be a reasonable resolution to your concern? Unfortunately,
> what was done with the locking in this case would not be detected with
> this change unless the rcu_read_lock() was replaced. IOW, people could
> still use the rcu_read_lock() and skip the detection.

Yes, I guess this is still better than nothing.

> Doing the same in the mas_unlock() doesn't make as much sense since that
> may be called without the intent to reuse the state at all. So we'd be
> doing more work than necessary at the end of each loop or use.

Yes, understood.

Honza

--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR