summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-11-16 13:36:24 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-11-24 13:39:14 +0100
commit38d3e20ff427d5b3dc47e3312728bb05dac8b8f4 (patch)
treec71ff1af3975333d868b16780ea3e54e85365392
parent3261603426ec2c7e147abad6db95aac5261728d6 (diff)
mm: never attempt async page lock if we've transferred data already
commit 0abed7c69b956d135cb6d320c350b2adb213e7d8 upstream. 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--mm/filemap.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/mm/filemap.c b/mm/filemap.c
index 407b94d8ce00..6024d15998a4 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2327,10 +2327,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;
@@ -2373,10 +2378,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;