Skip to content

Commit 0abed7c

Browse files
committed
mm: never attempt async page lock if we've transferred data already
We catch the case where we enter generic_file_buffered_read() with data already transferred, but we also need to be careful not to allow an async page lock if we're looping transferring data. If not, we could be returning -EIOCBQUEUED instead of the transferred amount, and it could result in double waitqueue additions as well. Cc: stable@vger.kernel.org # v5.9 Fixes: 1a0a785 ("mm: support async buffered reads in generic_file_buffered_read()") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 944d144 commit 0abed7c

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

mm/filemap.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,10 +2347,15 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb,
23472347

23482348
page_not_up_to_date:
23492349
/* Get exclusive access to the page ... */
2350-
if (iocb->ki_flags & IOCB_WAITQ)
2350+
if (iocb->ki_flags & IOCB_WAITQ) {
2351+
if (written) {
2352+
put_page(page);
2353+
goto out;
2354+
}
23512355
error = lock_page_async(page, iocb->ki_waitq);
2352-
else
2356+
} else {
23532357
error = lock_page_killable(page);
2358+
}
23542359
if (unlikely(error))
23552360
goto readpage_error;
23562361

@@ -2393,10 +2398,15 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb,
23932398
}
23942399

23952400
if (!PageUptodate(page)) {
2396-
if (iocb->ki_flags & IOCB_WAITQ)
2401+
if (iocb->ki_flags & IOCB_WAITQ) {
2402+
if (written) {
2403+
put_page(page);
2404+
goto out;
2405+
}
23972406
error = lock_page_async(page, iocb->ki_waitq);
2398-
else
2407+
} else {
23992408
error = lock_page_killable(page);
2409+
}
24002410

24012411
if (unlikely(error))
24022412
goto readpage_error;

0 commit comments

Comments
 (0)