mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Matthew Wilcox <willy@infradead.org>,
	 Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Kiryl Shutsemau (Meta)" <kas@kernel.org>,
	 Alexander Viro <viro@zeniv.linux.org.uk>,
	Miklos Szeredi <miklos@szeredi.hu>, Amit Shah <amit@kernel.org>,
	 Jan Kara <jack@suse.cz>,
	"David Hildenbrand (Arm)" <david@kernel.org>,
	 Zi Yan <ziy@nvidia.com>, Bernd Schubert <bschubert@ddn.com>,
	 Hugh Dickins <hughd@google.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Arnd Bergmann <arnd@arndb.de>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	linux-fsdevel@vger.kernel.org,  fuse-devel@lists.linux.dev,
	virtualization@lists.linux.dev, netdev@vger.kernel.org,
	 linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Date: Wed, 11 Nov 2026 14:42:44 +0100	[thread overview]
Message-ID: <20261111-thunfisch-wirbt-waldrand-822275b2d3b1@brauner> (raw)
In-Reply-To: <20261111-heimreisen-ungeziefer-empfunden-a892571f2c07@brauner>

On Wed, Nov 11, 2026 at 01:36:37PM +0100, Christian Brauner wrote:
> So we need to copy per page which would fix both.

So the fix below is what we've done before for pipes and I think it's
the right thing to do here too. I put the following on vfs.fixes:

-- >8 --
From: Christian Brauner <brauner@kernel.org>
Subject: [PATCH] virtio_console: copy pipe buffers that span multiple pages

pipe_to_sg() maps buf->page with kmap_local_page() and then copies up
to a page worth of data starting at buf->offset. But kmap_local_page()
only maps a single page and a pipe buffer can span multiple pages of a
compound page with buf->offset pointing past the first one:

- skb_splice_bits() for AF_UNIX and TCP sockets
- tracing_buffers_splice_read() with sub-buffers larger than a page
- fuse_dev_splice_read() which hands out the page cache folios of WRITE
  requests. Those can be large folios since b46e09667411 ("fuse: enable
  large folios").

Without HIGHMEM this happens to work because kmap_local_page() is just
page_address() and a compound page is contiguous in the direct map.
With HIGHMEM the copy reads past the mapping. A fuse server on a 32-bit
HIGHMEM guest that splices a WRITE request into a virtio port crashes:

  BUG: unable to handle page fault for address: fffab000
  #PF: supervisor read access in kernel mode
  #PF: error_code(0x0000) - not-present page
  Oops: Oops: 0000 [#1] SMP
  EIP: pipe_to_sg+0x158/0x1e0
  Call Trace:
   __splice_from_pipe+0xd6/0x1f0
   port_fops_splice_write+0xf9/0x170
   do_splice+0x2c1/0x810
   __ia32_sys_splice+0x2e7/0x310
   ia32_sys_call+0x1916/0x2510
   __do_fast_syscall_32+0xd4/0x550
   do_fast_syscall_32+0x32/0x70
   do_SYSENTER_32+0x15/0x20
   entry_SYSENTER_32+0xa6/0x115

pipe_read() had the same problem and 08aa64796016 ("teach
copy_page_to_iter() to handle compound pages") fixed it by mapping one
subpage at a time. So copy the buffer with copy_page_to_iter() as well.

Fixes: b46e09667411 ("fuse: enable large folios")
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 drivers/char/virtio_console.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index b1b1aaf43e07e..b93a31b81cf4e 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -12,6 +12,7 @@
 #include <linux/freezer.h>
 #include <linux/fs.h>
 #include <linux/splice.h>
+#include <linux/uio.h>
 #include <linux/pagemap.h>
 #include <linux/idr.h>
 #include <linux/init.h>
@@ -891,8 +892,9 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
 {
 	struct sg_list *sgl = sd->u.data;
 	unsigned int offset, len;
+	struct iov_iter to;
 	struct page *page;
-	char *src;
+	struct kvec kv;
 
 	if (sgl->n == sgl->size)
 		return 0;
@@ -907,9 +909,14 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
 	if (len + offset > PAGE_SIZE)
 		len = PAGE_SIZE - offset;
 
-	src = kmap_local_page(buf->page);
-	memcpy(page_address(page) + offset, src + buf->offset, len);
-	kunmap_local(src);
+	/* The buffer can span several pages of a compound page. */
+	kv.iov_base = page_address(page) + offset;
+	kv.iov_len = len;
+	iov_iter_kvec(&to, ITER_DEST, &kv, 1, len);
+	if (copy_page_to_iter(buf->page, buf->offset, len, &to) != len) {
+		__free_page(page);
+		return -EFAULT;
+	}
 
 	sg_set_page(&sgl->sg[sgl->n], page, len, offset);
 	sgl->n++;

-- 

  reply	other threads:[~2026-11-11 13:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 14:52 [PATCH 0/4] splice: remove pipe buffer stealing Kiryl Shutsemau (Meta)
2026-11-10 14:52 ` [PATCH 1/4] virtio_console: copy pipe buffers in splice_write() Kiryl Shutsemau (Meta)
2026-11-10 16:24   ` Zi Yan
2026-11-10 19:19   ` Matthew Wilcox
2026-11-11 12:36     ` Christian Brauner
2026-11-11 13:42       ` Christian Brauner [this message]
2026-11-11 16:43         ` Linus Torvalds
2026-11-11 18:53           ` Christian Brauner
2026-11-11 19:26             ` Linus Torvalds
2026-11-10 14:52 ` [PATCH 2/4] fuse: don't move pipe buffers into the page cache Kiryl Shutsemau (Meta)
2026-11-10 16:25   ` Zi Yan
2026-11-11  9:02   ` Miklos Szeredi
2026-11-10 14:52 ` [PATCH 3/4] splice: remove pipe buffer stealing Kiryl Shutsemau (Meta)
2026-11-10 14:52 ` [PATCH 4/4] splice: replace nosteal_pipe_buf_ops with default_pipe_buf_ops Kiryl Shutsemau (Meta)
2026-11-10 15:59 ` [PATCH 0/4] splice: remove pipe buffer stealing Linus Torvalds
2026-11-11 11:06   ` Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261111-thunfisch-wirbt-waldrand-822275b2d3b1@brauner \
    --to=brauner@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=amit@kernel.org \
    --cc=arnd@arndb.de \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bschubert@ddn.com \
    --cc=davem@davemloft.net \
    --cc=david@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=fuse-devel@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=horms@kernel.org \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=kas@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=miklos@szeredi.hu \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=virtualization@lists.linux.dev \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®