Re: Buggy rwsem locking code in fs/smb/client/file.c

From: David Wysochanski
Date: Mon Jul 03 2023 - 14:47:53 EST


On Mon, Jul 3, 2023 at 1:00 PM Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Mon, 3 Jul 2023 at 08:43, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> >
> > And hides the bug by wrapping the down_write() with:
> >
> > +void
> > +cifs_down_write(struct rw_semaphore *sem)
> > +{
> > + while (!down_write_trylock(sem))
> > + msleep(10);
> > +}
>
> That is indeed disgusting.
>
> It may *work* - because as the commit message says, it means that
> writers are now never queued up and thus never block recursive
> readers.
>
> And in the process it now becomes absolutely horribly unfair to
> writers, who will easily get starved by readers.
>
> This is absolutely not acceptable in any sane situation. Are writers
> *so* rare and special that starving them is ok?
>
> Because starvation can be just as deadly as a deadlock. You're just
> hiding the problem from lockdep and yourself.
>
> This is very much a "head in the sand" solution.
>
> Linus
>

Steve and Linus,

Thank you for pointing this out. I'll have to get with Ronnie on this
and come up with something better.