Re: [PATCH v3] tty: tty_io: remove hung_up_tty_fops

From: Paul E. McKenney
Date: Wed May 01 2024 - 17:49:25 EST


On Wed, May 01, 2024 at 02:20:35PM -0700, Linus Torvalds wrote:
> On Wed, 1 May 2024 at 14:06, Linus Torvalds
> <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> >
> > So it would be something like
> >
> > const struct file_operations * __data_racy f_op;
> >
> > and only the load of f_op would be volatile - not the pointer itself.
>
> Noe that in reality, we'd actually prefer the compiler to treat that
> "__data_racy" as volatile in the sense of "don't reload this value",
> but at the same time be the opposite of volatile in the sense that
> using one read multiple times is actually a good idea.
>
> IOW, the problem is rematerialization ("read the value more than once
> when there is just one access in the source"), not strictly a "read
> the value separately each time it is accessed".
>
> We've actually had that before: it's not that we want each access to
> force a read from memory, we want to avoid a TOCTOU race.
>
> Many of our "READ_ONCE()" uses are of that kind, and using "volatile"
> sadly generates horrible code, but is the only way to tell the
> compiler to not ever rematerialize the value by loading it _twice_.
>
> I'd love to see an extension where "const volatile" basically means
> exactly that: the volatile tells the compiler that it can't
> rematerialize by doing the load multiple times, but the "const" would
> say that if the compiler sees two or more accesses, it can still CSE
> them.

No promises, other than that if we don't ask, they won't say "yes".

Let me see what can be done.

Thanx, Paul

> Oh well. Thankfully it's not a hugely common code generation problem.
> It comes up every once in a while, and I think the last time this
> worry came up, I think we had gcc people tell us that they don't
> actually ever rematerialize loads from memory.
>
> Of course, that was an implementation issue, not a guarantee.
>
> Linus