From: Linus Torvalds > Sent: 24 July 2021 20:53 > > On Sat, Jul 24, 2021 at 12:35 PM Andreas Gruenbacher > <agruenba@xxxxxxxxxx> 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)