linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH v2] splice: Prevent gifting of multipage folios
@ 2023-02-27 15:51 David Howells
  2023-02-27 15:53 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: David Howells @ 2023-02-27 15:51 UTC (permalink / raw)
  To: Jens Axboe, Matthew Wilcox, Miklos Szeredi, Amit Shah
  Cc: dhowells, linux-fsdevel, virtualization, linux-mm, linux-kernel

    
Don't let parts of compound pages/multipage folios be gifted by (vm)splice
into a pipe as the other end may only be expecting single-page gifts (fuse
and virtio console for example).

replace_page_cache_folio(), for example, will do the wrong thing if it
tries to replace a single paged folio with a multipage folio.

Try to avoid this by making add_to_pipe() remove the gift flag on multipage
folios.

Fixes: 7afa6fd037e5 ("[PATCH] vmsplice: allow user to pass in gift pages")
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Matthew Wilcox <willy@infradead.org>
cc: Jens Axboe <axboe@suse.de>
cc: Miklos Szeredi <miklos@szeredi.hu>
cc: Amit Shah <amit@kernel.org>
cc: linux-fsdevel@vger.kernel.org
cc: virtualization@lists.linux-foundation.org
cc: linux-mm@kvack.org
---
 fs/splice.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/splice.c b/fs/splice.c
index 2e76dbb81a8f..8bbd7794d9f0 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -240,6 +240,8 @@ ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
 	} else if (pipe_full(head, tail, pipe->max_usage)) {
 		ret = -EAGAIN;
 	} else {
+		if (PageCompound(buf->page))
+			buf->flags &= ~PIPE_BUF_FLAG_GIFT;
 		pipe->bufs[head & mask] = *buf;
 		pipe->head = head + 1;
 		return buf->len;


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RFC][PATCH v2] splice: Prevent gifting of multipage folios
  2023-02-27 15:51 [RFC][PATCH v2] splice: Prevent gifting of multipage folios David Howells
@ 2023-02-27 15:53 ` Matthew Wilcox
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2023-02-27 15:53 UTC (permalink / raw)
  To: David Howells
  Cc: Jens Axboe, Miklos Szeredi, Amit Shah, linux-fsdevel,
	virtualization, linux-mm, linux-kernel

On Mon, Feb 27, 2023 at 03:51:03PM +0000, David Howells wrote:
>     
> Don't let parts of compound pages/multipage folios be gifted by (vm)splice
> into a pipe as the other end may only be expecting single-page gifts (fuse
> and virtio console for example).
> 
> replace_page_cache_folio(), for example, will do the wrong thing if it
> tries to replace a single paged folio with a multipage folio.
> 
> Try to avoid this by making add_to_pipe() remove the gift flag on multipage
> folios.
> 
> Fixes: 7afa6fd037e5 ("[PATCH] vmsplice: allow user to pass in gift pages")
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Matthew Wilcox <willy@infradead.org>

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: stable@vger.kernel.org

> cc: Jens Axboe <axboe@suse.de>
> cc: Miklos Szeredi <miklos@szeredi.hu>
> cc: Amit Shah <amit@kernel.org>
> cc: linux-fsdevel@vger.kernel.org
> cc: virtualization@lists.linux-foundation.org
> cc: linux-mm@kvack.org
> ---
>  fs/splice.c |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/splice.c b/fs/splice.c
> index 2e76dbb81a8f..8bbd7794d9f0 100644
> --- a/fs/splice.c
> +++ b/fs/splice.c
> @@ -240,6 +240,8 @@ ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
>  	} else if (pipe_full(head, tail, pipe->max_usage)) {
>  		ret = -EAGAIN;
>  	} else {
> +		if (PageCompound(buf->page))
> +			buf->flags &= ~PIPE_BUF_FLAG_GIFT;
>  		pipe->bufs[head & mask] = *buf;
>  		pipe->head = head + 1;
>  		return buf->len;
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-27 15:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-27 15:51 [RFC][PATCH v2] splice: Prevent gifting of multipage folios David Howells
2023-02-27 15:53 ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).