lkml.org 
[lkml]   [2019]   [Apr]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v1 13/15] fs/splice: use put_user_page() when appropriate
Date
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 --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;
--
2.20.1
\
 
 \ /
  Last update: 2019-04-11 23:10    [W:0.558 / U:5.476 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site