Skip to content

Commit

Permalink
ANDROID: mm/filemap: Fix missing put_page() for speculative page fault
Browse files Browse the repository at this point in the history
find_get_page() returns a page with increased refcount, assuming a page
exists at the given index. Ensure this refcount is dropped on error.

Bug: 253068137
Fixes: cd333a0 ("BACKPORT: FROMLIST: mm: implement speculative handling in filemap_fault()")
Change-Id: Idc7b9e3f11f32a02bed4c6f4e11cec9200a5c790
Signed-off-by: Patrick Daly <[email protected]>
  • Loading branch information
Patrick Daly authored and surenbaghdasaryan committed Oct 12, 2022
1 parent 0555154 commit 6232eec
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3055,11 +3055,14 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)

if (vmf->flags & FAULT_FLAG_SPECULATIVE) {
page = find_get_page(mapping, offset);
if (unlikely(!page) || unlikely(PageReadahead(page)))
if (unlikely(!page))
return VM_FAULT_RETRY;

if (unlikely(PageReadahead(page)))
goto page_put;

if (!trylock_page(page))
return VM_FAULT_RETRY;
goto page_put;

if (unlikely(compound_head(page)->mapping != mapping))
goto page_unlock;
Expand Down Expand Up @@ -3091,6 +3094,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
return VM_FAULT_LOCKED;
page_unlock:
unlock_page(page);
page_put:
put_page(page);
return VM_FAULT_RETRY;
}

Expand Down

0 comments on commit 6232eec

Please sign in to comment.