@@ -970,26 +970,6 @@ static ssize_t bch2_buffered_write(struc
unsigned offset = pos & (PAGE_SIZE - 1);
unsigned bytes = iov_iter_count(iter);
again:
- /*
- * Bring in the user page that we will copy from _first_.
- * Otherwise there's a nasty deadlock on copying from the
- * same page as we're writing to, without it being marked
- * up-to-date.
- *
- * Not only is this an optimisation, but it is also required
- * to check that the address is actually valid, when atomic
- * usercopies are used, below.
- */
- if (unlikely(fault_in_iov_iter_readable(iter, bytes))) {
- bytes = min_t(unsigned long, iov_iter_count(iter),
- PAGE_SIZE - offset);
-
- if (unlikely(fault_in_iov_iter_readable(iter, bytes))) {
- ret = -EFAULT;
- break;
- }
- }
-
if (unlikely(fatal_signal_pending(current))) {
ret = -EINTR;
break;
@@ -1012,6 +992,16 @@ again:
*/
bytes = min_t(unsigned long, PAGE_SIZE - offset,
iov_iter_single_seg_count(iter));
+
+ /*
+ * Faulting in 'iter' may be required for forward
+ * progress. Do it here, out outside the fast path
+ * and when not holding any folio locks.
+ */
+ if (fault_in_iov_iter_readable(iter, bytes) == bytes) {
+ ret = -EFAULT;
+ break;
+ }
goto again;
}
pos += ret;