Article View: linux.kernel.netdev
Article #14555Re: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
From: Christian Brauner
Date: Wed, 11 Nov 2026 13:42
Date: Wed, 11 Nov 2026 13:42
96 lines
11975 bytes
11975 bytes
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++;
--
Technical Details
Message-ID:
<20261111-thunfisch-wirbt-waldrand-822275b2d3b1@brauner>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361085-linux-kernel-netdev=dewy.ruReferences:
<20261110145241.536019-1-kas@kernel.org> <20261110145241.536019-2-kas@kernel.org> <avNuQqLf9CG9dSsE@casper.infradead.org> <20261111-heimreisen-ungeziefer-empfunden-a892571f2c07@brauner>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361085-linux-kernel-netdev=dewy.ru From: brauner@kernel.org (Christian Brauner) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write() Date: Wed, 11 Nov 2026 14:42:44 +0100 Organization: Usenet Network Message-ID: <20261111-thunfisch-wirbt-waldrand-822275b2d3b1@brauner> References: <20261110145241.536019-1-kas@kernel.org> <20261110145241.536019-2-kas@kernel.org> <avNuQqLf9CG9dSsE@casper.infradead.org> <20261111-heimreisen-ungeziefer-empfunden-a892571f2c07@brauner> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Injection-Info: usenet.network; logging-data="863373"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:E1nd8uRK0XH8zUP72bjHXUA/Nf4= sha256:lyIeGFqgvWZBRTu7yBE8hls/cIDNBCx624kF2aaF1GQ= sha1:45J9I3iKGnmPqxURd8siysIYLkE= sha256:4ixd3jjp//0eZpxBbSbPgVPVTvcJpt5bhYHxhe8CGmU= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id EF3F4113EC1; Wed, 11 Nov 2026 16:46:28 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AepLgvRk6aZL; Wed, 11 Nov 2026 16:46:21 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-361085-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 50987113EF9; Wed, 11 Nov 2026 16:46:12 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 009D839F5D; Wed, 11 Nov 2026 13:43:18 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1794404579; b=g/jR39NVkwMflKed9GqgucuiHG35sZFS3cVGfll7Edx/hKpff4ybjPZ2p+E2KT9N4ZIm JCb6Hlzz8D+UgZ5jNTuNh7t0zVpuhFbJlWxOOMUWHAZY08+2Zpvl/foNmmkfripn/jXiW y74dyqR8zoV0wn+SwzlzNOuRd3Zb26MWZ8+db5xmvLq4fikHIWf68tYhlvfr5XIJkWAfG JPDZU+JdQHcAFIK8cYkeI+c2tlSDanBv9g6w07+9FBWcQ5YIhle/bZAJbgIpZsvJ/9dqs xhxrBdS80D+QCN3wQWxpABIVDxBZvJFExTdAZvKOV1eGsRZtfQ9U97mrzS4RwogJsaQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794404579; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=r2uDapf2vLabhbDFIRRtIj4i5+V0KX58w12edhkpSZU=; b=3xW69+FgedI5Ov0tkk+EDEFsud+GU2H+SdLnHb5qmL4ZO5tCARHXfVXa0J5++oyznteT YTnEGvHPJVAA1AsS6Bw6ZOJxsY5BsTK8E13ZszjKhvJcZxoEVNzbPo9B7+qt6EBjH8gy4 Jynngn3lEzdptVBti/XYmu2diABS5DCnvjEDmi6kxTQ2qo1FlXP/iSY6ZTS/p5HIYX31l TZmfglFlLPZCdnw7z2Uz4Dj0Deu8RfD4F+WfWRRLM3b/qVjFOfJ7unG6iwABnmzFCwz28 1FqCDN3gBsA/OFmIL4r/r4pRWKDgJu/iNybPcfMZGkrAjWm8tJY8wlccTkRvUWadmPw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=N1FWFgdc; arc=fail smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 392BF606A8B2; Wed, 11 Nov 2026 13:42:59 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=N1FWFgdc X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794404573; b=iKb8tVGtqOAzqng+SL93kjSt7ZXgrI4fZG8eZp7TS1Nuloo78/jInIEUqwrzuqXWiEdQ fwC+KUxbpUMG3DFQzFGMDI93XS2nHO1WcH95NbBqwcx97SwdIcAXRR4gqkNR8Dl9bxipP pYsVB/sDPrW5ZTWI05Rcj0weqTIoRE7Perm3xI8UzLhuX4QsZvQhBosO0ofSdU5oalAG6 ZlVRJ3SiBpcGsTlFuyBHyqibv+xbjDCvERegq91t+p8aGTpgeib5gIVJNyo9ySQw0NXRm o5j+ZuIA7ZmJ1YNhIKcwOBpHfd1HT8kAseJSxiuzUqHqO7lXZBZgCyl5DSW7ueNtQPg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794404573; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=r2uDapf2vLabhbDFIRRtIj4i5+V0KX58w12edhkpSZU=; b=qePUMrYrdwdtOp6/IhFCq0d+UYDIjlXTXG9m7rj4Oapymmy3inzAgAYpmUD6uSJLFUA2 HFy2VB7jun+hFTHynrR8meKo1pplZTxMAULEzNW+MXNzLwWR964VIP3PklsvXEDskmsRu W2RXu5RkiWqz1lx3jgHJdT8D24P4CH1U4T9XpkYvevBF2bbZBrhCdSN+z5DA4D/jAdBeo URp/nYhEUzgPxLSLQ0x2C3MEIp4ahsD2+LsT0jRKjV1lp+5VrcFx27MsGETEZJFptid6l Op9103l/w9g1fTSUp+P+RbwBr9nQj0K3Z99LPMHZtwWIx+tHNuAlr7N7e0gTkVRADFw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=N1FWFgdc; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56F06606A32E; Wed, 11 Nov 2026 13:42:53 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48B351F00A06; Wed, 11 Nov 2026 13:42:47 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794404573; bh=r2uDapf2vLabhbDFIRRtIj4i5+V0KX58w12edhkpSZU=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=N1FWFgdc7n3FyJi4mWq7kE7aBBRtNzoz7OTcWnlRMydaapZ3nDIlCS4Okv1TVPC3m JL6rQ4hb45pb3iD/dM5aW7LzXLL/qyYUni1xL1rlyF6YBcPpru6XkKZzzFwowC9Y6y C7NiuCGH+vmHlWX+5tIej70Q1CIcqLl6FT43SjHcnbxrNC7mmiqAQmKBwWSoAD7GLd ArJzKTz6tCYzM+6Y3ek8ew3nEUuf+jxXUBKm3e9gdsw66SDyb8OUIR83eD2WnwijaO dPW/jiYjBeQgF5n7srNsN9thQlouIMfyRaahC/yQazXkj1+PCWlU+Bj+iM7D9axTAT G3hqLCcrRvQ3g== X-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 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261111-heimreisen-ungeziefer-empfunden-a892571f2c07@brauner>