diff mbox series

[v1,13/15] fs/splice: use put_user_page() when appropriate

Message ID 20190411210834.4105-14-jglisse@redhat.com (mailing list archive)
State New, archived
Headers show
Series Keep track of GUPed pages in fs and block | expand

Commit Message

Jerome Glisse April 11, 2019, 9:08 p.m. UTC
From: Jérôme Glisse <jglisse@redhat.com>

Use put_user_page() when page reference was taken through GUP.

Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-block@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Matthew Wilcox <willy@infradead.org>
---
 fs/splice.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/fs/splice.c b/fs/splice.c
index 4a0b522a0cb4..c9c350d37912 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -371,6 +371,7 @@  static ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
 	unsigned int nr_pages;
 	size_t offset, base, copied = 0;
 	ssize_t res;
+	bool gup;
 	int i;
 
 	if (pipe->nrbufs == pipe->buffers)
@@ -383,7 +384,7 @@  static ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
 	offset = *ppos & ~PAGE_MASK;
 
 	iov_iter_pipe(&to, READ, pipe, len + offset);
-
+	gup = iov_iter_get_pages_use_gup(&to);
 	res = iov_iter_get_pages_alloc(&to, &pages, len + offset, &base);
 	if (res <= 0)
 		return -ENOMEM;
@@ -419,8 +420,12 @@  static ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
 	if (vec != __vec)
 		kfree(vec);
 out:
-	for (i = 0; i < nr_pages; i++)
-		put_page(pages[i]);
+	for (i = 0; i < nr_pages; i++) {
+		if (gup)
+			put_user_page(pages[i]);
+		else
+			put_page(pages[i]);
+	}
 	kvfree(pages);
 	iov_iter_advance(&to, copied);	/* truncates and discards */
 	return res;