diff mbox series

[v6,20/34] vfs: Make splice use iov_iter_extract_pages()

Message ID 167391062544.2311931.15195962488932892568.stgit@warthog.procyon.org.uk (mailing list archive)
State New, archived
Headers show
Series iov_iter: Improve page extraction (ref, pin or just list) | expand

Commit Message

David Howells Jan. 16, 2023, 11:10 p.m. UTC
Make splice's iter_to_pipe() use iov_iter_extract_pages().  Splice requests
will rejected if the request if the cleanup mode is going to be anything
other than put_pages() since we're going to be attaching pages from the
iterator to a pipe and then returning to the caller, leaving the spliced
pages to their fates at some unknown time in the future.

Note this will cause some requests to fail that could work before - such as
splicing from an XARRAY-type iterator - if there's any way to do it as
extraction doesn't take refs or pins on non-user-backed iterators.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Al Viro <viro@zeniv.linux.org.uk>
cc: Christoph Hellwig <hch@lst.de>
cc: Matthew Wilcox <willy@infradead.org>
cc: linux-fsdevel@vger.kernel.org
---

 fs/splice.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Al Viro Jan. 19, 2023, 2:31 a.m. UTC | #1
On Mon, Jan 16, 2023 at 11:10:25PM +0000, David Howells wrote:

> diff --git a/fs/splice.c b/fs/splice.c
> index 19c5b5adc548..c3433266ba1b 100644
> --- a/fs/splice.c
> +++ b/fs/splice.c
> @@ -1159,14 +1159,18 @@ static int iter_to_pipe(struct iov_iter *from,
>  	size_t total = 0;
>  	int ret = 0;
>  
> +	/* For the moment, all pages attached to a pipe must have refs, not pins. */
> +	if (WARN_ON(iov_iter_extract_mode(from, FOLL_SOURCE_BUF) != FOLL_GET))
> +		return -EIO;

Huh?  WTF does that have to do with pins?  Why would we be pinning the _source_
pages anyway?  We do want them referenced, for obvious reasons (they might be
stuck in the pipe), but that has nothing to do with get vs. pin.

If anything, this is one place where we want the semantics of iov_iter_get_pages...
diff mbox series

Patch

diff --git a/fs/splice.c b/fs/splice.c
index 19c5b5adc548..c3433266ba1b 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1159,14 +1159,18 @@  static int iter_to_pipe(struct iov_iter *from,
 	size_t total = 0;
 	int ret = 0;
 
+	/* For the moment, all pages attached to a pipe must have refs, not pins. */
+	if (WARN_ON(iov_iter_extract_mode(from, FOLL_SOURCE_BUF) != FOLL_GET))
+		return -EIO;
+
 	while (iov_iter_count(from)) {
-		struct page *pages[16];
+		struct page *pages[16], **ppages = pages;
 		ssize_t left;
 		size_t start;
 		int i, n;
 
-		left = iov_iter_get_pages(from, pages, ~0UL, 16, &start,
-					  FOLL_SOURCE_BUF);
+		left = iov_iter_extract_pages(from, &ppages, ~0UL, 16,
+					      FOLL_SOURCE_BUF, &start);
 		if (left <= 0) {
 			ret = left;
 			break;