splice: remove pipe buffer stealing
Subsystems (9)
cover splice: remove pipe buffer stealing
->try_steal() lets the consumer of a pipe buffer take its page instead of copying the data. Two consumers use it:
- fuse, when a server splices a read reply into /dev/fuse with
SPLICE_F_MOVE: the page goes into the fuse file's page cache;
- virtio_console, which passes the page to the host.
The page can come from the page cache of another file, from a write() into the pipe, or from vmsplice(SPLICE_F_GIFT). Stealing it takes page cache folios out of their files, and turns pages into page cache folios and back. That gets in the way of reading the page cache without folio references [1] and of telling folios apart with a PG_folio flag. It works only on pages that nothing else holds, for fuse only on clean, unmapped, order-0 ones, and it has needed fixes again and again:
32f98877c57b ("fuse: don't check refcount after stealing page")
b89ecd60d38e ("fuse: ignore PG_workingset after stealing")
712a951025c0 ("fuse: fix page stealing")
59ba47b6be9c ("fuse: Check for large folio with SPLICE_F_MOVE")
15c20483d915 ("fuse: validate folio state before pipe_buf_try_steal() in fuse_try_move_folio()")
Linus and David suggested removing it [2]. Both consumers already copy when a steal fails; with this series they always do. vmsplice() and splice() still accept SPLICE_F_GIFT and SPLICE_F_MOVE, and fuse still advertises FUSE_SPLICE_MOVE, so that servers which ask for it mount as before.
Miklos, Amit: do you know of users of the fuse move, or of virtio_console splice, that depend on the copy being avoided?
Without ->try_steal(), nosteal_pipe_buf_ops is the same as default_pipe_buf_ops, and the last patch keeps only the latter.
Tested on x86_64 with a FUSE server that answers reads by splicing the page cache pages of a backing file into /dev/fuse with SPLICE_F_MOVE. On v7.4-rc1 how much moves depends on folio sizes: with order-0 folios on both sides, one read of a 16M fuse file took 3968 of the backing file's 4096 pages out of its page cache. With the series nothing moves, and the data read through fuse is the same, also when the server reads its requests with splice(). A virtio-serial port fed by splice() from a pipe and from a file, and vmsplice(SPLICE_F_GIFT), SPLICE_F_MOVE, tee() and AF_UNIX socket splice checks also give the same data before and after.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/CAHk-=whhp=Q8qR+wPoM9+mxYPQ_OXMOEoKmT7J0JZikFZusuqw@mail.gmail.com/
Kiryl Shutsemau (Meta) (4):
virtio_console: copy pipe buffers in splice_write()
fuse: don't move pipe buffers into the page cache
splice: remove pipe buffer stealing
splice: replace nosteal_pipe_buf_ops with default_pipe_buf_ops
drivers/char/virtio_console.c | 39 ++++----- fs/fuse/args.h | 1 - fs/fuse/dev.c | 146 +--------------------------------- fs/fuse/file.c | 1 - fs/fuse/fuse_dev_i.h | 1 - fs/pipe.c | 43 ---------- fs/splice.c | 104 ++---------------------- include/linux/pipe_fs_i.h | 38 --------- kernel/watch_queue.c | 4 - mm/shmem.c | 7 -- net/core/skbuff.c | 2 +- 11 files changed, 26 insertions(+), 360 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.54.0
PATCH 1/4 virtio_console: copy pipe buffers in splice_write()
pipe_to_sg() tries to steal the page of each pipe buffer and pass it to the host as it is. When the steal fails, it copies the data into a page of its own.
Pages written into the pipe with write(), gifted user pages and page cache pages can be stolen. The ftrace ring buffer pages that virtio-trace splices cannot, so that in-tree user always gets the copy.
Always copy. The data that reaches the host does not change.
Preparation for removing ->try_steal() from pipe buffers.
--- drivers/char/virtio_console.c | 39 +++++++++++++---------------------- 1 file changed, 14 insertions(+), 25 deletions(-)
drivers/char/virtio_console.c +14 -25
@@ -891,45 +891,34 @@ 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 page *page; +char *src;if (sgl->n == sgl->size)return 0 ; -/* Try lock this page */ -if (pipe_buf_try_steal (pipe, buf)) { -/* Get reference and unlock page for moving */ -get_page (buf->page); -unlock_page (buf->page); + page =alloc_page (GFP_KERNEL ); +if (!page) +return -ENOMEM ; - len =min (buf->len, sd->len); -sg_set_page (&(sgl->sg[sgl->n]), buf->page, len, buf->offset); - }else { -/* Failback to copying a page */ -struct page *page =alloc_page (GFP_KERNEL ); -char *src; + offset = sd->pos & ~PAGE_MASK ; -if (!page) -return -ENOMEM ; + len = sd->len; +if (len + offset >PAGE_SIZE ) + len =PAGE_SIZE - offset; - offset = sd->pos & ~PAGE_MASK ; + src =kmap_local_page (buf->page); +memcpy (page_address (page) + offset, src + buf->offset, len); +kunmap_local (src); - len = sd->len; -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); - -sg_set_page (&(sgl->sg[sgl->n]), page, len, offset); - } +sg_set_page (&sgl->sg[sgl->n], page, len, offset); sgl->n++; sgl->len += len;return len; } -/* Faster zero-copy write by splicing */ +/* Write by splicing, copying the data from the pipe */ static ssize_t port_fops_splice_write (struct pipe_inode_info *pipe,struct file *filp,loff_t *ppos,size_t len,unsigned int flags)
Signature · 1 line
2.54.0
Re: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 10 lines · Kiryl Shutsemau (Meta)
pipe_to_sg()tries to steal the page of each pipe buffer and pass it to the host as it is. When the steal fails, it copies the data into a page of its own.Pages written into the pipe with
write(), gifted user pages and page cache pages can be stolen. The ftrace ring buffer pages that virtio-trace splices cannot, so that in-tree user always gets the copy.Always copy. The data that reaches the host does not change.
Quoted 8 lines
Preparation for removing ->try_steal() from pipe buffers.
Suggested-by Linus Torvalds <[email protected]>Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>--- drivers/char/virtio_console.c | 39 +++++++++++++---------------------- 1 file changed, 14 insertions(+), 25 deletions(-)
LGTM.
Best Regards,
Yan, Zi
Re: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
In reply to Kiryl Shutsemau (Meta)drivers/char/virtio_console.c static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf, · line 912
Quoted 13 lines · Kiryl Shutsemau (Meta)
drivers/char/virtio_console.c +10
-0+ page =alloc_page (GFP_KERNEL ); +if (!page) +return -ENOMEM ; + offset = sd->pos & ~PAGE_MASK ; + len = sd->len; +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);
memcpy_from_page(page_address(page) + offset, buf->page, buf->offset, len);
Quoted 6 lines
drivers/char/virtio_console.c +1
-0+sg_set_page (&sgl->sg[sgl->n], page, len, offset); sgl->n++; sgl->len += len;return len; }
Christian Brauner
maintainerRe: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 7 lines · Matthew Wilcox
drivers/char/virtio_console.c static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf, · line 912
Quoted 3 lines · Kiryl Shutsemau (Meta)
drivers/char/virtio_console.c +3
-0+ src =kmap_local_page (buf->page); +memcpy (page_address (page) + offset, src + buf->offset, len); +kunmap_local (src);memcpy_from_page(page_address(page) + offset, buf->page, buf->offset, len);
I don't think that works. pipe_to_sg() only clamps len to the destination page. A pipe buffer however can span multiple pages of a compound page iircu. And buf->offset can point past the first one.
I found two exmples:
(1) skb_splice_bits() for AF_UNIX and TCP
(2) tracing_buffers_splice_read() with buffer_subbuf_size_kb > 4,
And virtio-trace splices that stuff.
Which means VM_BUG_ON() in memcpy_from_page() fires:
kernel BUG at include/linux/highmem.h:542!
Oops: invalid opcode: 0000 [#1] SMP NOPTI RIP: 0010:pipe_to_sg+0x130/0x150 Call Trace: <TASK> __splice_from_pipe+0x92/0x1e0 port_fops_splice_write+0x13f/0x1a0 do_splice+0x3b6/0x8e0 __do_splice+0x20a/0x230 __x64_sys_splice+0x97/0x130 do_syscall_64+0xde/0x4b0 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Fwiw, the open-coded copy is broken as well. Just on HIGHMEM...
Starting with b46e09667411 ("fuse: enable large folios") fuse_dev_splice_read() hands out large page cache folios and kmap_local_page() only maps the first page.
So a fuse server on a 32-bit HIGHMEM guest that splices a WRITE request into a virtio port crashes mainline:
BUG: unable to handle page fault for address: fffab000 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page EIP: pipe_to_sg+0x184/0x2b0 Call Trace: __splice_from_pipe+0xd6/0x1f0 port_fops_splice_write+0xf9/0x170 do_splice+0x2c1/0x810 __ia32_sys_splice+0x2e7/0x310
So we need to copy per page which would fix both.
Christian Brauner
maintainerRe: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 1 line · Christian Brauner
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 <[email protected]>
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.
--- drivers/char/virtio_console.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/char/virtio_console.c +11 -4
@@ -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++;
Re: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 3 lines · Christian Brauner
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:
Please no.
drivers/char/virtio_console.c static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf, · line 912
Quoted 3 lines
drivers/char/virtio_console.c +0
-3- src =kmap_local_page (buf->page); -memcpy (page_address (page) + offset, src + buf->offset, len); -kunmap_local (src);
This boils down to one memcpy.
HIGHMEM is dead. Nobody sane uses it. It *will* go away. It's already effectively never ever used.
There are some broken 32-bit arm setups that use it, and legacy museum 32-bit x86.
Don't make one memcpy() that can be inlined become this garbage:
drivers/char/virtio_console.c static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf, · line 919
Quoted 8 lines
drivers/char/virtio_console.c +8
-0+/* 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 ; + }
just because of broken shit that nobody has ever complained about or ever hit.
Linus
Christian Brauner
maintainerRe: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 30 lines · Linus Torvalds
Quoted 3 lines · Christian Brauner
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:
Please no.
drivers/char/virtio_console.c static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf, · line 912
Quoted 3 lines
drivers/char/virtio_console.c +0
-3- src =kmap_local_page (buf->page); -memcpy (page_address (page) + offset, src + buf->offset, len); -kunmap_local (src);This boils down to one memcpy.
HIGHMEM is dead. Nobody sane uses it. It *will* go away. It's already effectively never ever used.
There are some broken 32-bit arm setups that use it, and legacy museum 32-bit x86.
Don't make one
memcpy()that can be inlined become this garbage:drivers/char/virtio_console.c static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf, · line 919
Quoted 8 lines
drivers/char/virtio_console.c +8
-0+/* 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 ; + }
Quoted 1 line
just because of broken shit that nobody has ever complained about or ever hit.
If that's the official new stance than I'm very happy.
I went by what we have historically done and very recent history still has us fixing HIGHMEM shit.
So if this is an official thing that we can now say: "Fuck it, we don't care about HIGHMEM and will ignore bugs because". Then why can't we just completely kill it for say v7.5?
Re: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 2 lines · Christian Brauner
If that's the official new stance than I'm very happy.
I definitely want to remove HIGHMEM entirely in the not too distant future. And before we remove it, we can most definitely document the fact that we will not be worried about insane users.
And things like security issues count as "insane user": if you use HIGHMEM outside of controlled embedded setups or museum pieces you get to keep both pieces when it breaks.
IOW, it's legacy. We should aim to not introduce *new* bugs to it, but if there are pre-existing bugs they very much count as "don't care", this will be removed soon.
I think the only reason it wasn't removed a couple of years ago already is basically a few old 32-bit ARM platforms that still used it.
Those platforms still exist, and I predict that they'll still exist next year, but if those users have to stay at the current LTS kernel, that's fine.
Linus
Arnd Bergmann
maintainerRe: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 8 lines · Linus Torvalds
Quoted 2 lines · Christian Brauner
If that's the official new stance than I'm very happy.
I definitely want to remove HIGHMEM entirely in the not too distant future. And before we remove it, we can most definitely document the fact that we will not be worried about insane users.
Quoted 7 lines
And things like security issues count as "insane user": if you use HIGHMEM outside of controlled embedded setups or museum pieces you get to keep both pieces when it breaks.
IOW, it's legacy. We should aim to not introduce *new* bugs to it, but if there are pre-existing bugs they very much count as "don't care", this will be removed soon.
Agreed. There is also the option of adding Kconfig dependencies to mark things that are known broken with highmem when we either know that it is buggy, or we have a good reason to break something that none of those remaining users should be using.
Quoted 7 lines
I think the only reason it wasn't removed a couple of years ago already is basically a few old 32-bit ARM platforms that still used it.
Those platforms still exist, and I predict that they'll still exist next year, but if those users have to stay at the current LTS kernel, that's fine.
I tried to push for what I thought was an aggressive timeline last year, but that would still keep the Arm bits for a couple more LTS releases and only gradually reduce the scope of highmem in the meantime, removing support from architectures, file systems, and drivers where possible. See https://lwn.net/Articles/1051010/
for a summary of my talk in Tokyo, including the slides and a link to the video for anyone wanting more details.
I also prepared a number of patches towards this, but have so far not been great at following up to get them merged, sorry about that.
I definitely still want to revisit this soon, in particular the bits about defaulting to VMSPLIT_2G_OPT, and probably my patch to allow having (limited) discontiguous lowmem on Arm systems with a large MMIO hole.
Scope-wise I think we absolutely need zsmalloc (zram/zswap) on arm32 to work with GFP_HIGHUSER, but enough people have told me that they still expect to need anonymous memory and ext4 page cache for a while, and probably powerpc32. The majority of __GFP_HIGHMEM allocations can probably just be converted to use lowmem, which would eliminate a good chunk of kmap() calls as well. In my attempts to do that, I came across two problems I'd have to solve though:
- Movable allocations (GFP_HIGHUSER_MOVABLE) imply highmem. while I think only 64-bit architectures support movable pages today, we cannot currently express an allocation that should be movable on 64-bit but lowmem on 32-bit.
- Internal users of tmpfs (in particular DRM/GEM) usually don't want highmem or movable pages, but actual tmpfs does default to GFP_HIGHUSER_MOVABLE. Separating the two is complicated.
I added a few people to Cc here that I believe care about having several more LTS releases with some highmem support because of existing customer requirements.
Arnd
Re: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 38 lines · Arnd Bergmann
Quoted 8 lines · Linus Torvalds
Quoted 2 lines · Christian Brauner
If that's the official new stance than I'm very happy.
I definitely want to remove HIGHMEM entirely in the not too distant future. And before we remove it, we can most definitely document the fact that we will not be worried about insane users.
Quoted 7 lines
And things like security issues count as "insane user": if you use HIGHMEM outside of controlled embedded setups or museum pieces you get to keep both pieces when it breaks.
IOW, it's legacy. We should aim to not introduce *new* bugs to it, but if there are pre-existing bugs they very much count as "don't care", this will be removed soon.
Agreed. There is also the option of adding
Kconfigdependencies to mark things that are known broken with highmem when we either know that it is buggy, or we have a good reason to break something that none of those remaining users should be using.Quoted 7 lines
I think the only reason it wasn't removed a couple of years ago already is basically a few old 32-bit ARM platforms that still used it.
Those platforms still exist, and I predict that they'll still exist next year, but if those users have to stay at the current LTS kernel, that's fine.
I tried to push for what I thought was an aggressive timeline last year, but that would still keep the Arm bits for a couple more LTS releases and only gradually reduce the scope of highmem in the meantime, removing support from architectures, file systems, and drivers where possible. See https://lwn.net/Articles/1051010/
for a summary of my talk in Tokyo, including the slides and a link to the video for anyone wanting more details.
Quoted 3 lines
I also prepared a number of patches towards this, but have so far not been great at following up to get them merged, sorry about that.
I think we can already start at removing CONFIG_HIGHPTE now, right?
Signature · 3 lines
Cheers, David
Arnd Bergmann
maintainerRe: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 11 lines · David Hildenbrand (Arm)
Quoted 10 lines · Arnd Bergmann
On Wed, Nov 11, 2026, at 20:26, Linus Torvalds wrote:
I tried to push for what I thought was an aggressive timeline last year, but that would still keep the Arm bits for a couple more LTS releases and only gradually reduce the scope of highmem in the meantime, removing support from architectures, file systems, and drivers where possible. See https://lwn.net/Articles/1051010/
for a summary of my talk in Tokyo, including the slides and a link to the video for anyone wanting more details.
Quoted 5 lines
Quoted 3 lines
I also prepared a number of patches towards this, but have so far not been great at following up to get them merged, sorry about that.
I think we can already start at removing
CONFIG_HIGHPTEnow, right?
Yes, I think my patch from two years ago still applies, see
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
If not, I can send you an updated version.
Arnd
Re: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · David Hildenbrand (Arm)
Quoted 12 lines · Arnd Bergmann
I tried to push for what I thought was an aggressive timeline last year, but that would still keep the Arm bits for a couple more LTS releases and only gradually reduce the scope of highmem in the meantime, removing support from architectures, file systems, and drivers where possible. See https://lwn.net/Articles/1051010/
for a summary of my talk in Tokyo, including the slides and a link to the video for anyone wanting more details.I also prepared a number of patches towards this, but have so far not been great at following up to get them merged, sorry about that.
Quoted 8 lines
Quoted 1 line
I think we can already start at removing
CONFIG_HIGHPTEnow, right?Yes, I think my patch from two years ago still applies, see
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/If not, I can send you an updated version.
yes, please, that also brings it up to reviewer's attention :)
Signature · 3 lines
Cheers, David
Arnd Bergmann
maintainerRe: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 18 lines · David Hildenbrand (Arm)
Quoted 17 lines · Arnd Bergmann
Quoted 15 lines · David Hildenbrand (Arm)
Quoted 9 lines · Arnd Bergmann
I tried to push for what I thought was an aggressive timeline last year, but that would still keep the Arm bits for a couple more LTS releases and only gradually reduce the scope of highmem in the meantime, removing support from architectures, file systems, and drivers where possible. See https://lwn.net/Articles/1051010/
for a summary of my talk in Tokyo, including the slides and a link to the video for anyone wanting more details.Quoted 3 lines
I also prepared a number of patches towards this, but have so far not been great at following up to get them merged, sorry about that.
I think we can already start at removing
CONFIG_HIGHPTEnow, right?
Quoted 8 lines
Quoted 6 lines
Yes, I think my patch from two years ago still applies, see
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/If not, I can send you an updated version.
yes, please, that also brings it up to reviewer's attention :)
Ok, I have rebased my old patches to 7.4-rc2 now and pushed them to
https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/log/?h=highmem-7.4
I'll do some more build testing on this version before I post them to the list.
Arnd
Arnd Bergmann
maintainerRe: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 3 lines · Arnd Bergmann
I'll do some more build testing on this version before I post them to the list.
Posted with a somewhat shorter Cc list at
https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#t
Arnd
Re: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
Quoted 3 lines · Arnd Bergmann
Posted with a somewhat shorter Cc list at
https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#t
Lovely.
I'd love to expand on this kind of early removal: anybody want to get brownie points by just removing the remaining users of the legacy 'kmap()' interface entirely?
I don't think we actually have that many of them. Almost all users have already been converted to 'kmap_local_page()' and friends.
If we got rid of the legacy kmap() case, I think that would get rid of the whole "pkmap_page_table[]" mess and the PKMAP_BASE / PKMAP_END / PKMAP_ADDR games and only use the FIXMAP area.
Linus
[email protected]
AI reviewRe: [PATCH 1/4] virtio_console: copy pipe buffers in splice_write()
In reply to Kiryl Shutsemau (Meta)Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
pipe_to_sg()tries to steal the page of each pipe buffer and pass it to the host as it is. When the steal fails, it copies the data into a page of its own.Pages written into the pipe with
write(), gifted user pages and page cache pages can be stolen. The ftrace ring buffer pages that virtio-trace splices cannot, so that in-tree user always gets the copy.
Quoted 6 lines
Always copy. The data that reaches the host does not change.
Preparation for removing ->try_steal() from pipe buffers.
Suggested-by Linus Torvalds <[email protected]>Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/4 fuse: don't move pipe buffers into the page cache
In reply to Kiryl Shutsemau (Meta)A splice() into /dev/fuse with SPLICE_F_MOVE lets the reply to a read request steal full pages from the pipe. Each stolen page replaces, in the fuse file's page cache, the folio that the request allocated. The page can be a page cache folio of another file, a page written into the pipe, or a gifted user page.
Always copy. The server sees the same data, and the move was a hint that splice() never promised to honour.
Keep advertising FUSE_SPLICE_MOVE. libfuse fails the mount of a filesystem that asks for a capability the kernel does not offer.
Preparation for removing ->try_steal() from pipe buffers.
--- fs/fuse/args.h | 1 - fs/fuse/dev.c | 144 +------------------------------------------ fs/fuse/file.c | 1 - fs/fuse/fuse_dev_i.h | 1 - 4 files changed, 3 insertions(+), 144 deletions(-)
fs/fuse/args.h +0 -1
@@ -36,7 +36,6 @@ struct fuse_args { bool user_pages:1; bool out_argvar:1; bool page_zeroing:1; - bool page_replace:1; bool may_block:1; bool is_ext:1; bool is_pinned:1;
fs/fuse/dev.c +3 -141
180 lines not on this page · raw message
fs/fuse/file.c +0 -1
@@ -1096,7 +1096,6 @@ static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file, ap->args.out_pages = true; ap->args.page_zeroing = true; - ap->args.page_replace = true;/* * Don't overflow end offset.
fs/fuse/fuse_dev_i.h +0 -1
@@ -326,7 +326,6 @@ struct fuse_copy_state {unsigned int len;unsigned int offset; bool write:1; - bool move_folios:1; bool is_uring:1;/* set when the payload is zero-copied. folios are filled in place */ bool skip_folio_copy:1;
Signature · 1 line
2.54.0
Re: [PATCH 2/4] fuse: don't move pipe buffers into the page cache
Quoted 17 lines · Kiryl Shutsemau (Meta)
A
splice()into/dev/fusewithSPLICE_F_MOVElets the reply to a read request steal full pages from the pipe. Each stolen page replaces, in the fuse file's page cache, the folio that the request allocated. The page can be a page cache folio of another file, a page written into the pipe, or a gifted user page.Always copy. The server sees the same data, and the move was a hint that
splice()never promised to honour.Keep advertising
FUSE_SPLICE_MOVE. libfuse fails the mount of a filesystem that asks for a capability the kernel does not offer.Preparation for removing ->try_steal() from pipe buffers.
Suggested-by David Hildenbrand (Arm) <[email protected]>Suggested-by Linus Torvalds <[email protected]>Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>
Quoted 7 lines
--- fs/fuse/args.h | 1 - fs/fuse/dev.c | 144 +------------------------------------------ fs/fuse/file.c | 1 - fs/fuse/fuse_dev_i.h | 1 - 4 files changed, 3 insertions(+), 144 deletions(-)
LGTM.
Best Regards,
Yan, Zi
[email protected]
AI reviewRe: [PATCH 2/4] fuse: don't move pipe buffers into the page cache
In reply to Kiryl Shutsemau (Meta)Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
A
splice()into/dev/fusewithSPLICE_F_MOVElets the reply to a read request steal full pages from the pipe. Each stolen page replaces, in the fuse file's page cache, the folio that the request allocated. The page can be a page cache folio of another file, a page written into the pipe, or a gifted user page.Always copy. The server sees the same data, and the move was a hint that
splice()never promised to honour.
Quoted 8 lines
Keep advertising
FUSE_SPLICE_MOVE. libfuse fails the mount of a filesystem that asks for a capability the kernel does not offer.Preparation for removing ->try_steal() from pipe buffers.
Suggested-by David Hildenbrand (Arm) <[email protected]>Suggested-by Linus Torvalds <[email protected]>Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/4] fuse: don't move pipe buffers into the page cache
In reply to Kiryl Shutsemau (Meta)Quoted 9 lines · Kiryl Shutsemau (Meta)
A
splice()into/dev/fusewithSPLICE_F_MOVElets the reply to a read request steal full pages from the pipe. Each stolen page replaces, in the fuse file's page cache, the folio that the request allocated. The page can be a page cache folio of another file, a page written into the pipe, or a gifted user page.Always copy. The server sees the same data, and the move was a hint that
splice()never promised to honour.
Did some research and looks like this feature is not used by any major project.
Thanks,
Miklos
PATCH 3/4 splice: remove pipe buffer stealing
In reply to Kiryl Shutsemau (Meta)Nothing calls pipe_buf_try_steal() any more. Remove ->try_steal() from struct pipe_buf_operations, its implementations and the exported generic_pipe_buf_try_steal().
PIPE_BUF_FLAG_LRU and PIPE_BUF_FLAG_GIFT were set only for stealing, and go too. page_cache_pipe_buf_release() did nothing but drop the page and the LRU flag, so page cache and user page buffers use generic_pipe_buf_release().
vmsplice() still accepts SPLICE_F_GIFT, and splice() SPLICE_F_MOVE. Both were hints, and nothing acts on them now.
--- fs/pipe.c | 43 ------------------ fs/splice.c | 96 +++------------------------------------ include/linux/pipe_fs_i.h | 36 --------------- kernel/watch_queue.c | 4 -- mm/shmem.c | 7 --- 5 files changed, 6 insertions(+), 180 deletions(-)
fs/pipe.c +0 -43
@@ -222,48 +222,6 @@ static void anon_pipe_buf_release(struct pipe_inode_info *pipe,anon_pipe_put_page (pipe, page); } -static bool anon_pipe_buf_try_steal (struct pipe_inode_info *pipe, -struct pipe_buffer *buf) -{ -struct page *page = buf->page; - -if (page_count (page) !=1 ) -return false; -memcg_kmem_uncharge_page (page,0 ); -__SetPageLocked (page); -return true; -} - -/** -* generic_pipe_buf_try_steal - attempt to take ownership of a &pipe_buffer -* @pipe: the pipe that the buffer belongs to -* @buf: the buffer to attempt to steal -* -* Description: -* This function attempts to steal the &struct page attached to -* @buf. If successful, this function returns 0 and returns with -* the page locked. The caller may then reuse the page for whatever -* he wishes; the typical use is insertion into a different file -* page cache. -*/ -bool generic_pipe_buf_try_steal (struct pipe_inode_info *pipe, -struct pipe_buffer *buf) -{ -struct page *page = buf->page; - -/* -* A reference of one is golden, that means that the owner of this -* page is the only one holding a reference to it. lock the page -* and return OK. -*/ -if (page_count (page) ==1 ) { -lock_page (page); -return true; - } -return false; -} -EXPORT_SYMBOL (generic_pipe_buf_try_steal); -/** * generic_pipe_buf_get - get a reference to a &struct pipe_buffer * @pipe: the pipe that the buffer belongs to
@@ -297,7 +255,6 @@ EXPORT_SYMBOL(generic_pipe_buf_release);static const struct pipe_buf_operations anon_pipe_buf_ops = { .release = anon_pipe_buf_release, - .try_steal = anon_pipe_buf_try_steal, .get = generic_pipe_buf_get, };
fs/splice.c +6 -90
151 lines not on this page · raw message
include/linux/pipe_fs_i.h +0 -36
@@ -4,9 +4,7 @@#define PIPE_DEF_BUFFERS 16 -#define PIPE_BUF_FLAG_LRU 0x01/* page is on the LRU */ #define PIPE_BUF_FLAG_ATOMIC 0x02/* was atomically mapped */ -#define PIPE_BUF_FLAG_GIFT 0x04/* page is a gift */ #define PIPE_BUF_FLAG_PACKET 0x08/* read() as a packet */ #define PIPE_BUF_FLAG_CAN_MERGE 0x10/* can merge buffers */ #define PIPE_BUF_FLAG_WHOLE 0x20/* read() must return entire buffer or error */
@@ -127,16 +125,6 @@ struct pipe_inode_info {#endif }; -/* -* Note on the nesting of these functions: -* -* ->confirm() -* ->try_steal() -* -* That is, ->try_steal() must be called on a confirmed buffer. See below for -* the meaning of each operation. Also see the kerneldoc in fs/pipe.c for the -* pipe and generic variants of these hooks. -*/ struct pipe_buf_operations {/* * ->confirm() verifies that the data in the pipe buffer is there
@@ -153,16 +141,6 @@ struct pipe_buf_operations {*/ void (*release)(struct pipe_inode_info *,struct pipe_buffer *); -/* -* Attempt to take ownership of the pipe buffer and its contents. -* ->try_steal() returns %true for success, in which case the contents -* of the pipe (the buf->page) is locked and now completely owned by the -* caller. The page may then be transferred to a different mapping, the -* most often used case is insertion into different file address space -* cache. -*/ -bool (*try_steal)(struct pipe_inode_info *,struct pipe_buffer *); -/* * Get a reference to the pipe buffer. */
@@ -304,19 +282,6 @@ static inline int pipe_buf_confirm(struct pipe_inode_info *pipe,return buf->ops->confirm (pipe, buf); } -/** -* pipe_buf_try_steal - attempt to take ownership of a pipe_buffer -* @pipe: the pipe that the buffer belongs to -* @buf: the buffer to attempt to steal -*/ -static inline bool pipe_buf_try_steal (struct pipe_inode_info *pipe, -struct pipe_buffer *buf) -{ -if (!buf->ops->try_steal) -return false; -return buf->ops->try_steal (pipe, buf); -} -/* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual memory allocation, whereas PIPE_BUF makes atomicity guarantees. */ #define PIPE_SIZE PAGE_SIZE
@@ -335,7 +300,6 @@ void free_pipe_info(struct pipe_inode_info *);/* Generic pipe buffer ops functions */ bool generic_pipe_buf_get (struct pipe_inode_info *,struct pipe_buffer *); -bool generic_pipe_buf_try_steal (struct pipe_inode_info *,struct pipe_buffer *);void generic_pipe_buf_release (struct pipe_inode_info *,struct pipe_buffer *);extern const struct pipe_buf_operations nosteal_pipe_buf_ops;
kernel/watch_queue.c +0 -4
@@ -77,13 +77,9 @@ static void watch_queue_pipe_buf_release(struct pipe_inode_info *pipe,generic_pipe_buf_release (pipe, buf); } -// No try_steal function => no stealing -#define watch_queue_pipe_buf_try_steal NULL -/* New data written to a pipe may be appended to a buffer with this type. */ static const struct pipe_buf_operations watch_queue_pipe_buf_ops = { .release = watch_queue_pipe_buf_release, - .try_steal = watch_queue_pipe_buf_try_steal, .get = generic_pipe_buf_get, };
mm/shmem.c +0 -7
@@ -3655,15 +3655,8 @@ static void zero_pipe_buf_release(struct pipe_inode_info *pipe, { } -static bool zero_pipe_buf_try_steal (struct pipe_inode_info *pipe, -struct pipe_buffer *buf) -{ -return false; -} -static const struct pipe_buf_operations zero_pipe_buf_ops = { .release = zero_pipe_buf_release, - .try_steal = zero_pipe_buf_try_steal, .get = zero_pipe_buf_get, };
Signature · 1 line
2.54.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 9 lines
Nothing calls
pipe_buf_try_steal()any more. Remove ->try_steal() from structpipe_buf_operations, its implementations and the exportedgeneric_pipe_buf_try_steal().
PIPE_BUF_FLAG_LRUandPIPE_BUF_FLAG_GIFTwere set only for stealing, and go too.page_cache_pipe_buf_release()did nothing but drop the page and the LRU flag, so page cache and user page buffers usegeneric_pipe_buf_release().
Quoted 5 lines
vmsplice()still acceptsSPLICE_F_GIFT, andsplice()SPLICE_F_MOVE. Both were hints, and nothing acts on them now.Suggested-by Linus Torvalds <[email protected]>Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH 4/4 splice: replace nosteal_pipe_buf_ops with default_pipe_buf_ops
In reply to Kiryl Shutsemau (Meta)Without ->try_steal(), nosteal_pipe_buf_ops and default_pipe_buf_ops are the same: generic_pipe_buf_release() and generic_pipe_buf_get().
Keep default_pipe_buf_ops, and use it in skb_splice_bits() and fuse_dev_splice_read(). Export it in place of nosteal_pipe_buf_ops, since fuse can be built as a module.
--- fs/fuse/dev.c | 2 +- fs/splice.c | 8 +------- include/linux/pipe_fs_i.h | 2 -- net/core/skbuff.c | 2 +- 4 files changed, 3 insertions(+), 11 deletions(-)
fs/fuse/dev.c +1 -1
@@ -1627,7 +1627,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,* Need to be careful about this. Having buf->ops in module * code can Oops if the buffer persists after module unload. */ - bufs[page_nr].ops = &nosteal_pipe_buf_ops; + bufs[page_nr].ops = &default_pipe_buf_ops; bufs[page_nr].flags =0 ; ret =add_to_pipe (pipe, &bufs[page_nr++]);if (unlikely (ret <0 ))
fs/splice.c +1 -7
@@ -333,13 +333,7 @@ const struct pipe_buf_operations default_pipe_buf_ops = { .release = generic_pipe_buf_release, .get = generic_pipe_buf_get, }; - -/* Pipe buffer operations for a socket and similar. */ -const struct pipe_buf_operations nosteal_pipe_buf_ops = { - .release = generic_pipe_buf_release, - .get = generic_pipe_buf_get, -}; -EXPORT_SYMBOL (nosteal_pipe_buf_ops); +EXPORT_SYMBOL (default_pipe_buf_ops);static void wakeup_pipe_writers (struct pipe_inode_info *pipe) {
include/linux/pipe_fs_i.h +0 -2
@@ -302,8 +302,6 @@ void free_pipe_info(struct pipe_inode_info *);bool generic_pipe_buf_get (struct pipe_inode_info *,struct pipe_buffer *);void generic_pipe_buf_release (struct pipe_inode_info *,struct pipe_buffer *); -extern const struct pipe_buf_operations nosteal_pipe_buf_ops; -unsigned long account_pipe_buffers (struct user_struct *user,unsigned long old,unsigned long new);bool too_many_pipe_buffers_soft (unsigned long user_bufs);
net/core/skbuff.c +1 -1
@@ -3281,7 +3281,7 @@ int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset, .pages = pages, .partial = partial, .nr_pages_max = MAX_SKB_FRAGS, - .ops = &nosteal_pipe_buf_ops, + .ops = &default_pipe_buf_ops, .spd_release = sock_spd_release, };int ret =0 ;
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 4/4] splice: replace nosteal_pipe_buf_ops with default_pipe_buf_ops
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Without ->try_steal(),
nosteal_pipe_buf_opsanddefault_pipe_buf_opsare the same:generic_pipe_buf_release()andgeneric_pipe_buf_get().Keep
default_pipe_buf_ops, and use it inskb_splice_bits()andfuse_dev_splice_read(). Export it in place ofnosteal_pipe_buf_ops, since fuse can be built as a module.Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Quoted 2 lines · Kiryl Shutsemau (Meta)
11 files changed, 26 insertions(+), 360 deletions(-)
Ack. Lovely. I'm considering just taking this as-is now, rather than delaying it. Comments?
Linus
Christian Brauner
maintainerQuoted 6 lines · Linus Torvalds
Quoted 2 lines · Kiryl Shutsemau (Meta)
11 files changed, 26 insertions(+), 360 deletions(-)Ack. Lovely. I'm considering just taking this as-is now, rather than delaying it. Comments?
I'll pull it into vfs.fixes and send you a pull request today. I have more stuff anyway.