mm: never attempt async page lock if we've transferred data already

upstream commit id: 0abed7c69b956d135cb6d320c350b2adb213e7d8

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: 1a0a7853b901 ("mm: support async buffered reads in generic_file_buffered_read()")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Ni Xun <richardni@tencent.com>
This commit is contained in:
Jens Axboe 2020-11-16 13:36:24 -07:00 committed by Ni Xun
parent 789da11347
commit 97f4cc280f
1 changed files with 14 additions and 4 deletions

View File

@ -2206,10 +2206,15 @@ page_ok:
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;
@ -2252,10 +2257,15 @@ readpage:
}
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;