filemap: fix the conditional folio_put in filemap_fault
Subsystems (4)
PATCH 1/2 filemap: fix the conditional folio_put in filemap_fault
folio can't be NULL here now that __filemap_get_folio returns an ERR_PTR. Remove the conditional folio_put after the out_retry label and add a new label for the cases where we have a valid folio.
--- mm/filemap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
mm/filemap.c +5 -5
@@ -3298,7 +3298,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) }if (!lock_folio_maybe_drop_mmap (vmf, folio, &fpin)) - goto out_retry; + goto out_retry_put_folio;/* Did it get truncated? */ if (unlikely (folio->mapping != mapping)) {
@@ -3334,7 +3334,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)*/ if (fpin) {folio_unlock (folio); - goto out_retry; + goto out_retry_put_folio; }if (mapping_locked)filemap_invalidate_unlock_shared (mapping);
@@ -3363,7 +3363,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) fpin =maybe_unlock_mmap_for_io (vmf, fpin); error =filemap_read_folio (file, mapping->a_ops->read_folio, folio);if (fpin) - goto out_retry; + goto out_retry_put_folio;folio_put (folio);if (!error || error ==AOP_TRUNCATED_PAGE )
@@ -3372,14 +3372,14 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)return VM_FAULT_SIGBUS ; +out_retry_put_folio: +folio_put (folio); out_retry:/* * We dropped the mmap_lock, we need to return to the fault handler to * re-find the vma and come back and find our hopefully still populated * page. */ -if (folio) -folio_put (folio);if (mapping_locked)filemap_invalidate_unlock_shared (mapping);if (fpin)
Signature · 1 line
2.39.2
PATCH 2/2 afs: fix the afs_dir_get_folio return value
Keep returning NULL on failure instead of letting an ERR_PTR escape to callers that don't expect it.
--- fs/afs/dir_edit.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/afs/dir_edit.c +4 -3
@@ -115,11 +115,12 @@ static struct folio *afs_dir_get_folio(struct afs_vnode *vnode, pgoff_t index) folio =__filemap_get_folio (mapping, index,FGP_LOCK |FGP_ACCESSED |FGP_CREAT , mapping->gfp_mask); -if (IS_ERR (folio)) +if (IS_ERR (folio)) {clear_bit (AFS_VNODE_DIR_VALID , &vnode->flags); -else if (folio && !folio_test_private (folio)) +return NULL ; + } +if (!folio_test_private (folio))folio_attach_private (folio, (void *)1 ); -return folio; }
Signature · 1 line
2.39.2
Re: [PATCH 2/2] afs: fix the afs_dir_get_folio return value
Quoted 6 lines · Christoph Hellwig
Keep returning NULL on failure instead of letting an
ERR_PTRescape to callers that don't expect it.Fixes 66dabbb65d67 ("mm: return an ERR_PTR from __filemap_get_folio")Reported-by Jan Kara <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 27 lines
--- fs/afs/dir_edit.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/afs/dir_edit.c +4
-3@@ -115,11 +115,12 @@ static struct folio *afs_dir_get_folio(struct afs_vnode *vnode, pgoff_t index) folio =__filemap_get_folio (mapping, index,FGP_LOCK |FGP_ACCESSED |FGP_CREAT , mapping->gfp_mask); -if (IS_ERR (folio)) +if (IS_ERR (folio)) {clear_bit (AFS_VNODE_DIR_VALID , &vnode->flags); -else if (folio && !folio_test_private (folio)) +return NULL ; + } +if (!folio_test_private (folio))folio_attach_private (folio, (void *)1 ); -return folio; }Signature · 1 line
2.39.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 2/2] afs: fix the afs_dir_get_folio return value
In reply to Christoph HellwigQuoted 6 lines · Christoph Hellwig
Keep returning NULL on failure instead of letting an
ERR_PTRescape to callers that don't expect it.Fixes 66dabbb65d67 ("mm: return an ERR_PTR from __filemap_get_folio")Reported-by Jan Kara <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>
Matthew Wilcox
maintainerQuoted 4 lines · Christoph Hellwig
mm/filemap.c +0
-0@@ -3372,14 +3372,14 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)return VM_FAULT_SIGBUS ;
mm/filemap.c vm_fault_t filemap_fault(struct vm_fault *vmf) · line 3382
Quoted 10 lines
mm/filemap.c +2
-2+out_retry_put_folio: +folio_put (folio); out_retry:/* * We dropped the mmap_lock, we need to return to the fault handler to * re-find the vma and come back and find our hopefully still populated * page. */ -if (folio) -folio_put (folio);
Why not simply:
- if (folio)
+ if (!IS_ERR_OR_NULL(folio))
Review
Quoted 6 lines · Matthew Wilcox
mm/filemap.c vm_fault_t filemap_fault(struct vm_fault *vmf) · line 3382
Quoted 1 line
mm/filemap.c +0
-1-folio_put (folio);Why not simply:
(quoted diff) +1
-1- if (folio) + if (!IS_ERR_OR_NULL(folio))
no need for the OR_NULL. But I find the extra label way easier to reason about, and it's exactly the same amount of code.
Matthew Wilcox
maintainerQuoted 9 lines · Christoph Hellwig
Review
Quoted 6 lines · Matthew Wilcox
mm/filemap.c vm_fault_t filemap_fault(struct vm_fault *vmf) · line 3382
Quoted 1 line
mm/filemap.c +0
-1-folio_put (folio);Why not simply:
(quoted diff) +1
-1- if (folio) + if (!IS_ERR_OR_NULL(folio))no need for the
OR_NULL.
Right. I didn't read the whole function.
Quoted 2 lines
But I find the extra label way easier to reason about, and it's exactly the same amount of code.
If it were easy to reason about, it would have a less ugly name.
Quoted 7 lines · Christoph Hellwig
folio can't be NULL here now that
__filemap_get_folioreturns anERR_PTR. Remove the conditionalfolio_putafter theout_retrylabel and add a new label for the cases where we have a valid folio.Fixes 66dabbb65d67 ("mm: return an ERR_PTR from __filemap_get_folio")Reported-by [email protected]Signed-off-by Christoph Hellwig <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 55 lines
--- mm/filemap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/filemap.c +5
-5@@ -3298,7 +3298,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) }if (!lock_folio_maybe_drop_mmap (vmf, folio, &fpin)) - goto out_retry; + goto out_retry_put_folio;/* Did it get truncated? */ if (unlikely (folio->mapping != mapping)) {@@ -3334,7 +3334,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)*/ if (fpin) {folio_unlock (folio); - goto out_retry; + goto out_retry_put_folio; }if (mapping_locked)filemap_invalidate_unlock_shared (mapping);@@ -3363,7 +3363,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) fpin =maybe_unlock_mmap_for_io (vmf, fpin); error =filemap_read_folio (file, mapping->a_ops->read_folio, folio);if (fpin) - goto out_retry; + goto out_retry_put_folio;folio_put (folio);if (!error || error ==AOP_TRUNCATED_PAGE )@@ -3372,14 +3372,14 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)return VM_FAULT_SIGBUS ; +out_retry_put_folio: +folio_put (folio); out_retry:/* * We dropped the mmap_lock, we need to return to the fault handler to * re-find the vma and come back and find our hopefully still populated * page. */ -if (folio) -folio_put (folio);if (mapping_locked)filemap_invalidate_unlock_shared (mapping);if (fpin)Signature · 1 line
2.39.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR