All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Christian Brauner <brauner@kernel.org>,
	Christoph Hellwig <hch@lst.de>, Aleksa Sarai <cyphar@cyphar.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Seth Forshee <sforshee@kernel.org>,
	linux-fsdevel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] file: always lock position
Date: Tue, 25 Jul 2023 14:41:28 -0600	[thread overview]
Message-ID: <8d1069bf-4c0b-22be-e4c4-5f2b1eb1f7e8@kernel.dk> (raw)
In-Reply-To: <CAHk-=wg8gY+oBoehMop2G8wq2L0ciApZEOOMpiPCL=6gxBgx=g@mail.gmail.com>

On 7/25/23 12:30?PM, Linus Torvalds wrote:
> On Mon, 24 Jul 2023 at 15:57, Jens Axboe <axboe@kernel.dk> wrote:
>>
>> On 7/24/23 4:25?PM, Linus Torvalds wrote:
>>> This sentence still worries me.
>>>
>>> Those fixed files had better have their own refcounts from being
>>> fixed. So the rules really shouldn't change in any way what-so-ever.
>>> So what exactly are you alluding to?
>>
>> They do, but they only have a single reference, which is what fixes them
>> into the io_uring file table for fixed files. With the patch from the
>> top of this thread, that should then be fine as we don't need to
>> artificially elevator the ref count more than that.
> 
> No.
> 
> The patch from the top of this thread cannot *possibly* matter for a
> io_uring fixed file.
> 
> The fdget_pos() always gets the file pointer from the file table. But
> that means that it is guaranteed to have a refcount of at least one.
> 
> If io_uring fixed file holds a reference (and not holding a reference
> would be a huge bug), that in turn means that the minimum refcount is
> now two.

Right, but what if the original app closes the file descriptor? Now you
have the io_uring file table still holding a reference to it, but it'd
just be 1. Which is enough to keep it alive, but you can still have
multiple IOs inflight against this file.

Obviously using the file position is wonky with async IO to begin with,
exactly because you can have multiple IOs in flight to it at the same
time. You can make it work by specifying ordering constraints, but that
is obviously also totally messy and not really a valid use case. Just
don't use the file position at that point.

Some libraries are limited though and want to use file positions with
async IO, and they generally get to keep both pieces if they do and
don't treat it as sync IO (or serialized, at least) at that point.

> So the code in fdget_pos() is correct, with or without the patch.
> 
> The *only* problem is when something actually violates the refcounting
> rules. Sadly, that's exactly what pidfd_getfd() does, and can
> basically make a private file pointer be non-private without
> synchronizing with the original owner of the fd.
> 
> Now, io_uring may have had its own problems, if it tried to
> re-implement some io_uring-specific version of fdget_pos() for the
> fixed file case, and thought that it could use the file_count() == 1
> trick when it *wasn't* also a file table entry.
>
> But that would be an independent bug from copy-and-pasting code
> without taking the surrounding rules into account.

We never made any assumptions on the file_count() for the file, exactly
because the count of it means nothing to io_uring in terms of whether we
can have concurrent IO to it or not.

-- 
Jens Axboe


  reply	other threads:[~2023-07-25 20:42 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-24 15:00 [PATCH] file: always lock position Christian Brauner
2023-07-24 15:53 ` Linus Torvalds
2023-07-24 16:19   ` Christian Brauner
2023-07-24 16:36     ` Linus Torvalds
2023-07-24 16:51       ` Linus Torvalds
2023-09-02  4:44         ` Al Viro
2023-07-24 17:23       ` Christian Brauner
2023-07-24 17:34         ` Linus Torvalds
2023-07-24 17:46           ` Christian Brauner
2023-07-24 18:01             ` Linus Torvalds
2023-07-24 18:05               ` Jens Axboe
2023-07-24 18:27                 ` Linus Torvalds
2023-07-24 18:48                   ` Christian Brauner
2023-07-24 22:25                     ` Linus Torvalds
2023-07-24 22:56                       ` Jens Axboe
2023-07-25 18:30                         ` Linus Torvalds
2023-07-25 20:41                           ` Jens Axboe [this message]
2023-07-25 20:51                             ` Linus Torvalds
2023-07-25 20:58                               ` Jens Axboe
2023-07-26  8:36                               ` Christian Brauner
2023-07-26 10:31                                 ` David Laight
2023-07-26 12:53                                   ` Christian Brauner
2023-07-26  8:07                           ` Christian Brauner
2023-07-24 16:46   ` Christian Brauner
2023-07-24 16:59     ` Linus Torvalds
2023-07-24 17:18       ` Linus Torvalds
2023-08-03  9:53       ` Mateusz Guzik
2023-08-03 14:15         ` Christian Brauner
2023-08-03 15:17           ` Mateusz Guzik
2023-08-03 15:18             ` Mateusz Guzik
2023-08-03 15:45         ` Linus Torvalds
2023-08-03 17:54           ` Mateusz Guzik
2023-08-03 18:02           ` Christian Brauner
2023-08-03 18:35             ` Linus Torvalds
2023-08-04 13:43               ` Christian Brauner
2023-08-04 13:59                 ` Christoph Hellwig
2023-09-02  3:43               ` Al Viro
     [not found] <20230804-turnverein-helfer-ef07a4d7bbec@brauner>
2023-08-05 11:46 ` Christian Brauner
2023-08-05 18:47   ` Linus Torvalds
2023-08-05 19:46     ` Linus Torvalds
2023-08-06  6:10       ` Christian Brauner
2023-08-06 13:25         ` Christian Brauner
2023-08-06 17:48           ` Linus Torvalds

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=8d1069bf-4c0b-22be-e4c4-5f2b1eb1f7e8@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=cyphar@cyphar.com \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=sforshee@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.