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

From: Marco Elver
Date: Thu May 02 2024 - 10:15:14 EST


On Wed, 1 May 2024 at 23:06, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Wed, 1 May 2024 at 13:15, Marco Elver <elver@xxxxxxxxxx> wrote:
> >
> > This is relatively trivial:
> >
> > #ifdef __SANITIZE_THREAD__
> > #define __data_racy volatile
> > #endif
>
> I really wouldn't want to make a code generation difference, but I
> guess when the sanitizer is on, the compiler generating crap code
> isn't a huge deal.
>
> > In some cases it might cause the compiler to complain if converting a
> > volatile pointer to a non-volatile pointer
>
> No. Note that it's not the *pointer* that is volatile, it's the
> structure member.
>
> 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.
>
> Of course, if somebody then does "&file->f_op" to get a pointer to a
> pointer, *that* would now be a volatile pointer, but I don't see
> people doing that.

This is the case I thought of. I still think everything is working as
intended then, since passing a pointer to a __data_racy variable
should be done with pointers to __data_racy (just like other type
qualifiers - the rules are by virtue of implementation equivalent to
volatile). Not a problem, just an observation.

> So I guess this might be a way forward. Anybody want to verify?

I sent a patch to add the type qualifier - in a simple test I added it
does what we want:
https://lore.kernel.org/all/20240502141242.2765090-1-elver@xxxxxxxxxx/T/#u

I'll leave it to Tetsuo to amend the original patch if __data_racy makes sense.

Thanks,
-- Marco

> Now, the "hung_up_tty_fops" *do* need to be expanded to have hung up
> ops for every op that is non-NULL in the normal tty ops. That was a
> real bug. We'd also want to add a big comment to the tty fops to make
> sure anybody who adds a new tty f_op member to make sure to populate
> the hung up version too.
>
> Linus