[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <03e0541400e946cf87bc285198b82491@AcuMS.aculab.com>
Date: Tue, 27 Jul 2021 09:30:02 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Linus Torvalds' <torvalds@...ux-foundation.org>,
Andreas Gruenbacher <agruenba@...hat.com>
CC: Alexander Viro <viro@...iv.linux.org.uk>,
Christoph Hellwig <hch@...radead.org>,
"Darrick J. Wong" <djwong@...nel.org>, Jan Kara <jack@...e.cz>,
Matthew Wilcox <willy@...radead.org>,
cluster-devel <cluster-devel@...hat.com>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
"ocfs2-devel@....oracle.com" <ocfs2-devel@....oracle.com>
Subject: RE: [PATCH v4 1/8] iov_iter: Introduce iov_iter_fault_in_writeable
helper
From: Linus Torvalds
> Sent: 24 July 2021 20:53
>
> On Sat, Jul 24, 2021 at 12:35 PM Andreas Gruenbacher
> <agruenba@...hat.com> wrote:
> >
> > +int iov_iter_fault_in_writeable(const struct iov_iter *i, size_t bytes)
> > +{
> ...
> > + if (fault_in_user_pages(start, len, true) != len)
> > + return -EFAULT;
>
> Looking at this once more, I think this is likely wrong.
>
> Why?
>
> Because any user can/should only care about at least *part* of the
> area being writable.
>
> Imagine that you're doing a large read. If the *first* page is
> writable, you should still return the partial read, not -EFAULT.
My 2c...
Is it actually worth doing any more than ensuring the first byte
of the buffer is paged in before entering the block that has
to disable page faults?
Most of the all the pages are present so the IO completes.
The pages can always get unmapped (due to page pressure or
another application thread unmapping them) so there needs
to be a retry loop.
Given the cost of actually faulting in a page going around
the outer loop may not matter.
Indeed, if an application has just mmap()ed in a very large
file and is then doing a write() from it then it is quite
likely that the pages got unmapped!
Clearly there needs to be extra code to ensure progress is made.
This might actually require the use of 'bounce buffers'
for really problematic user requests.
I also wonder what actually happens for pipes and fifos.
IIRC reads and write of up to PIPE_MAX (typically 4096)
are expected to be atomic.
This should be true even if there are page faults part way
through the copy_to/from_user().
It has to be said I can't see any reference to PIPE_MAX
in the linux man pages, but I'm sure it is in the POSIX/TOG
spec.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists