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

From: Linus Torvalds
Date: Thu May 02 2024 - 13:30:25 EST


On Thu, 2 May 2024 at 09:42, Tetsuo Handa
<penguin-kernel@xxxxxxxxxxxxxxxxxxx> wrote:
>
> OK if below change is acceptable.
>
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -1012,7 +1012,7 @@ struct file {
> struct file_ra_state f_ra;
> struct path f_path;
> struct inode *f_inode; /* cached value */
> - const struct file_operations *f_op;
> + const __data_racy struct file_operations *f_op;

No, this is very wrong.

It's not the *pointer* that is __data_racy. It's the structure *fied*.

So that should be

const struct file_operations *__data_racy f_op;

which is very different.

> Hmm, debugfs assumes that f_op does not change?
>
> fs/debugfs/file.c: In function 'full_proxy_release':
> fs/debugfs/file.c:357:45: warning: initialization discards 'volatile' qualifier from pointer target type [-Wdiscarded-qualifiers]
> const struct file_operations *proxy_fops = filp->f_op;
> ^~~~

This error is a direct result of placing the __data_racy in the wrong place.

It's not that the _result_ of reading filp->f_op is racy. It's the
read of filp->f_op itself that is.

Yes, this is unusual. The *common* thing is to mark pointers as being
volatile. But this really is something entirely different from that.

Linus