Take a reference on a page when PG_private_2 is set and drop it once the
bit is unlocked[1].

Reported-by: Linus Torvalds <torva...@linux-foundation.org>
Signed-off-by: David Howells <dhowe...@redhat.com>
cc: Matthew Wilcox <wi...@infradead.org>
cc: Linus Torvalds <torva...@linux-foundation.org>
cc: linux...@kvack.org
cc: linux-cach...@redhat.com
cc: linux-...@lists.infradead.org
cc: linux-...@vger.kernel.org
cc: linux-c...@vger.kernel.org
cc: ceph-de...@vger.kernel.org
cc: v9fs-develo...@lists.sourceforge.net
cc: linux-fsde...@vger.kernel.org
Link: 
https://lore.kernel.org/r/CAHk-=wh+2gbF7XEjYc=HV9w_2uVzVf7vs60BPz0gFA=+pum...@mail.gmail.com/
 [1]
Link: https://lore.kernel.org/r/1331025.1612974...@warthog.procyon.org.uk/
Link: 
https://lore.kernel.org/r/161340400833.1303470.8070750156044982282.st...@warthog.procyon.org.uk/
 # v3
---

 fs/netfs/read_helper.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/netfs/read_helper.c b/fs/netfs/read_helper.c
index 0a7b76c11c98..ce11ca4c32e4 100644
--- a/fs/netfs/read_helper.c
+++ b/fs/netfs/read_helper.c
@@ -10,6 +10,7 @@
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <linux/pagemap.h>
+#include <linux/pagevec.h>
 #include <linux/slab.h>
 #include <linux/uio.h>
 #include <linux/sched/mm.h>
@@ -238,10 +239,13 @@ static void netfs_rreq_unmark_after_write(struct 
netfs_read_request *rreq,
                                          bool was_async)
 {
        struct netfs_read_subrequest *subreq;
+       struct pagevec pvec;
        struct page *page;
        pgoff_t unlocked = 0;
        bool have_unlocked = false;
 
+       pagevec_init(&pvec);
+
        rcu_read_lock();
 
        list_for_each_entry(subreq, &rreq->subrequests, rreq_link) {
@@ -255,6 +259,8 @@ static void netfs_rreq_unmark_after_write(struct 
netfs_read_request *rreq,
                                continue;
                        unlocked = page->index;
                        unlock_page_fscache(page);
+                       if (pagevec_add(&pvec, page) == 0)
+                               pagevec_release(&pvec);
                        have_unlocked = true;
                }
        }
@@ -413,8 +419,10 @@ static void netfs_rreq_unlock(struct netfs_read_request 
*rreq)
                                pg_failed = true;
                                break;
                        }
-                       if (test_bit(NETFS_SREQ_WRITE_TO_CACHE, &subreq->flags))
+                       if (test_bit(NETFS_SREQ_WRITE_TO_CACHE, 
&subreq->flags)) {
+                               get_page(page);
                                SetPageFsCache(page);
+                       }
                        pg_failed |= subreq_failed;
                        if (pgend < iopos + subreq->len)
                                break;


Reply via email to