mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	Brian Foster <bfoster@redhat.com>,
	"Darrick J. Wong" <djwong@kernel.org>,
	Chi Zhiling <chizhiling@163.com>,
	cem@kernel.org, linux-xfs@vger.kernel.org,
	linux-kernel@vger.kernel.org, Chi Zhiling <chizhiling@kylinos.cn>,
	John Garry <john.g.garry@oracle.com>
Subject: Re: [PATCH] xfs: Remove i_rwsem lock in buffered read
Date: Mon, 20 Jan 2025 16:11:41 +1100	[thread overview]
Message-ID: <Z43bDYQ6PwklKgJ3@dread.disaster.area> (raw)
In-Reply-To: <CAOQ4uxizxUg+EXar2GzDWgp+reRZ_0wc+DAaSAGmUZ1VXOjjLw@mail.gmail.com>

On Sat, Jan 18, 2025 at 02:03:41PM +0100, Amir Goldstein wrote:
> On Fri, Jan 17, 2025 at 11:19 PM Dave Chinner
> <david@fromorbit.com> wrote:
> > On Fri, Jan 17, 2025 at 02:27:46PM +0100, Amir Goldstein wrote:
> > > On Wed, Jan 15, 2025 at 10:41 PM Dave Chinner
> > > <david@fromorbit.com> wrote: For all practical purposes, we
> > > could maintain a counter in inode not for submitted DIO, but
> > > for files opened O_DIRECT.
> > >
> > > The first open O_DIRECT could serialize with in-flight
> > > buffered writes holding a shared iolock and then buffered
> > > writes could take SH vs. EX iolock depending on folio state
> > > and on i_dio_open_count.
> >
> > I don't see how this can be made to work w.r.t. sane data
> > coherency behaviour. e.g. how does this model serialise a new
> > DIO write that is submitted after a share-locked buffered write
> > has just started and passed all the "i_dio_count == 0" checks
> > that enable it to use shared locking? i.e. we now have
> > potentially overlapping buffered writes and DIO writes being
> > done concurrently because the buffered write may not have
> > instantiated folios in the page cache yet....
> >
> 
> A shared-locked buffered write can only start when there is no
> O_DIRECT file open on the inode.  The first open for O_DIRECT to
> increment i_dio_open_count needs to take exclusive iolock to wait
> for all in-flight buffered writes then release the iolock.
> 
> All DIO submitted via O_DIRECT fds will be safe against in-flight
> share-locked buffered write.

Hooking ->open() and ->release() isn't sufficient. O_DIRECT can be
changed at any time via fcntl(F_SETFL) which isn't synchronised
against IO in progress at all. i.e. we can't track that, nor can we
even use f_ops->check_flags to reject changes to O_DIRECT state
because it doesn't pass either the filp or the inode....

IOWs, as it stands logic like "is the file opened for O_DIRECT" in
the IO path is inherently racy and the racing mechanisms are
directly under the control of unprivileged userspace applications.
Without mods from the VFS down and new hooks being implemented in
XFS along with all the whacky "which serialisiation method do we
use" logic and dealing with the complexities and switching
between them, tracking struct files that are open for O_DIRECT isn't
really a viable mechanism for enabling shared buffered writes...

-Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2025-01-20  5:11 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-26  6:16 Chi Zhiling
2024-12-26 21:50 ` Dave Chinner
2024-12-28  7:37   ` Chi Zhiling
2024-12-28 22:17     ` Dave Chinner
2024-12-30  2:42       ` Chi Zhiling
2025-01-07 12:13         ` Amir Goldstein
2025-01-07 17:12           ` Christoph Hellwig
2025-01-08  7:43           ` Chi Zhiling
2025-01-08 11:33             ` Amir Goldstein
2025-01-08 11:45               ` Amir Goldstein
2025-01-08 12:15               ` John Garry
2025-01-09 10:07                 ` Amir Goldstein
2025-01-09 12:40                   ` John Garry
2025-01-09  8:37               ` Chi Zhiling
2025-01-09 10:25                 ` Amir Goldstein
2025-01-09 12:10                   ` Chi Zhiling
2025-01-09 12:25                     ` John Garry
2025-01-08 17:35             ` Darrick J. Wong
2025-01-09 23:28               ` Dave Chinner
2025-01-10  1:31                 ` Chi Zhiling
2025-01-10 17:07                 ` Amir Goldstein
2025-01-12 10:05                   ` Chi Zhiling
2025-01-13  2:44                     ` Darrick J. Wong
2025-01-13  5:59                       ` Chi Zhiling
2025-01-13 13:40                       ` Brian Foster
2025-01-13 16:19                         ` Darrick J. Wong
2025-01-15  5:55                         ` Christoph Hellwig
2025-01-15 21:41                           ` Dave Chinner
2025-01-16  4:36                             ` Christoph Hellwig
2025-01-17 22:20                               ` Dave Chinner
2025-01-16 14:23                             ` Brian Foster
2025-01-17 13:27                             ` Amir Goldstein
2025-01-17 22:19                               ` Dave Chinner
2025-01-18 13:03                                 ` Amir Goldstein
2025-01-20  5:11                                   ` Dave Chinner [this message]
2025-01-22  6:08                                 ` Christoph Hellwig
2025-01-22 23:35                                   ` Dave Chinner
2025-01-17 16:12                             ` Chi Zhiling
2025-01-24  7:57                             ` Chi Zhiling
2025-01-27 20:49                               ` Dave Chinner
2025-01-28  5:15                                 ` Christoph Hellwig
2025-01-28 21:23                                   ` David Laight
2025-01-29  0:59                                   ` Dave Chinner
2025-01-29  5:20                                     ` Christoph Hellwig
2025-02-10  1:44                                 ` Chi Zhiling
2025-01-14  0:09                   ` Dave Chinner
2025-01-25  8:43           ` Jinliang Zheng
2025-01-25 14:14             ` Amir Goldstein
2025-06-20 14:03   ` Jinliang Zheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z43bDYQ6PwklKgJ3@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=amir73il@gmail.com \
    --cc=bfoster@redhat.com \
    --cc=cem@kernel.org \
    --cc=chizhiling@163.com \
    --cc=chizhiling@kylinos.cn \
    --cc=djwong@kernel.org \
    --cc=hch@infradead.org \
    --cc=john.g.garry@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome