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

From: Linus Torvalds
Date: Mon Jul 03 2023 - 13:00:37 EST


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