[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-kernel
Subject:    Re: [PATCH v3] tty: tty_io: remove hung_up_tty_fops
From:       Marco Elver <elver () google ! com>
Date:       2024-05-02 17:20:25
Message-ID: CANpmjNPtoKf1ysbKd=E8o753JT0DzBanzFBP234VBsazfufVAQ () mail ! gmail ! com
[Download RAW message or body]

On Thu, 2 May 2024 at 18:42, Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
> 
> On 2024/05/02 23:14, Marco Elver wrote:
> > 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@google.com/T/#u
> 
> Want some updates to Documentation/process/volatile-considered-harmful.rst
> because __data_racy is for patches to add volatile variables ?

This has nothing to do with volatile. It's merely an implementation
artifact that in CONFIG_KCSAN builds __data_racy translates to
"volatile": the compiler will emit special instrumentation for
volatile accesses so that KCSAN thinks they are "marked". However,
volatile is and has been an implementation detail of certain
primitives like READ_ONCE()/WRITE_ONCE(), although as a developer
using this interface we should not be concerned with the fact that
there's volatile underneath. In a perfect world the compiler would
give us a better "tool" than volatile, but we have to make do with the
tools we have at our disposal today.

> Patches to remove volatile variables are generally welcome - as long as
> they come with a justification which shows that the concurrency issues have
> been properly thought through.

My suggestion is to forget about "volatile" and simply pretend it's
data_race() but as a type qualifier, like the bit of documentation I
added to Documentation/dev-tools/kcsan.rst in the patch.

> > 
> > I'll leave it to Tetsuo to amend the original patch if __data_racy makes sense.
> 
> 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;
> 
> u64                     f_version;
> #ifdef CONFIG_SECURITY
> 
> 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; ^~~~

Exactly as I pointed out elsewhere: pointers to __data_racy fields now
have to become __data_racy as well:

  const struct file_operations __data_racy *proxy_fops = filp->f_op;

should be what you want there. The type system is in fact helping us
here as intended. :-)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic