Re: Do we need to unrevert "fs: do not prefault sys_write() user buffer pages"?

From: Linus Torvalds
Date: Tue Jun 22 2021 - 11:32:59 EST


Note this part:

On Tue, Jun 22, 2021 at 8:20 AM David Howells <dhowells@xxxxxxxxxx> wrote:
>
> copied = iov_iter_copy_from_user_atomic(page, i, offset, bytes);

The "atomic" is the key thing.

The fault_in_readable is just an optimistic "let's make things be mapped".

But yes, it could get unmapped again before the actual copy happens
with the lock held. But that's why the copy is using that atomic
version, so if that happens, we'll end up repeating.

Honestly, the first part comment above the
iov_iter_fault_in_readable() is a bit misleading (the deadlock would
be real _except_ for the atomic part), and it would logically make
sense to only do this for when the actual atomic copy_from_user_atomic
fails. But then you'd have to fault things twice if you do fault.

Linus