Skip to content

Commit

Permalink
mm: never attempt async page lock if we've transferred data already
Browse files Browse the repository at this point in the history
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: [email protected] # v5.9
Fixes: 1a0a785 ("mm: support async buffered reads in generic_file_buffered_read()")
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Nov 16, 2020
1 parent 944d144 commit 0abed7c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2347,10 +2347,15 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb,

page_not_up_to_date:
/* Get exclusive access to the page ... */
if (iocb->ki_flags & IOCB_WAITQ)
if (iocb->ki_flags & IOCB_WAITQ) {
if (written) {
put_page(page);
goto out;
}
error = lock_page_async(page, iocb->ki_waitq);
else
} else {
error = lock_page_killable(page);
}
if (unlikely(error))
goto readpage_error;

Expand Down Expand Up @@ -2393,10 +2398,15 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb,
}

if (!PageUptodate(page)) {
if (iocb->ki_flags & IOCB_WAITQ)
if (iocb->ki_flags & IOCB_WAITQ) {
if (written) {
put_page(page);
goto out;
}
error = lock_page_async(page, iocb->ki_waitq);
else
} else {
error = lock_page_killable(page);
}

if (unlikely(error))
goto readpage_error;
Expand Down

0 comments on commit 0abed7c

Please sign in to comment.