vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2
Subsystems (12)
cover vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2
This patchset is for VFS.
Recently we got a lot of vulnerabilities in splice/vmsplice.
Also vmsplice already was source of vulnerabilities in the past:
CVE-2020-29374 (see https://lwn.net/Articles/849638/ ).
Also vmsplice is problematic for other reasons. Here is what other developers say:
Linus Torvalds in 2023:
Quoted 4 lines
So I'd personally be perfectly ok with just making
vmsplice()be exactly the same as write, and turn all ofvmsplice()into just "it's aread()if the pipe is open for read, and a write if it's open for writing".
https://lore.kernel.org/all/CAHk-=wgG_2cmHgZwKjydi7=iimyHyN8aessnbM9XQ9ufbaUz9g@mail.gmail.com/
Christoph Hellwig in May 2026:
Quoted 5 lines
vmsplice is the worst, as it is one of the few remaining places that can incorrectly dirty file backed pages without telling the file system and cause the other problems fixed by a
FOLL_PINconversion, but it is the only one where we do not have any idea yet how we could convert it toFOLL_PINdue to the unbounded pin time.
https://lore.kernel.org/all/[email protected]/
See recent discussion here:
https://lore.kernel.org/all/[email protected]/T/#u
For all these reasons I propose to make vmsplice a simple wrapper for preadv2/pwritev2.
vmsplice(fd, vec, vlen, vmsplice_flags) will
be equivalent to preadv2(fd, vec, vlen, -1, rw_flags) if you have readable pipe and to pwritev2(fd, vec, vlen, -1, rw_flags) if you have writable pipe.
SPLICE_F_NONBLOCK is translated to RWF_NOWAIT, all other SPLICE_F_* flags are ignored.
There is a small change to handling of NONBLOCK-related flags, see commit messages for details.
I tested this patch in Qemu.
This patchset was written by me, not by LLMs.
Askar Safin (3):
tee: fs/splice.c: remove unused parameter "flags" from "link_pipe"
vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2
splice: remove PIPE_BUF_FLAG_GIFT
fs/fuse/dev.c | 1 - fs/read_write.c | 23 +++++ fs/splice.c | 202 +------------------------------------- include/linux/pipe_fs_i.h | 1 - include/linux/skbuff.h | 4 +- include/linux/splice.h | 2 +- include/linux/syscalls.h | 4 +- 7 files changed, 33 insertions(+), 204 deletions(-)
base-commit: e7ae89a0c97ce2b68b0983cd01eda67cf373517d (7.1-rc5)
Signature · 1 line
2.47.3
PATCH 1/3 tee: fs/splice.c: remove unused parameter "flags" from "link_pipe"
Remove unused parameter "flags" from "link_pipe".
--- fs/splice.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/splice.c +2 -2
@@ -1849,7 +1849,7 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe,*/ static ssize_t link_pipe (struct pipe_inode_info *ipipe,struct pipe_inode_info *opipe, -size_t len,unsigned int flags) +size_t len) {struct pipe_buffer *ibuf, *obuf;unsigned int i_head, o_head;
@@ -1962,7 +1962,7 @@ ssize_t do_tee(struct file *in, struct file *out, size_t len,if (!ret) { ret =opipe_prep (opipe, flags);if (!ret) - ret =link_pipe (ipipe, opipe, len, flags); + ret =link_pipe (ipipe, opipe, len); } }
Signature · 1 line
2.47.3
PATCH 2/3 vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2
In reply to Askar Safinvmsplice behavior on writable pipe became equivalent to pwritev2. vmsplice behavior on readable pipe already was nearly equivalent to preadv2, but I made this explicit. I. e. I made it obvious from code that vmsplice now is equivalent to preadv2/pwritev2.
Also I moved vmsplice to fs/read_write.c, because now it arguably belongs there.
Note that SPLICE_F_NONBLOCK behavior slightly changed: previously vmsplice ignored whether the pipe was opened with O_NONBLOCK, and mode of operation depended on whether SPLICE_F_NONBLOCK was passed only. Now the operation will be non-blocking if O_NONBLOCK was passed when opening *or* SPLICE_F_NONBLOCK was passed to vmsplice. Previous behavior was arguably buggy, and new behavior is arguably better.
Now SPLICE_F_GIFT is always ignored by all 3 syscalls: splice, tee and vmsplice.
--- fs/read_write.c | 23 +++++ fs/splice.c | 192 +-------------------------------------- include/linux/skbuff.h | 4 +- include/linux/splice.h | 2 +- include/linux/syscalls.h | 4 +- 5 files changed, 29 insertions(+), 196 deletions(-)
fs/read_write.c +23 -0
@@ -1213,6 +1213,29 @@ SYSCALL_DEFINE6(pwritev2, unsigned long, fd, const struct iovec __user *, vec,return do_pwritev (fd, vec, vlen, pos, flags); } +/* +* Legacy preadv2/pwritev2 wrapper. +*/ +SYSCALL_DEFINE4(vmsplice, unsigned long, fd, const struct iovec __user *, vec, + unsigned long, vlen, unsigned int, flags) +{ +if (unlikely (flags & ~SPLICE_F_ALL )) +return -EINVAL ; + +CLASS (fd, f)(fd); +if (fd_empty (f)) +return -EBADF ; + +/* We do do_writev/do_readv, so it is okay to pass "false" here */ +if (!get_pipe_info (fd_file (f),/* for_splice = */ false)) +return -EBADF ; + +if (fd_file (f)->f_mode &FMODE_WRITE ) +return do_writev (fd, vec, vlen, (flags &SPLICE_F_NONBLOCK ) ?RWF_NOWAIT :0 ); +else +return do_readv (fd, vec, vlen, (flags &SPLICE_F_NONBLOCK ) ?RWF_NOWAIT :0 ); +} +/* * Various compat syscalls. Note that they all pretend to take a native * iovec - import_iovec will properly treat those as compat_iovecs based on
fs/splice.c +1 -191
210 lines not on this page · raw message
include/linux/skbuff.h +2 -2
@@ -505,7 +505,7 @@ enum { SKBFL_ZEROCOPY_ENABLE = BIT(0),/* This indicates at least one fragment might be overwritten -* (as in vmsplice(), sendfile() ...) +* (as in sendfile(), ...) * If we need to compute a TX checksum, we'll need to copy * all frags to avoid possible bad checksum */
@@ -4017,7 +4017,7 @@ static inline int skb_linearize(struct sk_buff *skb)* @skb: buffer to test * * Return: true if the skb has at least one frag that might be modified -* by an external entity (as in vmsplice()/sendfile()) +* by an external entity (as in sendfile()) */ static inline bool skb_has_shared_frag (const struct sk_buff *skb) {
include/linux/splice.h +1 -1
@@ -19,7 +19,7 @@/* we may still block on the fd we splice */ /* from/to, of course */ #define SPLICE_F_MORE (0x04)/* expect more data */ -#define SPLICE_F_GIFT (0x08)/* pages passed in are a gift */ +#define SPLICE_F_GIFT (0x08)/* ignored */ #define SPLICE_F_ALL (SPLICE_F_MOVE|SPLICE_F_NONBLOCK|SPLICE_F_MORE|SPLICE_F_GIFT)
include/linux/syscalls.h +2 -2
@@ -514,8 +514,8 @@ asmlinkage long sys_ppoll_time32(struct pollfd __user *, unsigned int, struct old_timespec32 __user *, const sigset_t __user *, size_t);asmlinkage long sys_signalfd4 (int ufd,sigset_t __user *user_mask,size_t sizemask,int flags); -asmlinkage long sys_vmsplice (int fd,const struct iovec __user *iov, -unsigned long nr_segs,unsigned int flags); +asmlinkage long sys_vmsplice (unsigned long fd,const struct iovec __user *vec, +unsigned long vlen,unsigned int flags);asmlinkage long sys_splice (int fd_in,loff_t __user *off_in,int fd_out,loff_t __user *off_out,size_t len,unsigned int flags);
Signature · 1 line
2.47.3
Hi Askar,
include/linux/syscalls.h asmlinkage long sys_ppoll_time32(struct pollfd __user *, unsigned int, · line 518
Quoted 12 lines
include/linux/syscalls.h +2
-2@@ -514,8 +514,8 @@ asmlinkage long sys_ppoll_time32(struct pollfd __user *, unsigned int, struct old_timespec32 __user *, const sigset_t __user *, size_t);asmlinkage long sys_signalfd4 (int ufd,sigset_t __user *user_mask,size_t sizemask,int flags); -asmlinkage long sys_vmsplice (int fd,const struct iovec __user *iov, -unsigned long nr_segs,unsigned int flags); +asmlinkage long sys_vmsplice (unsigned long fd,const struct iovec __user *vec, +unsigned long vlen,unsigned int flags);
Why is 'int fd' changed to 'unsigned long fd'? Should that be its own commit if the change is desired?
metze
Stefan Metzmacher <[email protected]>:
Quoted 1 line
Why is 'int fd' changed to 'unsigned long fd'?
Because preadv2 and pwritev2 take "unsigned long". I want vmsplice to be as similar as possible to preadv2 and pwritev2.
Quoted 1 line
Should that be its own commit if the change is desired?
Yes, possibly. But this patchset already got to next.
Signature · 1 line
Askar Safin
Quoted 5 lines · On Thu, 4 Jun 2026 00:17:36 +0300 Askar Safin <[email protected]> wrote:
Stefan Metzmacher <[email protected]>:
Quoted 1 line
Why is 'int fd' changed to 'unsigned long fd'?
Because preadv2 and pwritev2 take "unsigned long". I want vmsplice to be as similar as possible to preadv2 and pwritev2.
Something needs to ensure that the high 32bits of the fd get masked off on 64bit systems.
They can be non-zero in the register that comes from userspace.
-- David
Quoted 5 lines
Quoted 2 lines
Should that be its own commit if the change is desired?
Yes, possibly. But this patchset already got to next.
Quoted 3 lines · David Laight
Something needs to ensure that the high 32bits of the fd get masked off on 64bit systems.
That something already exists: CLASS(fd, f)(fd);
It ignores the top bits, because 'fdget()' takes an 'unsigned int'.
We have been a bit random in how we declare the system calls in general, and we mix 'unsigned int' and 'int' and 'unsigned long' pretty much randomly when it comes to file descriptor arguments to system calls.
fs/read_write.c in particular uses all three cases with no real logic to it all:
SYSCALL_DEFINE3(lseek, unsigned int, fd, ..
SYSCALL_DEFINE3(readv, unsigned long, fd, ..
SYSCALL_DEFINE4(sendfile, int, out_fd, ..
but then anything that uses fdget() (through one of the helper classes or not) will simply not care.
Does it make sense? Is it pretty? Nope. Does it matter? Also nope.
Linus
Quoted 16 lines · On Thu, 4 Jun 2026 07:17:10 -0700 Linus Torvalds…
Quoted 3 lines · David Laight
Something needs to ensure that the high 32bits of the fd get masked off on 64bit systems.
That something already exists:
CLASS(fd, f)(fd);It ignores the top bits, because '
fdget()' takes an 'unsigned int'.We have been a bit random in how we declare the system calls in general, and we mix 'unsigned int' and 'int' and 'unsigned long' pretty much randomly when it comes to file descriptor arguments to system calls.
fs/read_write.cin particular uses all three cases with no real logic to it all:
Quoted 8 lines
SYSCALL_DEFINE3(lseek, unsigned int, fd, ..
SYSCALL_DEFINE3(readv, unsigned long, fd, ..
SYSCALL_DEFINE4(sendfile, int,out_fd, ..but then anything that uses
fdget()(through one of the helper classes or not) will simply not care.Does it make sense? Is it pretty? Nope. Does it matter? Also nope.
I know it has mattered elsewhere, and is easy to get wrong because 'mostly it works'.
At least u32/u64 is reasonably sane - the called function has to ignore the high bits (at least on x86).
Bool is another matter entirely, (IIRC from a couple of weeks ago) gcc will assume that the low 8 bits of the parameter register are either 0 or 1 and clang assumes that the low 32 bits are 0 or 1. You can't even check with 'if ((u32)bool_param > 1) error()' because the compiler 'knows' it can't be false.
It all dumps you down one of the UB 'rabbit holes'.
-- David
Quoted 2 lines
Linus
Quoted 6 lines · David Laight
Bool is another matter entirely, (IIRC from a couple of weeks ago) gcc will assume that the low 8 bits of the parameter register are either 0 or 1 and clang assumes that the low 32 bits are 0 or 1. You can't even check with 'if ((u32)bool_param > 1)
error()' because the compiler 'knows' it can't be false.
Nobody should ever use 'bool' as a system call argument. Anything that takes a boolean should take a 'flags' field with bits.
But this is basically what a lot of the SYSCALL_DEFINEx() macros are all about - sorting out ABI assumptions.
For example, on powerpc (iirc - maybe it was 390), a 32-bit argument is always sign-extended by the ABI, and the compiler *depends* on that. But at system call boundaries we can't trust that the user side actually follows the ABI, so SYSCALL_DEFINEx() will actually take a 'unsigned long' and turn it into a 32-bit argument so that things like this are well-defined and you can't fool the kernel by not following the ABI rules.
The same would be the case if some system call actually takes bool (but I don't think such garbage exists). The SYSCALL_DEFINE() macro magic would take the full register content and *force* it to follow the ABI conventions, whatever they are on that platform.
Linus
Quoted 10 lines · On Thu, 4 Jun 2026 12:30:30 -0700 Linus Torvalds…
Quoted 6 lines · David Laight
Bool is another matter entirely, (IIRC from a couple of weeks ago) gcc will assume that the low 8 bits of the parameter register are either 0 or 1 and clang assumes that the low 32 bits are 0 or 1. You can't even check with 'if ((u32)bool_param > 1)
error()' because the compiler 'knows' it can't be false.Nobody should ever use 'bool' as a system call argument. Anything that takes a boolean should take a 'flags' field with bits.
I was thinking of more generally, not syscall arguments. In C you can't really guarantee that a 'bool' variable will always contain 0 or 1.
Even if you write: https://godbolt.org/z/81P87vv7o
int f(char *p, _Bool b)
{
return p[b ? 1 : 0];
}you get *(p + b), neither (int)b, !!b or (b & 1) make any difference.
Talking of broken compilers, had you noticed that:
struct foo {
int a;
char c[32];
};int b(struct foo *f)
{
return __builtin_object_size(f->c, 1);
}returns -1 (size unknown/indefinite).
You can't use __builtin_object_size() to stop code running off the end of anything referenced by address - even when the size is constant.
Quoted 6 lines
But this is basically what a lot of the
SYSCALL_DEFINEx()macros are all about - sorting out ABI assumptions.For example, on powerpc (iirc - maybe it was 390), a 32-bit argument is always sign-extended by the ABI, and the compiler *depends* on that.
I think riscv might sign extend 32bit values in 64bit registers. x86 and arm both zero extend.
Zero extending is more friendly to the kernel where pretty much all values are non-negative.
I think I've used signed variables slightly more often than fp in the last 47+ years.
-- David
Quoted 12 lines
But at system call boundaries we can't trust that the user side actually follows the ABI, so
SYSCALL_DEFINEx()will actually take a 'unsigned long' and turn it into a 32-bit argument so that things like this are well-defined and you can't fool the kernel by not following the ABI rules.The same would be the case if some system call actually takes bool (but I don't think such garbage exists). The
SYSCALL_DEFINE()macro magic would take the full register content and *force* it to follow the ABI conventions, whatever they are on that platform.Linus
Quoted 3 lines · David Laight
I think riscv might sign extend 32bit values in 64bit registers. x86 and arm both zero extend.
That's different.
x86 really doesn't *care*. If the caller zero-extends or leaves high bits set randomly, according to the x86 ABI that's perfectly fine: the callee will only care about the low 32 bits. So the high bits are simply not relevant for the ABI.
The Powerpc ABI makes the the sign extension part of the calling conventions.
So if a caller doesn't sign extend a 32-bit value, the result is random behavior - if you pass some function an 'int' argument, the function may end up looking at bit 63 to see if it's negative (except IBM calls it "bit 0" because they have to be different from everybody else)
Linus
* Linus Torvalds:
Quoted 11 lines · David Laight
Quoted 3 lines
I think riscv might sign extend 32bit values in 64bit registers. x86 and arm both zero extend.
That's different.
x86 really doesn't *care*. If the caller zero-extends or leaves high bits set randomly, according to the x86 ABI that's perfectly fine: the callee will only care about the low 32 bits. So the high bits are simply not relevant for the ABI.
Please note that Clang does not implement the x86-64 ABI and requires zero extension. We see increasing problems from that, now that we have more C code calling Rust code. (The other direction is generally fine.) Unfortunately, it's difficult to fix in LLVM.
In the original x86-64 psABI, this was left unspecified by omission except for the special case of _Bool. However, Clang/LLVM gets the _Bool case wrong as well, so it's not just a matter of an unclear specification.
This isn't really specific to x86-64. _Bool is simply not part of the ABI that is stable across compilers, a bit like bitfields in structs passed by value.
Thanks,
Florian
Quoted 11 lines · Florian Weimer
* Linus Torvalds:
Quoted 4 lines
x86 really doesn't *care*. If the caller zero-extends or leaves high bits set randomly, according to the x86 ABI that's perfectly fine: the callee will only care about the low 32 bits. So the high bits are simply not relevant for the ABI.
Please note that Clang does not implement the x86-64 ABI and requires zero extension. We see increasing problems from that, now that we have more C code calling Rust code.
Uhhuh. But that is only specific to 'bool', right?
If it were to have the same issue that powerpc(*) had - that 'unsigned int' has to be passed to functions with well-defined high bits - that would be bad.
And I'm pretty sure that clang doesn't do that.
Anyway, for the kernel, this shouldn't be an issue simply because we typically avoid 'bool' in arguments or structures that are exposed to outside.
(I say 'typically' because I'm sure it happens in some broken UAPI thing anyway).
Linus
(*) I may mis-remember. Maybe it was s390, not powerpc. The s390 compat layer independently had a similar issue wrt pointers, where bit 31 had to be cleared. s390 dropped the 31-bit code entirely fairly recently, but it caused some "interesting" code in the already disgusting syscall argument handling wrapper macros.
Quoted 6 lines · Linus Torvalds
If it were to have the same issue that
powerpc(*)had - that 'unsigned int' has to be passed to functions with well-defined high bits - that would be bad.And I'm pretty sure that clang doesn't do that.
It's perhaps worth nothing *why* it's horribly bad and why I think the powerpc ABI is nasty: it means that *some* things are done in 32 bits, but other things then expect the upper bits to always match.
It caused security issues, where user space would (for example) pass in a 'int fd' what was value in the low bits, and then had interesting upper bits.
The range check in the kernel would then compare fd to max_fds - using a 32-bit unsigned compare - and see that it is all in range.
Then it would use the *exact same fd variable* to index into the fd array, but the compiler would use the full 64-bit value for that array dereference - without having ever checked those upper bits. And it had passed the unmodified full 64-bit value around the whole time, all the way from untrusted user space, and the kernel code all looked "obviously correct" and had all the proper checks in place.
If you want to bleed out of your eyes, take a look at the rather horrendous macros in <linux/syscalls.h> (and the sometimes even more horrendous arch 'syscall_wrappers.h' files).
They deal with issues like this - and others - with some truly inscrutable code. You have to be super-human to be able to read it, but those wrappers are why we can then just do things like
SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
and it will generate not only infrastructure for tracing etc, but also the code necessary to force clean up the types for the architecture.
Linus
* Linus Torvalds:
Quoted 9 lines · Florian Weimer
Quoted 8 lines
* Linus Torvalds:
Quoted 4 lines
x86 really doesn't *care*. If the caller zero-extends or leaves high bits set randomly, according to the x86 ABI that's perfectly fine: the callee will only care about the low 32 bits. So the high bits are simply not relevant for the ABI.
Quoted 5 lines
Quoted 3 lines
Please note that Clang does not implement the x86-64 ABI and requires zero extension. We see increasing problems from that, now that we have more C code calling Rust code.
Uhhuh. But that is only specific to 'bool', right?
Also char and short. This
extern int a[];
int
f (short i)
{
return a[i];
}
gets turned into:
f:
movslq %edi, %rax movl a(,%rax,4), %eax retq
This code assumes that the short value has been previously sign-extended into %edi.
As I read the original psABI, this assumption was not valid, and the extra bits were unspecified by omission. And GCC tends to use shorter instruction encodings without extension if that does not result in partial register stalls.
Quoted 3 lines
If it were to have the same issue that
powerpc(*)had - that 'unsigned int' has to be passed to functions with well-defined high bits - that would be bad.
I would have to ask around. It's hard to tell from experiments what the expectations around int/unsigned arguments are. Clang and LLVM treat the upper bits from int/unsigned return values as undefined in some cases.
Quoted 3 lines
Anyway, for the kernel, this shouldn't be an issue simply because we typically avoid 'bool' in arguments or structures that are exposed to outside.
Right, but array indexing with u8/u16/s8/s16 function arguments is impacted, too.
Thanks,
Florian
Quoted 4 lines · Florian Weimer
Quoted 2 lines
Uhhuh. But that is only specific to 'bool', right?
Also char and short.
That sounds like a complete ABI violation as far as I can tell.
Scary. Because I would not be surprised if we have code that assumes otherwise.
Now, the kernel *seldom* uses char/short types, and since compilers are typically at least self-consistent in those cases and we don't interact directly with untrusted sources.
The system call interface is special, but we wrap that for other reasons so deeply these days that we'd not be impacted.
But we also do have various assembler code, and I certainly wasn't aware that apparently compilers have been walking away from the old ABI rules.
I did find assembler code that clearly uses just 8-bit register accesses and function calls, but it was all _entirely_ within assembler. The low-level debug printing in
arch/x86/kernel/relocate_kernel_64.S
puts the character values in %al and then calls pr_char_8250() or pr_char_8250_mmio32() with it, but that is *all* in asm code.
I didn't find anything obvious that calls C code with that kind of argument though (which makes sense - we typically call the other way:
C code calling into asm code, not the other way around).
So at a guess we're fine, but it's still somewhat unsettling.
And maybe others were aware of this, and it's just me that has old 32-bit x86 code in mind.
Linus
Quoted 6 lines · On Fri, 5 Jun 2026 10:12:05 -0700 Linus Torvalds…
Quoted 4 lines · Florian Weimer
Quoted 2 lines
Uhhuh. But that is only specific to 'bool', right?
Also char and short.
Quoted 7 lines
That sounds like a complete ABI violation as far as I can tell.
Scary. Because I would not be surprised if we have code that assumes otherwise.
Now, the kernel *seldom* uses char/short types, and since compilers are typically at least self-consistent in those cases and we don't interact directly with untrusted sources.
There are plenty of places where char/short are used for function call parameters/results (and not for single characters or similar).
I'm sure some people (even some who should really know better) think the smaller type will save space.
I've always worried about whether the calling or called code is responsible for ensuring the unused bits are zero (or maybe the sign extension of a signed value).
Clearly the compiler should obey its own rules - so mostly it is just extra instruction to do the masking.
But for interactions with asm code, and possibly code that gets mixed between gcc and clang (maybe for out of tree modules) it does matter.
You also don't really want to be doing maths of char/short (and there are quite a of of those as well). I think it is only m86 and m68k that actually have 8/16 bits maths instructions (is s390 old enough?) everywhere else the compiler has to explicitly mask the high bits.
Maybe it is time to 'nuke' all the 'short' locals/parameters/results (eg from htons()) as well as all the 'long' for values than aren't dependant on 32/64 bit builds.
-- David
Quoted 6 lines · David Laight
Talking of broken compilers, had you noticed that:
struct foo { int a; char c[32]; };
Quoted 7 lines
int
b(struct foo *f){ return __builtin_object_size(f->c, 1); }returns -1 (size unknown/indefinite).
You can't use__builtin_object_size()to stop code running off the end of anything referenced by address - even when the size is constant.
That is the entire point of using '-fstrict-flex-arrays=3' in the kernel:
df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")
https://godbolt.org/z/bvfrh7W58
Without it, all trailing arrays in structures are treated as flexible arrays, even those with fixed sizes.
Signature · 2 lines
Cheers, Nathan
Quoted 15 lines · On Thu, 4 Jun 2026 18:57:24 -0700 Nathan Chancellor <[email protected]> wrote:
Quoted 6 lines · David Laight
Talking of broken compilers, had you noticed that:
struct foo { int a; char c[32]; };Quoted 7 lines
int
b(struct foo *f){ return __builtin_object_size(f->c, 1); }returns -1 (size unknown/indefinite).
You can't use__builtin_object_size()to stop code running off the end of anything referenced by address - even when the size is constant.
Quoted 9 lines
That is the entire point of using '-fstrict-flex-arrays=3' in the kernel:
df8fc4e934c1("kbuild: Enable -fstrict-flex-arrays=3")
https://godbolt.org/z/bvfrh7W58Without it, all trailing arrays in structures are treated as flexible arrays, even those with fixed sizes.
strict-flex-arrays got added in gcc 13.1 and clang 15.0; it isn't supported by the gcc 12.2 on the debian 12 system I'm building kernels on. __buitin_object_size() itself is in gcc 4.1.2 and clang 3.0.
Neither are flex arrays mentioned in the gcc docs for __builtin_object_size().
Someone might have used (eg) 'char x[4]' as a flex array to include the padding, but no one would have used anything that extended the structure. And the chance of those hitting __builtin_object_size() is even smaller.
-- David
David Laight <[email protected]>:
Quoted 2 lines
I know it has mattered elsewhere, and is easy to get wrong because 'mostly it works'.
I will send a patch, which will change that argument back to "int". Hopefully today.
Also I will add that "wait_for_space".
Signature · 1 line
Askar Safin
Mark Brown
maintainerQuoted 8 lines · Askar Safin
vmsplice behavior on writable pipe became equivalent to pwritev2. vmsplice behavior on readable pipe already was nearly equivalent to preadv2, but I made this explicit. I. e. I made it obvious from code that vmsplice now is equivalent to preadv2/pwritev2.
Also I moved vmsplice to
fs/read_write.c, because now it arguably belongs there.
Quoted 6 lines
Note that
SPLICE_F_NONBLOCKbehavior slightly changed: previously vmsplice ignored whether the pipe was opened withO_NONBLOCK, and mode of operation depended on whetherSPLICE_F_NONBLOCKwas passed only. Now the operation will be non-blocking ifO_NONBLOCKwas passed when opening *or*SPLICE_F_NONBLOCKwas passed to vmsplice. Previous behavior was arguably buggy, and new behavior is arguably better.
FWIW this is triggering a failure in the LTP vmsplice01 test case (which sends with a vmsplice() and then tries to read that with a splice()) in -next:
| tst_tmpdir.c:316: TINFO: Using /tmp/LTP_vmsp3vEmQ as tmpdir (tmpfs filesystem) | L4471tst_test.c:2047: TINFO: LTP version: 20260130 | L4472tst_test.c:2050: TINFO: Tested kernel: 7.1.0-rc6-next-20260604 #1 SMP @1780589917 armv7l | L4473tst_kconfig.c:71: TINFO: Couldn't locate kernel config! | L4474tst_test.c:1875: TINFO: Overall timeout per run is 0h 00m 30s | L4475tst_test.c:1632: TINFO: tmpfs is supported by the test | L4476Test timeouted, sending SIGKILL! | L4477tst_test.c:1947: TINFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1 | L4478tst_test.c:1949: TBROK: Test killed! (timeout?)
As the test itself notes it's not super realistic but thought it was better to mention it since I didn't see any report on the list yet, I've CCed the LTP list.
Full log:
https://lava.sirena.org.uk/scheduler/job/2831199#L4468
bisect log:
# bad: [b99ae45861eccff1e1d8c7b05a13650be805d437] Add linux-next specific files for 20260604
# good: [5e9d583f58c8b56c9f5022639ac70cb7ae6e9fe9] Merge branch 'for-linux-next-fixes' of https://gitlab.freedesktop.org/drm/misc/kernel.git
# good: [a9f7db50ed2fff96727782456f49bf88def68510] tee: fs/splice.c: remove unused parameter "flags" from "link_pipe"
# good: [215701873a7ed1214bba82c8fadcd2583d0246c3] net: mdio: realtek-rtl9300: Add ports to info structure
# good: [b882d807fa443b529ae8bf917d7b640a8d555437] tools/nolibc: stackprotector: Avoid stalling program startup if crng is not init yet
# good: [835fa43a4d36bd66ad0dd052f9fa15f7bd365fa8] tools/nolibc: add ftruncate()
# good: [5d72c6a754ef488f88ad33c83d14556c6f38af3a] Merge branch 'pci/controller/dwc-qcom'
# good: [04b18289834f20bbed25813c4978833ca8bd6e82] Merge branch 'pci/controller/misc'
# good: [94bf692c483ffb325af0b110429ad37f445d40b0] Merge branch 'pci/endpoint'
# good: [1c996a37fd244d19e5dbb715328c1676e28ef607] tools/power turbostat: pmt: Improve sscanf() hygiene
# good: [083c9ab12c402efe9ed55c942ede92eb35f8bf2a] crypto: omap-des - add COMPILE_TEST and fix CONFIG_OF=n build
# good: [49e05bb00f2e8168695f7af4d694c39e1423e8a2] crypto: atmel-sha204a - fail on hwrng registration error in probe path
# good: [86ad8069366642fec18c1bc53c24cad3da720ce5] Documentation: qat_rl: make rate limiting wording clearer
# good: [d58b4a09d7f06750a706b70d068f5a678dad8233] crypto: atmel-sha204a - remove sysfs group before hwrng
# good: [34808ac8ddafc3e2c2a59e84eaab0a410e7a0fdc] regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16
# good: [dc3ec9af62a92a46378960e599521c2ac5f81343] hwrng: core - use MAX to simplify RNG_BUFFER_SIZE
# good: [513f49c33e91e58975ada7967b44512179f0e703] power: sequencing: print power sequencing device parent in debugfs
# good: [bb2d82d41894cb30d836e9796ff67d2f9a71eccf] Merge tag 'v7.1-rc2' into nolibc/for-next
# good: [07a1a6562ce29e2e0c134a57882d6e52e8758492] kcsan: Silence -Wmaybe-uninitialized when calling __kcsan_check_access()
git bisect start 'b99ae45861eccff1e1d8c7b05a13650be805d437' '5e9d583f58c8b56c9f5022639ac70cb7ae6e9fe9' 'a9f7db50ed2fff96727782456f49bf88def68510' '215701873a7ed1214bba82c8fadcd2583d0246c3' 'b882d807fa443b529ae8bf917d7b640a8d555437' '835fa43a4d36bd66ad0dd052f9fa15f7bd365fa8' '5d72c6a754ef488f88ad33c83d14556c6f38af3a' '04b18289834f20bbed25813c4978833ca8bd6e82' '94bf692c483ffb325af0b110429ad37f445d40b0' '1c996a37fd244d19e5dbb715328c1676e28ef607' '083c9ab12c402efe9ed55c942ede92eb35f8bf2a' '49e05bb00f2e8168695f7af4d694c39e1423e8a2' '86ad8069366642fec18c1bc53c24cad3da720ce5' 'd58b4a09d7f06750a706b70d068f5a678dad8233' '34808ac8ddafc3e2c2a59e84eaab0a410e7a0fdc' 'dc3ec9af62a92a46378960e599521c2ac5f81343' '513f49c33e91e58975ada7967b44512179f0e703' 'bb2d82d41894cb30d836e9796ff67d2f9a71eccf' '07a1a6562ce29e2e0c134a57882d6e52e8758492'
# test job: [a9f7db50ed2fff96727782456f49bf88def68510] https://lava.sirena.org.uk/scheduler/job/2827407 # test job: [215701873a7ed1214bba82c8fadcd2583d0246c3] https://lava.sirena.org.uk/scheduler/job/2804576 # test job: [b882d807fa443b529ae8bf917d7b640a8d555437] https://lava.sirena.org.uk/scheduler/job/2801267 # test job: [835fa43a4d36bd66ad0dd052f9fa15f7bd365fa8] https://lava.sirena.org.uk/scheduler/job/2801414 # test job: [5d72c6a754ef488f88ad33c83d14556c6f38af3a] https://lava.sirena.org.uk/scheduler/job/2827129 # test job: [04b18289834f20bbed25813c4978833ca8bd6e82] https://lava.sirena.org.uk/scheduler/job/2827205 # test job: [94bf692c483ffb325af0b110429ad37f445d40b0] https://lava.sirena.org.uk/scheduler/job/2827087 # test job: [1c996a37fd244d19e5dbb715328c1676e28ef607] https://lava.sirena.org.uk/scheduler/job/2801077 # test job: [083c9ab12c402efe9ed55c942ede92eb35f8bf2a] https://lava.sirena.org.uk/scheduler/job/2804905 # test job: [49e05bb00f2e8168695f7af4d694c39e1423e8a2] https://lava.sirena.org.uk/scheduler/job/2804997 # test job: [86ad8069366642fec18c1bc53c24cad3da720ce5] https://lava.sirena.org.uk/scheduler/job/2804815 # test job: [d58b4a09d7f06750a706b70d068f5a678dad8233] https://lava.sirena.org.uk/scheduler/job/2805032 # test job: [34808ac8ddafc3e2c2a59e84eaab0a410e7a0fdc] https://lava.sirena.org.uk/scheduler/job/2783569 # test job: [dc3ec9af62a92a46378960e599521c2ac5f81343] https://lava.sirena.org.uk/scheduler/job/2804763 # test job: [513f49c33e91e58975ada7967b44512179f0e703] https://lava.sirena.org.uk/scheduler/job/2801614 # test job: [bb2d82d41894cb30d836e9796ff67d2f9a71eccf] https://lava.sirena.org.uk/scheduler/job/2744679 # test job: [07a1a6562ce29e2e0c134a57882d6e52e8758492] https://lava.sirena.org.uk/scheduler/job/2745239 # test job: [b99ae45861eccff1e1d8c7b05a13650be805d437] https://lava.sirena.org.uk/scheduler/job/2831199 # bad: [b99ae45861eccff1e1d8c7b05a13650be805d437] Add linux-next specific files for 20260604 git bisect bad b99ae45861eccff1e1d8c7b05a13650be805d437 # test job: [2d4099641dbaed4b98711fc7d8ec94c5aec0a0f0] https://lava.sirena.org.uk/scheduler/job/2827279 # bad: [2d4099641dbaed4b98711fc7d8ec94c5aec0a0f0] Merge patch series "vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2" git bisect bad 2d4099641dbaed4b98711fc7d8ec94c5aec0a0f0 # test job: [e2c0b2368081bef7d1f6758cc9e7edde8521237c] https://lava.sirena.org.uk/scheduler/job/2827345 # bad: [e2c0b2368081bef7d1f6758cc9e7edde8521237c] vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2 git bisect bad e2c0b2368081bef7d1f6758cc9e7edde8521237c # first bad commit: [e2c0b2368081bef7d1f6758cc9e7edde8521237c] vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2 # test job: [7d75aa8edfce3e8ac4f0f8fe5728fd1eab8f7f23] https://lava.sirena.org.uk/scheduler/job/2829187 # skip: [7d75aa8edfce3e8ac4f0f8fe5728fd1eab8f7f23] splice: remove PIPE_BUF_FLAG_GIFT git bisect skip 7d75aa8edfce3e8ac4f0f8fe5728fd1eab8f7f23 # first bad commit: [e2c0b2368081bef7d1f6758cc9e7edde8521237c] vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2
Quoted 10 lines · Mark Brown
FWIW this is triggering a failure in the LTP vmsplice01 test case (which sends with a
vmsplice()and then tries to read that with asplice()) in -next:| tst_tmpdir.c:316: TINFO: Using /tmp/LTP_vmsp3vEmQ as tmpdir (tmpfs filesystem) | L4471tst_test.c:2047: TINFO: LTP version: 20260130 | L4472tst_test.c:2050: TINFO: Tested kernel: 7.1.0-rc6-next-20260604 #1 SMP @1780589917 armv7l | L4473tst_kconfig.c:71: TINFO: Couldn't locate kernel config! | L4474tst_test.c:1875: TINFO: Overall timeout per run is 0h 00m 30s
I htink this is the same thing that Christian already noted (he said "reported by David", but I don't know which David ;), where the vmsplice() writev() emulation was done as a blocking write, even though vmsplice only blocked at the beginning (ie waiting only for _initial_ space to write, not then blocking afterwards).
Linus
Mark Brown
maintainerQuoted 11 lines · Linus Torvalds
Quoted 3 lines · Mark Brown
| L4472tst_test.c:2050: TINFO: Tested kernel: 7.1.0-rc6-next-20260604 #1 SMP @1780589917 armv7l | L4473tst_kconfig.c:71: TINFO: Couldn't locate kernel config! | L4474tst_test.c:1875: TINFO: Overall timeout per run is 0h 00m 30sI htink this is the same thing that Christian already noted (he said "reported by David", but I don't know which David ;), where the
vmsplice()writev()emulation was done as a blocking write, even though vmsplice only blocked at the beginning (ie waiting only for _initial_ space to write, not then blocking afterwards).
Ah, yes it is - exactly the same issue that's mentioned in[1], I missed it in the middle of the quite large thread and didn't directly find David's report. Sorry for the duplication there.
[1] https://lore.kernel.org/r/20260603-raumfahrt-unmerklich-ertrugen-c4ecae70d5f9@brauner
David Hildenbrand (Arm)
maintainerQuoted 13 lines · Mark Brown
Quoted 11 lines · Linus Torvalds
Quoted 3 lines · Mark Brown
| L4472tst_test.c:2050: TINFO: Tested kernel: 7.1.0-rc6-next-20260604 #1 SMP @1780589917 armv7l | L4473tst_kconfig.c:71: TINFO: Couldn't locate kernel config! | L4474tst_test.c:1875: TINFO: Overall timeout per run is 0h 00m 30sI htink this is the same thing that Christian already noted (he said "reported by David", but I don't know which David ;), where the
vmsplice()writev()emulation was done as a blocking write, even though vmsplice only blocked at the beginning (ie waiting only for _initial_ space to write, not then blocking afterwards).
Quoted 3 lines
Ah, yes it is - exactly the same issue that's mentioned in[1], I missed it in the middle of the quite large thread and didn't directly find David's report. Sorry for the duplication there.
Yeah, I quickly discussed this with Christian on a different channel and he ended up sharing the report with the analysis directly.
Signature · 3 lines
Cheers, David
Alexander Gordeev
maintainerQuoted 18 lines · Askar Safin
vmsplice behavior on writable pipe became equivalent to pwritev2. vmsplice behavior on readable pipe already was nearly equivalent to preadv2, but I made this explicit. I. e. I made it obvious from code that vmsplice now is equivalent to preadv2/pwritev2.
Also I moved vmsplice to
fs/read_write.c, because now it arguably belongs there.Note that
SPLICE_F_NONBLOCKbehavior slightly changed: previously vmsplice ignored whether the pipe was opened withO_NONBLOCK, and mode of operation depended on whetherSPLICE_F_NONBLOCKwas passed only. Now the operation will be non-blocking ifO_NONBLOCKwas passed when opening *or*SPLICE_F_NONBLOCKwas passed to vmsplice. Previous behavior was arguably buggy, and new behavior is arguably better.Now
SPLICE_F_GIFTis always ignored by all 3 syscalls: splice, tee and vmsplice.
Quoted 8 lines
Signed-off-by Askar Safin <[email protected]>--- fs/read_write.c | 23 +++++ fs/splice.c | 192 +-------------------------------------- include/linux/skbuff.h | 4 +- include/linux/splice.h | 2 +- include/linux/syscalls.h | 4 +- 5 files changed, 29 insertions(+), 196 deletions(-)
Hi All,
This patch as commit e2c0b2368081b ("vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2") in linux-next on s390 causes the selftest tools/testing/selftests/mm/cow.c to hang:
# [RUN] vmsplice() + unmap in child ... with PTE-mapped THP (128 kB)
Recently there has been changes in THP area, so the problem is not necessary linked to this patch per se.
Please, let me know if you need any additional information.
Thanks!
David Hildenbrand (Arm)
maintainerQuoted 30 lines · Alexander Gordeev
Quoted 18 lines · Askar Safin
vmsplice behavior on writable pipe became equivalent to pwritev2. vmsplice behavior on readable pipe already was nearly equivalent to preadv2, but I made this explicit. I. e. I made it obvious from code that vmsplice now is equivalent to preadv2/pwritev2.
Also I moved vmsplice to
fs/read_write.c, because now it arguably belongs there.Note that
SPLICE_F_NONBLOCKbehavior slightly changed: previously vmsplice ignored whether the pipe was opened withO_NONBLOCK, and mode of operation depended on whetherSPLICE_F_NONBLOCKwas passed only. Now the operation will be non-blocking ifO_NONBLOCKwas passed when opening *or*SPLICE_F_NONBLOCKwas passed to vmsplice. Previous behavior was arguably buggy, and new behavior is arguably better.Now
SPLICE_F_GIFTis always ignored by all 3 syscalls: splice, tee and vmsplice.Quoted 8 lines
Signed-off-by Askar Safin <[email protected]>--- fs/read_write.c | 23 +++++ fs/splice.c | 192 +-------------------------------------- include/linux/skbuff.h | 4 +- include/linux/splice.h | 2 +- include/linux/syscalls.h | 4 +- 5 files changed, 29 insertions(+), 196 deletions(-)Hi All,
Quoted 8 lines
This patch as commit
e2c0b2368081b("vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2") in linux-next on s390 causes the selftesttools/testing/selftests/mm/cow.cto hang:# [RUN]
vmsplice()+ unmap in child ... with PTE-mapped THP (128 kB)Recently there has been changes in THP area, so the problem is not necessary linked to this patch per se.
If we reach 128 kB, then 64 kB likely worked. Which might hint at a similar problem as found by the vmsplice01 ltp test case (blocking instead of returning once the pipe is full).
https://lore.kernel.org/r/20260603-raumfahrt-unmerklich-ertrugen-c4ecae70d5f9@brauner
Signature · 3 lines
Cheers, David
Alexander Gordeev <[email protected]>:
Quoted 6 lines
Hi All,
This patch as commit
e2c0b2368081b("vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2") in linux-next on s390 causes the selftesttools/testing/selftests/mm/cow.cto hang:
Quoted 8 lines
# [RUN]
vmsplice()+ unmap in child ... with PTE-mapped THP (128 kB)Recently there has been changes in THP area, so the problem is not necessary linked to this patch per se.
Please, let me know if you need any additional information.
Thanks!
As well as I understand, this test uses vmsplice to pin pages. I. e. if my patch lands, then this test should be rewriten to use some other mechanism.
Signature · 1 line
Askar Safin
PATCH 3/3 splice: remove PIPE_BUF_FLAG_GIFT
In reply to Askar SafinIt is unused now.
--- fs/fuse/dev.c | 1 - fs/splice.c | 6 ++---- include/linux/pipe_fs_i.h | 1 - 3 files changed, 2 insertions(+), 6 deletions(-)
fs/fuse/dev.c +0 -1
@@ -2352,7 +2352,6 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe, goto out_free; *obuf = *ibuf; - obuf->flags &= ~PIPE_BUF_FLAG_GIFT ; obuf->len = rem; ibuf->offset += obuf->len; ibuf->len -= obuf->len;
fs/splice.c +2 -4
@@ -1622,10 +1622,9 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe, *obuf = *ibuf;/* -* Don't inherit the gift and merge flags, we need to +* Don't inherit the merge flag, we need to * prevent multiple steals of this page. */ - obuf->flags &= ~PIPE_BUF_FLAG_GIFT ; obuf->flags &= ~PIPE_BUF_FLAG_CAN_MERGE ; obuf->len = len;
@@ -1711,10 +1710,9 @@ static ssize_t link_pipe(struct pipe_inode_info *ipipe, *obuf = *ibuf;/* -* Don't inherit the gift and merge flag, we need to prevent +* Don't inherit the merge flag, we need to prevent * multiple steals of this page. */ - obuf->flags &= ~PIPE_BUF_FLAG_GIFT ; obuf->flags &= ~PIPE_BUF_FLAG_CAN_MERGE ;if (obuf->len > len)
include/linux/pipe_fs_i.h +0 -1
@@ -6,7 +6,6 @@#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 */
Signature · 1 line
2.47.3
Quoted 23 lines · Askar Safin
This patchset is for VFS.
Recently we got a lot of vulnerabilities in splice/vmsplice.
Also vmsplice already was source of vulnerabilities in the past:
CVE-2020-29374 (see https://lwn.net/Articles/849638/ ).Also vmsplice is problematic for other reasons. Here is what other developers say:
Linus Torvalds in 2023:
Quoted 4 lines
So I'd personally be perfectly ok with just making
vmsplice()be exactly the same as write, and turn all ofvmsplice()into just "it's aread()if the pipe is open for read, and a write if it's open for writing".https://lore.kernel.org/all/CAHk-=wgG_2cmHgZwKjydi7=iimyHyN8aessnbM9XQ9ufbaUz9g@mail.gmail.com/
Christoph Hellwig in May 2026:
Quoted 5 lines
vmsplice is the worst, as it is one of the few remaining places that can incorrectly dirty file backed pages without telling the file system and cause the other problems fixed by a
FOLL_PINconversion, but it is the only one where we do not have any idea yet how we could convert it toFOLL_PINdue to the unbounded pin time.
Quoted 4 lines
https://lore.kernel.org/all/[email protected]/
See recent discussion here:
https://lore.kernel.org/all/[email protected]/T/#u
So, you took an ongoing discussion with an ongoing RFC patchset, and you decided to reimplement part of the idea on your own, as a concurrent patchset.
Riiiiiight.... I don't think I have to NAK this, do I?
Quoted 8 lines
For all these reasons I propose to make vmsplice a simple wrapper for preadv2/pwritev2.
vmsplice(fd, vec, vlen, vmsplice_flags)will
be equivalent topreadv2(fd, vec, vlen, -1, rw_flags)if you have readable pipe and topwritev2(fd, vec, vlen, -1, rw_flags)if you have writable pipe.
This does not work. https://codesearch.debian.net/search?q=vmsplice%28&literal=1
There are users.
Signature · 1 line
Pedro
David Hildenbrand (Arm)
maintainerQuoted 26 lines · Pedro Falcato
Quoted 25 lines · Askar Safin
This patchset is for VFS.
Recently we got a lot of vulnerabilities in splice/vmsplice.
Also vmsplice already was source of vulnerabilities in the past:
CVE-2020-29374 (see https://lwn.net/Articles/849638/ ).Also vmsplice is problematic for other reasons. Here is what other developers say:
Linus Torvalds in 2023:
Quoted 4 lines
So I'd personally be perfectly ok with just making
vmsplice()be exactly the same as write, and turn all ofvmsplice()into just "it's aread()if the pipe is open for read, and a write if it's open for writing".https://lore.kernel.org/all/CAHk-=wgG_2cmHgZwKjydi7=iimyHyN8aessnbM9XQ9ufbaUz9g@mail.gmail.com/
Christoph Hellwig in May 2026:
Quoted 5 lines
vmsplice is the worst, as it is one of the few remaining places that can incorrectly dirty file backed pages without telling the file system and cause the other problems fixed by a
FOLL_PINconversion, but it is the only one where we do not have any idea yet how we could convert it toFOLL_PINdue to the unbounded pin time.
Quoted 7 lines
Quoted 2 lines
See recent discussion here:
https://lore.kernel.org/all/[email protected]/T/#uSo, you took an ongoing discussion with an ongoing RFC patchset, and you decided to reimplement part of the idea on your own, as a concurrent patchset.
Riiiiiight.... I don't think I have to NAK this, do I?
Jup. I'll just ignore this patch set here.
Signature · 3 lines
Cheers, David
Quoted 2 lines · Pedro Falcato
So, you took an ongoing discussion with an ongoing RFC patchset, and you decided to reimplement part of the idea on your own, as a concurrent patchset.
Yes. But I propose an alternative solution to this problem.
Brauner said in discussion for your patchset:
"So I'm not very likely to pick this up as is".
So, I decided to submit another solution.
Pedro, I'm not trying to insult you.
Other kernel developers will decide which of these two solutions they like more.
Many people in discussion of your patchset said how they dislike splice/vmsplice, and especially vmsplice. Hellwig said "vmsplice is the worst".
Brauner, Hellwig, Horn said that they dislike vmsplice. They said that vmsplice in its current form should not be used, and that it is broken.
Despite all these problems nobody managed to fix
vmsplice in all these years.
So I propose just to effectively remove it.
You may think that I just saw a recent discussion and decided to jump in. No. splice/vmsplice is my topic of interest for many years. You can verify this by searching "f:Askar splice" on lore.kernel.org . I simply decided that given recent vulnerabilities now is the perfect time to solve all these vmsplice problems once and for all.
I explained my position here:
https://lore.kernel.org/all/[email protected]/ . Nobody answered, so I just posted this patchset.
If my patchset is applied, then I will try to deal with splice-pagecache-to-pipe somehow, probably by removing it, too. :) I decided first to deal with vmsplice, because it seems to be easier problem.
Quoted 7 lines
Quoted 4 lines
vmsplice(fd, vec, vlen, vmsplice_flags)will
be equivalent topreadv2(fd, vec, vlen, -1, rw_flags)if you have readable pipe and topwritev2(fd, vec, vlen, -1, rw_flags)if you have writable pipe.This does not work. https://codesearch.debian.net/search?q=vmsplice%28&literal=1
There are users.
Yes, they are. But my solution is compatible. vmsplice is simply performance optimization. vmsplice will work just as before, but slower. And, most importantly, vmsplice design problems will be gone (nobody managed to fix them anyway for all these years).
Signature · 1 line
Askar Safin
Christian Brauner
maintainerQuoted 5 lines · Askar Safin
Quoted 2 lines · Pedro Falcato
So, you took an ongoing discussion with an ongoing RFC patchset, and you decided to reimplement part of the idea on your own, as a concurrent patchset.
Yes. But I propose an alternative solution to this problem.
So I think this is a case where no explicit rules have been broken. But if you know that someone has been posting patches and is working on a problem just racing them to get your own stuff merged is very likely to unnecessarily ruffle feathers. So sync with the person next time.
The discussion wasn't at an impasse and Pedro is expected to follow-up. It's not very nice to just have someone else's work be for naught.
Quoted 3 lines
Brauner said in discussion for your patchset:
"So I'm not very likely to pick this up as is".
So, I decided to submit another solution.
This lacks quite some context... I said "in its current form" and the a long discussion ensued.
Quoted 3 lines
If my patchset is applied, then I will try to deal with splice-pagecache-to-pipe somehow, probably by removing it, too. :) I decided first
So ok, but this is literally what Pedro is working on. This just wastes people's time.
Pedro Falcato <[email protected]>:
Quoted 8 lines · Askar Safin
Quoted 2 lines
See recent discussion here:
https://lore.kernel.org/all/[email protected]/T/#uSo, you took an ongoing discussion with an ongoing RFC patchset, and you decided to reimplement part of the idea on your own, as a concurrent patchset.
Riiiiiight.... I don't think I have to NAK this, do I?
Okay, possibly this was indeed inappropriate.
So this time I'm asking explicitly: is it okay to post new patchset?
I want to post patchset, which will remove pagecache-to-pipe splice.
Signature · 1 line
Askar Safin
Quoted 8 lines · Askar Safin
Pedro Falcato <[email protected]>:
Quoted 7 lines · Askar Safin
Quoted 2 lines
See recent discussion here:
https://lore.kernel.org/all/[email protected]/T/#uSo, you took an ongoing discussion with an ongoing RFC patchset, and you decided to reimplement part of the idea on your own, as a concurrent patchset.
Quoted 7 lines
Quoted 1 line
Riiiiiight.... I don't think I have to NAK this, do I?
Okay, possibly this was indeed inappropriate.
So this time I'm asking explicitly: is it okay to post new patchset?
I want to post patchset, which will remove pagecache-to-pipe splice.
Well, that's most definitely part of my patch. Also, you cannot outright remove splice() functionality, it's pretty important (besides people doing funky pipe business, it can also used for stuff like "take these pages that we just got on a socket, put them on a pipe and then ship them off to an actual file" with minimal copying; doing stuff like sendfile() also uses splice() internally).
So, I guess I'll be sending the v2 soon.
Signature · 1 line
Pedro
Quoted 3 lines · Pedro Falcato
Well, that's most definitely part of my patch. Also, you cannot outright remove
splice()functionality
That isn't what Askar's patch ever did.
You apparently didn't even read it.
Honestly, I think you are the one out of line here.
Askar did something I suggested years ago, and didn't remove any functionality.
It just changes vmsplice to be a copying model (one of the directions already was). It doesn't change regular splice at all.
And yes, it has the potential to be a visible behavior difference - if some insane user uses vmsplice and then modifies the buffer *afterwards*, then that would be semantically different between a zero-copy and a normal copy.
But that would be insane behavior, and was never really reliable anyway even with zero-copy (ie subsequent writes to user space buffers would potentially do COW breaking based purely on timing and memory pressure etc, so anybody who relied on it being visible wasn't goign to get it realiably anyway)
Perhaps more importantly, it has the potential to change performance - zero-copy *can* be a performance win, although typically it really doesn't tend to be (looking up the page mapping is often slower than copying).
I would expect it to be very clear in trivial benchmarks that aren't actually real loads. And probably not visible anywhere else.
But your responses have been making it clear that you didn't seem to actually look at the patch or the history of it.
Trying to make it look like Askar is the problem is only making you look worse.
Anyway, the vmsplice() thing is queued up in Christian's tree, and I guess we'll see if anybody even notices anything.
Linus
Quoted 8 lines · Linus Torvalds
Quoted 3 lines · Pedro Falcato
Well, that's most definitely part of my patch. Also, you cannot outright remove
splice()functionalityThat isn't what Askar's patch ever did.
You apparently didn't even read it.
Well, I was replying to Askar's new idea to remove pagecache-to-pipe splice, which is what he suggested. And directly intersects with my sysctl-to-disable-splice patch.
Quoted 18 lines
Honestly, I think you are the one out of line here.
Askar did something I suggested years ago, and didn't remove any functionality.
It just changes vmsplice to be a copying model (one of the directions already was). It doesn't change regular splice at all.
And yes, it has the potential to be a visible behavior difference - if some insane user uses vmsplice and then modifies the buffer *afterwards*, then that would be semantically different between a zero-copy and a normal copy.
But that would be insane behavior, and was never really reliable anyway even with zero-copy (ie subsequent writes to user space buffers would potentially do COW breaking based purely on timing and memory pressure etc, so anybody who relied on it being visible wasn't goign to get it realiably anyway)
Quoted 7 lines
Perhaps more importantly, it has the potential to change performance - zero-copy *can* be a performance win, although typically it really doesn't tend to be (looking up the page mapping is often slower than copying).
I would expect it to be very clear in trivial benchmarks that aren't actually real loads. And probably not visible anywhere else.
Yes, vmsplice() sucks, and we know it. Hopefully no one else will see the difference. I don't think we can say the same for splice(), though.
Quoted 1 line
Trying to make it look like Askar is the problem is only making you look worse.
To be clear, I don't think Askar is the (or a) problem. I'm glad he's contributing, and getting rid of bad kernel interfaces is always nice. I was just a little frustrated with a parallel splice-related-unscrew patch.
(Askar, if I was too hostile, I do sincerely apologize.)
Signature · 1 line
Pedro
Pedro Falcato <[email protected]>:
Quoted 1 line
(Askar, if I was too hostile, I do sincerely apologize.)
You did nothing wrong.
Signature · 1 line
Askar Safin
Linus Torvalds <[email protected]>:
Quoted 10 lines
That isn't what Askar's patch ever did.
You apparently didn't even read it.
Honestly, I think you are the one out of line here.
Askar did something I suggested years ago, and didn't remove any functionality.
It just changes vmsplice to be a copying model (one of the directions already was). It doesn't change regular splice at all.
Pedro is talking here not about this vmsplice patch, but about my future hypothetical patch, which will remove splice-pagecache-to-pipe.
Let me clarify, what I want to send: I will make splice-pagecache-to-pipe be a copy. I. e. this splice direction will continue to work, but will be possibly slower. I. e. I will do something like this (see end of this email) (absolutely not tested), and the same thing for other filesystems, and also I will remove resulting dead code and remove pipe_buf_operations::confirm (it will likely become unneeded).
If Pedro sends this instead, this will be okay.
fs/ext2/file.c +1 -1
@@ -326,7 +326,7 @@ const struct file_operations ext2_file_operations = { .release = ext2_release_file, .fsync = ext2_fsync, .get_unmapped_area = thp_get_unmapped_area, - .splice_read = filemap_splice_read, + .splice_read = copy_splice_read, .splice_write = iter_file_splice_write, .setlease = generic_setlease, };
Signature · 1 line
Askar Safin
Quoted 3 lines · Askar Safin
Pedro is talking here not about this vmsplice patch, but about my future hypothetical patch, which will remove splice-pagecache-to-pipe.
That absolutely would be my suggested next step.
Something like the attached - get rid of filemap_splice_read() entirely, and just replace it with copy_splice_read().
That also make the whole O_DIRECT and DAX special case just simply go away.
This is - in case there was any question about it - ENTIRELY untested.
It may not compile.
And if it does compile, it may do unspeakable things to your pets.
So think of this as nothing more than a "something like this". It does leave "splice_read" around, and it intentionally just does that
#define filemap_splice_read copy_splice_read
to not have to modify all the existing users one by one.
It would be interesting to hear if there are any actual real loads that would ever notice?
Linus
fs/splice.c | 6 -- include/linux/fs.h | 4 +- mm/filemap.c | 145 ------------------------------------------------ mm/internal.h | 6 -- mm/shmem.c | 159 +---------------------------------------------------- 5 files changed, 2 insertions(+), 318 deletions(-)
fs/splice.c +0 -6
@@ -971,12 +971,6 @@ static ssize_t do_splice_read(struct file *in, loff_t *ppos,if (unlikely (!in->f_op->splice_read))return warn_unsupported (in,"read" ); -/* -* O_DIRECT and DAX don't deal with the pagecache, so we allocate a -* buffer, copy into it and splice that into the pipe. -*/ -if ((in->f_flags &O_DIRECT ) ||IS_DAX (in->f_mapping->host)) -return copy_splice_read (in, ppos, pipe, len, flags);return in->f_op->splice_read (in, ppos, pipe, len, flags); }
include/linux/fs.h +1 -3
@@ -3072,9 +3072,7 @@ ssize_t vfs_iocb_iter_write(struct file *file, struct kiocb *iocb, struct iov_iter *iter);/* fs/splice.c */ -ssize_t filemap_splice_read (struct file *in,loff_t *ppos, -struct pipe_inode_info *pipe, -size_t len,unsigned int flags); +#define filemap_splice_read copy_splice_readssize_t copy_splice_read (struct file *in,loff_t *ppos,struct pipe_inode_info *pipe,size_t len,unsigned int flags);
mm/filemap.c +0 -145
151 lines not on this page · raw message
mm/internal.h +0 -6
@@ -1521,12 +1521,6 @@ struct migration_target_control {enum migrate_reason reason; }; -/* -* mm/filemap.c -*/ -size_t splice_folio_into_pipe (struct pipe_inode_info *pipe, -struct folio *folio,loff_t fpos,size_t size); -/* * mm/vmalloc.c */
mm/shmem.c +1 -158
171 lines not on this page · raw message
Linus Torvalds <[email protected]>:
Quoted 4 lines
That absolutely would be my suggested next step.
Something like the attached - get rid of
filemap_splice_read()entirely, and just replace it withcopy_splice_read().
Okay, I will post something like this soon.
But I'm slow person, and also I will test things in Qemu, so this will take some days.
Signature · 1 line
Askar Safin
Quoted 10 lines · Linus Torvalds
Quoted 3 lines · Askar Safin
Pedro is talking here not about this vmsplice patch, but about my future hypothetical patch, which will remove splice-pagecache-to-pipe.
That absolutely would be my suggested next step.
Something like the attached - get rid of
filemap_splice_read()entirely, and just replace it withcopy_splice_read().
Am I understanding correctly that this will completely break zerocopy sendfile? sendfile is, internally, splice-to-a-secret-per-task-pipe and then splice to the socket. How much to people care? These days, a lot of high-bandwidth network senders are sending encrypted data, which is not zerocopy frompagecache. But there are surely some users that care, for example the person who went to the effort to implement IORING_OP_SPLICE:
commit 7d67af2c013402537385dae343a2d0f6a4cb3bfd
Author: Pavel Begunkov <[email protected]> Date: Mon Feb 24 11:32:45 2020 +0300
io_uring: add splice(2) support
Now maybe someone cares about a different path? Splice from socket to pipe to file? Splice from socket to pipe to other socket? Does anyone do any of this? One can, of course, recv() directly to an mmapped file, but then you pay for page faults, so that probably a bad idea in most cases. At least all of these cases don't have spliced buffers that refer to a potentially read-only file.
But I'm a little concerned that zerocopy sends from files to network are actually important.
--Andy
Quoted 3 lines · Andy Lutomirski
Am I understanding correctly that this will completely break zerocopy sendfile?
Very much, yes.
And it's worth making it very very clear that ABSOLUTELY NONE of the recent big security bugs were in splice.
They were all in the networking and crypto code that just didn't deal with shared data correctly.
So in that sense, it's a bit sad to discuss castrating splice.
But it's probably still the right thing to at least try.
I've seen very impressive benchmark numbers over the years, but they've often smelled more like benchmarketing than actual real work.
There's also a real possibility that a lot of the sendfile / splice advantage has little to do with zero-copy, and more to do with the cost of mapping and maintaining buffers in user space.
If you are sending file data using plain reads and writes, it's not just the "copy from user space to socket data structures".
There's also the cost of populating user space in the first place:
page faults for mmap made *that* historical copy avoidance basically a fairy tale.
And not using mmap means that you have the cost of double caching in the kernel _and_ user space etc.
So sendfile() as a concept (whether you use combinations of splice() system calls or the sendfile system call itsefl) isn't necessarily only about the zero-copy, it's really also about avoiding the user space memory management.
But yes, there's a very real question of performance.
I just suspect we'll never get real answers without going the "let's just see what happens" route...
Linus
Christian Brauner
maintainerQuoted 7 lines · Linus Torvalds
Quoted 3 lines · Andy Lutomirski
Am I understanding correctly that this will completely break zerocopy sendfile?
Very much, yes.
Quoted 7 lines
And it's worth making it very very clear that ABSOLUTELY NONE of the recent big security bugs were in splice.
They were all in the networking and crypto code that just didn't deal with shared data correctly.
So in that sense, it's a bit sad to discuss castrating splice.
Well, we're completely ignoring the fact that splice()'s locking and interactions with pipe_lock() are complete insanity. So unless someone sits down and really thinks about how to rework the locking I think degrading splice() is just fine.
Quoted 1 line
But it's probably still the right thing to at least try.
Yes.
Quoted 2 lines
I just suspect we'll never get real answers without going the "let's just see what happens" route...
Yes.
Christian Brauner
maintainerQuoted 21 lines · Christian Brauner
Quoted 7 lines · Linus Torvalds
Quoted 3 lines · Andy Lutomirski
Am I understanding correctly that this will completely break zerocopy sendfile?
Very much, yes.
Quoted 7 lines
And it's worth making it very very clear that ABSOLUTELY NONE of the recent big security bugs were in splice.
They were all in the networking and crypto code that just didn't deal with shared data correctly.
So in that sense, it's a bit sad to discuss castrating splice.
Well, we're completely ignoring the fact that splice()'s locking and interactions with
pipe_lock()are complete insanity. So unless someone sits down and really thinks about how to rework the locking I think degradingsplice()is just fine.
Quoted 8 lines
Quoted 1 line
But it's probably still the right thing to at least try.
Yes.
Quoted 2 lines
I just suspect we'll never get real answers without going the "let's just see what happens" route...
Yes.
Reading this thread again I'm really amazed how willingly people argue to remain locked into a really broken API even if they're giving a risk but worthwhile chance to kill it for good. Anway, odd-userspace behavior time:
David reported vmsplice01 failing in the LTP testsuite after the change:
11297 20:41:02.548383 <LAVA_SIGNAL_STARTTC vmsplice01> 11298 20:41:02.548518 tst_tmpdir.c:316: TINFO: Using /tmp/LTP_vmsZ13ZQj as tmpdir (tmpfs filesystem) 11299 20:41:02.548656 tst_test.c:2047: TINFO: LTP version: 20260130 11300 20:41:02.548793 tst_test.c:2050: TINFO: Tested kernel: 7.1.0-rc6-next-20260602 #1 SMP PREEMPT Tue Jun 2 18:13:29 UTC 2026 aarch64 11301 20:41:02.548932 tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' 11302 20:41:02.549069 tst_test.c:1875: TINFO: Overall timeout per run is 0h 01m 30s 11303 20:41:02.549205 tst_test.c:1632: TINFO: tmpfs is supported by the test 11304 20:41:02.549340 Test timeouted, sending SIGKILL! 11305 20:41:02.549477 tst_test.c:1947: TINFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1 11306 20:41:02.549614 tst_test.c:1949: TBROK: Test killed! (timeout?) 11307 20:41:02.549751 11308 20:41:02.549887 Summary: 11309 20:41:02.550021 passed 0 11310 20:41:02.550155 failed 0 11311 20:41:02.550290 broken 1 11312 20:41:02.550450 skipped 0 11313 20:41:02.550582 warnings 0
11314 20:41:02.550710
11315 20:41:02.550838 <LAVA_SIGNAL_ENDTC vmsplice01>
So I looked at the test:
while (v.iov_len) {
/*
* in a real app you'd be more clever with poll of course,
* here we are basically just blocking on output room and
* not using the free time for anything interesting.
*/
if (poll(&pfd, 1, -1) < 0)
tst_brk(TBROK | TERRNO, "poll() failed");
written = vmsplice(pipes[1], &v, 1, 0);
if (written < 0) {
tst_brk(TBROK | TERRNO, "vmsplice() failed");
} else {
if (written == 0) {
break;
} else {
v.iov_base += written;
v.iov_len -= written;
}
}
SAFE_SPLICE(pipes[0], NULL, fd_out, &offset, written, 0);
//printf("offset = %lld\n", (long long)offset);
}Prior to the change add_to_pipe() returns -EAGAIN the moment the pipe is full. So iter_to_pipe stops and returns a partial count capped at pipe capacity. For a 128K buffer over a 64K pipe the first call returns 64K, the test drains it, call 2 returns the remaining 64K. Done.
After this change do_writev(... flags & SPLICE_F_NONBLOCK ? RWF_NOWAIT :
0) then calls pipe_write which does not stop when the pipe fills. It blocks until the entire iovec is consumed.
I kinda think we need to preserve similar semantics.
Quoted 11 lines · Christian Brauner
Prior to the change
add_to_pipe()returns-EAGAINthe moment the pipe is full. Soiter_to_pipestops and returns a partial count capped at pipe capacity. For a 128K buffer over a 64K pipe the first call returns 64K, the test drains it, call 2 returns the remaining 64K. Done.After this change do_writev(... flags &
SPLICE_F_NONBLOCK?RWF_NOWAIT:
0) then callspipe_writewhich does not stop when the pipe fills. It blocks until the entire iovec is consumed.I kinda think we need to preserve similar semantics.
Ack. We definitely do need to keep the old semantics.
Looking at the patch again, I think it's that
(flags & SPLICE_F_NONBLOCK) ? RWF_NOWAIT : 0
thing that is broken. I think splice_to_pipe is *always* nowait - but has the special conditional _initial_ wait.
So I think the RWF_NOWAIT should be unconditional to the do_writev(), and instead the code should do something like
ret = wait_for_space(pipe, flags);
if (!ret) do_writev(...RWF_NOWAIT);but admittedly I did not think very much about the details, so I might miss something.
Which also then probably measn that we should just keep the legacy wrapper in fs/splice.c and we'd just need to make do_writev() and do_readv() non-static.
Because I'd rather keep wait_for_space() internal to splice (or alternatively we'd move it to pipe.c, rename it to "pipe_wait_for_space()", and change the 'flags' argument to be a boolean to not make it use that splice-specific flags etc).
Linus
Quoted 33 lines · Linus Torvalds
Quoted 3 lines · Andy Lutomirski
Am I understanding correctly that this will completely break zerocopy sendfile?
Very much, yes.
And it's worth making it very very clear that ABSOLUTELY NONE of the recent big security bugs were in splice.
They were all in the networking and crypto code that just didn't deal with shared data correctly.
So in that sense, it's a bit sad to discuss castrating splice.
But it's probably still the right thing to at least try.
I've seen very impressive benchmark numbers over the years, but they've often smelled more like benchmarketing than actual real work.
There's also a real possibility that a lot of the sendfile / splice advantage has little to do with zero-copy, and more to do with the cost of mapping and maintaining buffers in user space.
If you are sending file data using plain reads and writes, it's not just the "copy from user space to socket data structures".
There's also the cost of populating user space in the first place:
page faults for mmap made *that* historical copy avoidance basically a fairy tale.
Quoted 7 lines
And not using mmap means that you have the cost of double caching in the kernel _and_ user space etc.
So
sendfile()as a concept (whether you use combinations ofsplice()system calls or the sendfile system call itsefl) isn't necessarily only about the zero-copy, it's really also about avoiding the user space memory management.
So maybe we should make sure that, if we go down the route of disabling all the splice magic, that we leave an API, maybe the existing sendfile or maybe something else, that does an optimized copy from one fd to another and that is at least capable of sending from a file to the network with at most one CPU-side copy.
Even if we’re just doing that, I continue to find it strange that we require that a pipe be involved. What’s so special about pipes that we allow splicing from file to pipe and then pipe to socket (this requiring that the pipe retain a reference to the file’s page cache structures to avoid *two* copies), but we can’t splice straight from file to socket. Heck, even sendfile is implemented under the hood as a pair of splices!
Quoted 6 lines · Andy Lutomirski
So maybe we should make sure that, if we go down the route of disabling all the splice magic, that we leave an API, maybe the existing sendfile or maybe something else, that does an optimized copy from one fd to another and that is at least capable of sending from a file to the network with at most one CPU-side copy.
Why?
That is *LITERALLY* the attack surface - and the complexity - that we should be removing.
sendfile() was a mistake. It is literally the "file->socket" thing that has been buggy.
I absolutely refuse to get rid of splice code but keep the buggy sh*t cases that caused all the problems in the first place.
Because *THAT* would just be completely insane and pointless.
Quoted 2 lines
Even if we’re just doing that, I continue to find it strange that we require that a pipe be involved. What’s so special about pipes
Again: it was never splice or the pipe that was the problem. Stop barking up the wrong tree.
It was "file data to socket" that was the truly horrendous issue.
That said, to explain the pipe: The reason for the pipe is to act as the kernel-side buffer.
Now, these days we have much more capable iov_iter interfaces than we used to, and in that sense the "pipe as a buffer" is certainly not the obvious choice now.
But even then you need to have a *handle* to the buffers for the general case, and that's what the pipe fd ends up then still effectively being.
It was also done to avoid the M:N translation problem, because people wanted to do zero-copy between other things than just "file -> socket".
But again: we're ABNSOLUTELY NOT keeping that "file -> socket" thing and getting rid of splice. That's literally keeping the bath-water and throwing out the baby.
Splice is the *good* part (well, relatively - splice is bad too).
ile->socket needs to DIE IN A FIRE considering the security problems it has had.
I hope Jakub is right that the problems have been all fixed, and this is all theoretical, but having seen just *how* many there were, I'm a bit sceptical.
Because if people think splice is complicated, you haven't looked at the skb rules. They are completely arbitrary and complex and spread all over the tree.
Linus
Quoted 3 lines · Linus Torvalds
Because if people think splice is complicated, you haven't looked at the skb rules. They are completely arbitrary and complex and spread all over the tree.
Yeah - I fell foul of the net loopback driver just reflecting the outgoing packet back, complete with all the original spliced bufferage. I was wondering if the loopback driver needs to look at the skbuff, see if it has zerocopy elements of some sort and, if so, copy it (or drop it if ENOMEM).
David
Quoted 4 lines · Linus Torvalds
But even then you need to have a *handle* to the buffers for the general case, and that's what the pipe fd ends up then still effectively being.
Again: for sendfile, you don't need the handle, because you can just "read the file data again".
But the the handle is needed for any buffering that can't do that - iow pretty much *any* other case than a file-backed source.
So the original use-cases included things like copying media data from a TV capture card to a GPU for outputting in a window.
There it's actually the intermediate buffer that is the important thing, and it needs to have a lifetime that is independent of the system call itself, because the system call may be interrupted by signals etc, and you can't just "read the data again" when you restart.
So the whole idea with splice() is that you have an input, an output, and a stateful buffer between the two that has a lifetime.
Having just a iov_iter isn't enough - even with the current much more capable iov_iter we have now (compared to when splice came to be: two decades ago when the modern iov_iter didn't even exist). You have to have that notion of a buffer with a lifetime.
(iov_iter came a couple of years later, but it then took many many years for it to become the powerful thing it is today where you can put almost arbitrary data into it - it started as purely a user space iovec iterator, all the bvec/kvec etc stuff that you need for IO buffering came a decade later)
So there's historical reasons for the use of pipes, but there really is a very fundamental reason for it too: wanting to *generic* data transfer between two points, not sendfile.
It's worth noticing that in the generic case, zero-copy isn't really even an issue.
When you think operations like "splice TV capture input to a pipe", you typically need to allocate the pages that you then DMA into *anyway*, and you'd just put those pages into the pipe. And the facty that you can then just take the data directly from those pages when you splice from the pipe to whatever GPU engine that does the decoding is kind of secondary.
So again: the big deal with splice() and the pipe isn't really about zero-copy. It's the in-kernel buffers where the drivers control the allocation and you don't have some "user space allocates memory, then kernel looks that allocation up and uses it" model.
Having less copies is kind of incidental. It *might* happen just because it's natural when some streaming device just gives it data away and doesn't care after the fact.
The problem with splicing from a file has been exactly the fact that it's *not* streaming data, and the filesystem zero-copy case gave direct access to the long-term cache.
Which is undoubtedly good for performance. But it fundamentally *requires* that the sink is trustworthy. Which has been problematic.
That's why sendfile() is bad. Not because splice itself is a bad concept, but because you have to have that absolute trust across components.
Linus
Quoted 9 lines · Linus Torvalds
Quoted 6 lines · Andy Lutomirski
So maybe we should make sure that, if we go down the route of disabling all the splice magic, that we leave an API, maybe the existing sendfile or maybe something else, that does an optimized copy from one fd to another and that is at least capable of sending from a file to the network with at most one CPU-side copy.
Quoted 4 lines
Why?
That is *LITERALLY* the attack surface - and the complexity - that we should be removing.
I think I buried the lede too much and you're arguing against what I was trying not to say.
Maybe we should keep an API that does an optimized copy, from one fd to another, that can send from a file to the network with at most ONE cpu-side copy. Not aiming for zero like sendfile / splice. Aiming for one.
If sendfile and splice get completely deoptimized (which I think makes a considerable amount of sense), then I think that, as you said, there's a risk that the most efficient way to send the contents of a file to the network is to read it into user memory and then send it, which is *two* copies to get it from pagecache to the outgoing socket buffer. But I think that just one copy can be done with essentially no funny business.
copy_splice_read is conceptually not terrible at all -- it allocates memory and copies from page cache. But splice_to_socket involves MSG_SPLACE_PAGES, which I think is a part of the mess that you dislike. And the path where one does copy_splice_read and then splice_to_socket has to be a bit complex because of tee and (I think) because splice_to_socket cannot assume that the incoming data is just ordinary unshared buffers.
What I'm suggesting is that, at least for network families/protocols that care to support such a thing, there could be a slightly tedious but otherwise utterly boring path to *copy* from pagecache to socket buffers. So, once the copy is done, the skbs would be ordinary skbs, exactly as if the user had called plain send(), and nothing downstream (the network drivers, crazy crypto code, etc) would ever see the difference.
I don't think I'm suggesting keeping *splice* as the user-visible API, but maybe plain sendfile could do this, and maybe someone would add io_uring support, but all the complexity would be confined to the code that does the actual copy and not spread to anywhere else in the network stack.
--Andy
Quoted 44 lines
sendfile()was a mistake. It is literally the "file->socket" thing that has been buggy.I absolutely refuse to get rid of splice code but keep the buggy sh*t cases that caused all the problems in the first place.
Because *THAT* would just be completely insane and pointless.
Quoted 2 lines
Even if we’re just doing that, I continue to find it strange that we require that a pipe be involved. What’s so special about pipes
Again: it was never splice or the pipe that was the problem. Stop barking up the wrong tree.
It was "file data to socket" that was the truly horrendous issue.
That said, to explain the pipe: The reason for the pipe is to act as the kernel-side buffer.
Now, these days we have much more capable
iov_iterinterfaces than we used to, and in that sense the "pipe as a buffer" is certainly not the obvious choice now.But even then you need to have a *handle* to the buffers for the general case, and that's what the pipe fd ends up then still effectively being.
It was also done to avoid the M:N translation problem, because people wanted to do zero-copy between other things than just "file -> socket".
But again: we're ABNSOLUTELY NOT keeping that "file -> socket" thing and getting rid of splice. That's literally keeping the bath-water and throwing out the baby.
Splice is the *good* part (well, relatively - splice is bad too).
ile->socketneeds to DIE IN A FIRE considering the security problems it has had.I hope Jakub is right that the problems have been all fixed, and this is all theoretical, but having seen just *how* many there were, I'm a bit sceptical.
Quoted 5 lines
Because if people think splice is complicated, you haven't looked at the skb rules. They are completely arbitrary and complex and spread all over the tree.
Linus
--
Andy Lutomirski
AMA Capital Management, LLC
Quoted 8 lines · Andy Lutomirski
I think I buried the lede too much and you're arguing against what I was trying not to say.
Maybe we should keep an API that does an optimized copy, from one fd to another, that can send from a file to the network with at most ONE cpu-side copy. Not aiming for zero like sendfile / splice. Aiming for one.
Oh, absolutely - that's what my completely untested test patch basically did.
The user space interface was still there.
And the networking side still continued to use the ->splice_write() thing for writing to the socket.
It was just the filesystem side that basically now instead of exposing the page cache directly (with filemap_splice_read) now only exposed a *copy* of the page cache (with copy_splice_read).
Linus
Quoted 4 lines · Linus Torvalds
It was just the filesystem side that basically now instead of exposing the page cache directly (with
filemap_splice_read) now only exposed a *copy* of the page cache (withcopy_splice_read).
... and let me note that UNTESTED part again.
The patch looked "ObviouslyCorrect(tm)" to me, and I did actually compile-test it too.
So it probably wasn't _complete_ crap.
But I never even booted it, and if I had, I wouldn't have had any loads that uses splice (or sendfile) anyway.
So caveat emptor.
Linus
Quoted 11 lines · Linus Torvalds
Quoted 8 lines · Andy Lutomirski
I think I buried the lede too much and you're arguing against what I was trying not to say.
Maybe we should keep an API that does an optimized copy, from one fd to another, that can send from a file to the network with at most ONE cpu-side copy. Not aiming for zero like sendfile / splice. Aiming for one.
Quoted 6 lines
Oh, absolutely - that's what my completely untested test patch basically did.
The user space interface was still there.
And the networking side still continued to use the ->splice_write() thing for writing to the socket.
So I'm suspicious that you've possibly make bugs much (MUCH) harder to exploit, but the underlying awful code and opportunity for bugs is still there. MSG_SPLICE_PAGES is still around, and there is still (AFAICS) no actual coherent description of what it means. There is code that checks for it and apparently needs to do something special. Foir example, some random kernel version I have checked out has this delight in af_alg.c:
/* use the existing memory in an allocated page */
if (ctx->merge && !(msg->msg_flags & MSG_SPLICE_PAGES)) {Grepping for MSG_SPLICE_PAGES come up with all kinds of terrors. Check out the lovely comment in drivers/block/drbd/drbd_main.c, for example...
And even with your patch, I think checking for MSG_SPLICE_PAGES still
matters: if I write to a pipe (using copy_splice_read or even just plain write) and then I tee() that data, then I splice one of those teed copies into a socket, then we hit ->sendmsg with MSG_SPLICE_PAGES set, and we're hoping that the code does the right thing. And maybe all the bugs are fixed by now or maybe they're not. Most of what your patch accomplishes is breaking the connection between the buffers and pagecache, so you can't poison /sbin/su.
It also seems kind of unfortunate that we can have skbs that contain data that isn't actually owned by the socket in question, and, with your patch applied, I'm wondering if the only case where this can really happen is tee() and a handful of random drivers that send to sockets. (The ones in drivers/nvme/host/tcp.c and iSCSI seem like the ones that people are likely to care about the most.)
I *think* that what I'm sort of suggesting is to drop this ability from the kernel as well, or at least to consider it. skbs would always own their contents. And something would get wired up so that at least the cases of sendfile, nvme and iscsi to TCP or UDP sockets would still works with only one copy, from the source page cache into the socket buffer.
I suppose the counterargument is that, even if more bugs exist, it's a bit hard to imagine a real attack involving tee, and one needs privileges to set up nvme or iscsi aimed at an unusual socket type.
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Quoted 5 lines · Andy Lutomirski
So I'm suspicious that you've possibly make bugs much (MUCH) harder to exploit, but the underlying awful code and opportunity for bugs is still there.
MSG_SPLICE_PAGESis still around, and there is still (AFAICS) no actual coherent description of what it means.
I don't disagree. I've only looked at the filesystem side.
The networking side does some odd stuff too (and I did look at some of that, and had to be edumacated by Jakub on some of the subtler rules for what skb data sharing is ok and when it's not - really not my area).
But at least MSG_SPLICE_PAGES should be kernel-internal only interface, and once you don't share page cache pages with networking code I think that kneecaps a lot of the attacks.
So that's really the aim here for me - at least _attempting_ to go "maybe we can just limit splice enough that it doesn't even *matter* when networking does something odd and questionable".
And it's entirely possible that the current zero-copy "networking gets direct access to the page cache folios" is a huge and insurmountable performance requirement for some loads. So the vmsplice patch - and _particularly_ my suggested "let's try always copying" patch - may simply be doomed.
But I'd rather try to simplify the splice code by removing complexity
- and possibly then failing and having to revert it and rethink things
- than not even trying.
Because I think splice() is a *cool* feature. It was always *clever*. I just don't think it's worth the pain it has cause.
And it's been around for a long long time, and after more than two decades it's still most definitely not _widely_ used.
So that makes it a failure in my book. Sometimes "clever" just isn't the right thing.
Linus
Hi Linus,
Quoted 14 lines · Andy Lutomirski
Quoted 5 lines
So I'm suspicious that you've possibly make bugs much (MUCH) harder to exploit, but the underlying awful code and opportunity for bugs is still there.
MSG_SPLICE_PAGESis still around, and there is still (AFAICS) no actual coherent description of what it means.I don't disagree. I've only looked at the filesystem side.
The networking side does some odd stuff too (and I did look at some of that, and had to be edumacated by Jakub on some of the subtler rules for what skb data sharing is ok and when it's not - really not my area).
Quoted 7 lines
But at least
MSG_SPLICE_PAGESshould be kernel-internal only interface, and once you don't share page cache pages with networking code I think that kneecaps a lot of the attacks.So that's really the aim here for me - at least _attempting_ to go "maybe we can just limit splice enough that it doesn't even *matter* when networking does something odd and questionable".
While prototyping a smbdirect_splice_to_bvecs() in order to
do use rdma_rw_ctx_init_bvec() I found things like pipe_buf_try_steal() and dived a bit deeper into struct address_space and found things like:mapping_mapped, mapping_tagged, mapping_deny_writable, mapping_allow_writable and similar things.
With that I'm wondering if we could allow splicing of
pages only if nobody mmap'ed the file => mapping_mapped() returned 0 and the page is not tagged with any of PAGECACHE_TAG_{DIRTY,WRITEBACK,TOWRITE} and once a page is spliced we tag the page in the i_pages xarray with a PAGECACHE_TAG_SPLICED. In all other cases the page would be copied.
Then any call to do_mmap() or vfs_writev at the highlevel
and at the lower levels most likely filemap_get_entry()/filemap_map_pages() will remove the pages marked with PAGECACHE_TAG_SPLICED
and allocate new pages used for the pagecache of the related index. It would be a bit similar to invalidate_inode_pages2_range() for direct io writes. Maybe optimizing by clearing PAGECACHE_TAG_SPLICED if the refcount of the page is 1.
This would also mean the content of spliced pages won't be changed by future writes to the file, which removes the problem with unstable pages and checksums.
It means the most common workload, e.g. a file only opened for file serving (or simple opens in general) would still be able to be optimized.
Does that sound useful and doable?
metze
Quoted 4 lines · Stefan Metzmacher
It means the most common workload, e.g. a file only opened for file serving (or simple opens in general) would still be able to be optimized.
Nope. If your web server opens files with write access, I'd be extremely surprised.
And if you don't have write access, and you're sending out data from files you opened just for reading - the onle sane case - you hit all the existing problems with "I can certainly look up pages, but I damn well shouldn't pass those pages to the networking code without copying them".
Linus
Quoted 9 lines · Linus Torvalds
Nope. If your web server opens files with write access, I'd be extremely surprised.
And if you don't have write access, and you're sending out data from files you opened just for reading - the onle sane case - you hit all the existing problems with "I can certainly look up pages, but I damn well shouldn't pass those pages to the networking code without copying them".
How about using write access as the gate to zero copy?
IOW allow zero-copy if you already hold write access, otherwise perform a copy.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 2 lines · Herbert Xu
How about using write access as the gate to zero copy?
Well, it's too late now - no sane user would open files for writing just to read from them.
And if the file isn't opened for writing originally, it won't show up in the fd. So we'd have to do some after-the-fact "is this writable using the credentials we had at open time" thing.
Which we do for some /proc stuff etc, but it's disgusting, and it isn't how any of this should work.
Plus honestly, in any *good* setup, the normal case really shouldn't be that the source is writable anyway. In benchmarks, sure. But in real life? Hell no.
If you're doing web serving of static content, your web server simply should not have write access to what it is serving. If it does, your web server setup is simply hot garbage and probably riddled with security issues anyway, because you clearly spent absolutely zero time on any kind of "minimal privileges" model.
(I'm not saying that splice would be primarily for web serving or that serving static pages like that is an interesting load - I'm using it purely as an example of why saying that writable files should get better treatment is crazy: it's not how *any* of this should work at any level at all).
So no. We should not treat writable files as some kind of preferred model for performance. We should discourage that kind of behavior, not encourage it.
Linus
Quoted 6 lines · Linus Torvalds
Because I think
splice()is a *cool* feature. It was always *clever*. I just don't think it's worth the pain it has cause.And it's been around for a long long time, and after more than two decades it's still most definitely not _widely_ used.
A couple of years ago I used tee(2) in dash(1) so that we could avoid reading the input line byte-by-byte which is what every other shell does in order to pass the rest of stdin to the executed command.
It's definitely niche but made a huge performance difference to this rather common scenario:
echo 'command
...
rest of stdin' | sh
I didn't even know tee(2) prior to this, even though it was added way back.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 5 lines · On Wed, 10 Jun 2026 13:09:19 +0800 Herbert Xu <[email protected]>…
Quoted 4 lines · Linus Torvalds
Because I think
splice()is a *cool* feature. It was always *clever*. I just don't think it's worth the pain it has cause.
Quoted 7 lines
Quoted 2 lines
And it's been around for a long long time, and after more than two decades it's still most definitely not _widely_ used.
A couple of years ago I used tee(2) in dash(1) so that we could avoid reading the input line byte-by-byte which is what every other shell does in order to pass the rest of stdin to the executed command.
The shell just needs something like MSG_PEEK to do a non-consuming read from a pipe.
(Without the strange behaviour of a second offset.)
That would be simple and could have been implemented 40 years ago.
-- David
Quoted 14 lines
It's definitely niche but made a huge performance difference to this rather common scenario:
echo 'command
...
rest of stdin' | shI didn't even know tee(2) prior to this, even though it was added way back.
Thanks,
Andy Lutomirski <[email protected]>:
Quoted 4 lines
Maybe we should keep an API that does an optimized copy, from one fd to another, that can send from a file to the network with at most ONE cpu-side copy. Not aiming for zero like sendfile / splice. Aiming for one.
Yes, this is what my hypothetical future patch will do.
One copy from pagecache to pipe, and then network uses that buffer directly.
Quoted 6 lines
But
splice_to_socketinvolvesMSG_SPLACE_PAGES, which I think is a part of the mess that you dislike. And the path where one doescopy_splice_readand thensplice_to_sockethas to be a bit complex because of tee and (I think) becausesplice_to_socketcannot assume that the incoming data is just ordinary unshared buffers.
My future patch will provide new guarantee: pipe buffers are always stable, i. e. they will not be externally-modified.
So hopefully network code will be adjusted to use this guarantee.
But pipe buffers will not be "ordinary unshared buffers".
They still may be shared with other things because of tee(2). (But they are still stable! They will not be randomly modified!)
But network code can do "pipe_buf_try_steal" and thus ensure that these buffers are not shared with anything else.
So, network code can be modified to use "pipe_buf_try_steal", and you will get "ordinary unshared buffers" exactly as you want. This will give you in total exactly one copy.
Also: as well as I understand, previously, pipe_buf_try_steal was kind of lie. It may return true for buffers created via vmsplice with GIFT. (I did not check this, but I think so.) I. e. pipe_buf_try_steal will return "true" in this case, but pages are still shared! But, thanks to my vmsplice patchset (which is already applied), this is no longer true! So now pipe_buf_try_steal is absolutely safe to use!
Finally, we can degrade tee(2) to copy, and hopefully this will allow us to always be sure that pipe buffers are not shared with anything. This is possible future direction.
Signature · 1 line
Askar Safin
Quoted 43 lines · Askar Safin
Andy Lutomirski <[email protected]>:
Quoted 4 lines
Maybe we should keep an API that does an optimized copy, from one fd to another, that can send from a file to the network with at most ONE cpu-side copy. Not aiming for zero like sendfile / splice. Aiming for one.
Yes, this is what my hypothetical future patch will do.
One copy from pagecache to pipe, and then network uses that buffer directly.
Quoted 6 lines
But
splice_to_socketinvolvesMSG_SPLACE_PAGES, which I think is a part of the mess that you dislike. And the path where one doescopy_splice_readand thensplice_to_sockethas to be a bit complex because of tee and (I think) becausesplice_to_socketcannot assume that the incoming data is just ordinary unshared buffers.My future patch will provide new guarantee: pipe buffers are always stable, i. e. they will not be externally-modified.
So hopefully network code will be adjusted to use this guarantee.
But pipe buffers will not be "ordinary unshared buffers".
They still may be shared with other things because of tee(2). (But they are still stable! They will not be randomly modified!)
But network code can do "
pipe_buf_try_steal" and thus ensure that these buffers are not shared with anything else.So, network code can be modified to use "
pipe_buf_try_steal", and you will get "ordinary unshared buffers" exactly as you want. This will give you in total exactly one copy.Also: as well as I understand, previously,
pipe_buf_try_stealwas kind of lie. It may return true for buffers created via vmsplice with GIFT. (I did not check this, but I think so.) I. e.pipe_buf_try_stealwill return "true" in this case, but pages are still shared! But, thanks to my vmsplice patchset (which is already applied), this is no longer true! So nowpipe_buf_try_stealis absolutely safe to use!
Quoted 3 lines
Finally, we can degrade tee(2) to copy, and hopefully this will allow us to always be sure that pipe buffers are not shared with anything. This is possible future direction.
I'm a bit nervous that, if I've read the code correctly (a big if), then iscsi and nvme will still send *shared* buffers via MSG_SPLICE_PAGES, but that normal user code will not be able to do this, and that something will bitrot.
Andy Lutomirski <[email protected]>:
Quoted 9 lines · Askar Safin
Quoted 3 lines
Finally, we can degrade tee(2) to copy, and hopefully this will allow us to always be sure that pipe buffers are not shared with anything. This is possible future direction.
I'm a bit nervous that, if I've read the code correctly (a big if), then iscsi and nvme will still send *shared* buffers via
MSG_SPLICE_PAGES, but that normal user code will not be able to do this, and that something will bitrot.
As well as I understand you correctly, you mean that if we remove tee(2), then there still will be subsystems, which will be able to send shared pages.
Yes, I totally agree.
So, if we remove tee(2), then we will probably need to remove all non-standard implementations of pipe_buf_operations.
Signature · 1 line
Askar Safin
Quoted 3 lines · Askar Safin
So, if we remove tee(2), then we will probably need to remove all non-standard implementations of
pipe_buf_operations.
I don't think tee matters.
Sure, it will share pages across pipes.
But if we make normal "splice to pipe" always copy from the page cache, nobody cares.
You can corrupt the resulting pages as much as you want - through multiple pipes if you use tee() to copy it - and it's all just corrupting your private copy.
And yes, iSCSI and nvme might do their own splice-like thing, but again, nobody really cares. When it's all kernel-internal, the attack surface has gone away.
So that's why splice() (and vmsplice()) is special - not because it's buggy, but because it's the user-facing attack surface to expose bugs elsewhere.
Linus
Jakub Kicinski
maintainerQuoted 4 lines · On Tue, 2 Jun 2026 21:20:13 -0700 Linus Torvalds wrote:
They were all in the networking and crypto code that just didn't deal with shared data correctly.
So in that sense, it's a bit sad to discuss castrating splice.
+1 IMVHO the networking bugs where people just not knowing what they were doing. Presumably AI has scrounged all the occurrences of that bug by now. I'd also hate to render splice optimizations moot based on those bugs.
Hi Linus,
Quoted 29 lines
Quoted 2 lines
Am I understanding correctly that this will completely break zerocopy sendfile?
Very much, yes.
And it's worth making it very very clear that ABSOLUTELY NONE of the recent big security bugs were in splice.
They were all in the networking and crypto code that just didn't deal with shared data correctly.
So in that sense, it's a bit sad to discuss castrating splice.
But it's probably still the right thing to at least try.
I've seen very impressive benchmark numbers over the years, but they've often smelled more like benchmarketing than actual real work.
There's also a real possibility that a lot of the sendfile / splice advantage has little to do with zero-copy, and more to do with the cost of mapping and maintaining buffers in user space.
If you are sending file data using plain reads and writes, it's not just the "copy from user space to socket data structures".
There's also the cost of populating user space in the first place:
page faults for mmap made *that* historical copy avoidance basically a fairy tale.
Quoted 7 lines
And not using mmap means that you have the cost of double caching in the kernel _and_ user space etc.
So
sendfile()as a concept (whether you use combinations ofsplice()system calls or the sendfile system call itsefl) isn't necessarily only about the zero-copy, it's really also about avoiding the user space memory management.
I don't think so. Ok, maybe for webservers just serving tiny html files, that's true. But for me with Samba it's really the copy_to/from_iter() that is the major factor.
We can use io_uring with IOSQE_ASYNC in order to offload the memcpy cpu wasting to different cores, but it's still wasting a lot of resources.
For the case of filesystem => socket, we can use IORING_OP_SENDMSG_ZC and that at least removes the copy_from_iter() in the sendmsg path, but the IORING_OP_READV of buffers in the sizes up to 8MBytes is wasting cpu in copy_to_iter().
For the case with smbdirect and RDMA offload with 2x200GBit/s links changes from only ~33GBytes/s are used (and the server cpu even if using multiple cores) is the limit. Without the memcpy waste ~46GByte/s is easily reached
and the limit is just the network link.
Maybe another solution could be having a version of copy_to/from_iter that uses async_memcpy(), but didn't have the time to experiment with that yet. Maybe a new flag to preadv2/pwritev2 could control that, so that the application can decide what's better.
But without an alternative please don't kill splice.
A lot of people are frustrated because they bought hardware that is able to handle a lot of throughput, but e.g. with the default of smb over tcp they get no higher than 3.5GByte/s on a 100GBit/s link that's able to handle ~11GBytes/s. And io_uring and splice are a key factor to fix that.
Thanks!
metze
Quoted 34 lines · On Fri, 5 Jun 2026 11:43:45 +0200 Stefan Metzmacher <[email protected]> wrote:
Hi Linus,
Quoted 32 lines
Quoted 2 lines
Am I understanding correctly that this will completely break zerocopy sendfile?
Very much, yes.
And it's worth making it very very clear that ABSOLUTELY NONE of the recent big security bugs were in splice.
They were all in the networking and crypto code that just didn't deal with shared data correctly.
So in that sense, it's a bit sad to discuss castrating splice.
But it's probably still the right thing to at least try.
I've seen very impressive benchmark numbers over the years, but they've often smelled more like benchmarketing than actual real work.
There's also a real possibility that a lot of the sendfile / splice advantage has little to do with zero-copy, and more to do with the cost of mapping and maintaining buffers in user space.
If you are sending file data using plain reads and writes, it's not just the "copy from user space to socket data structures".
There's also the cost of populating user space in the first place:
page faults for mmap made *that* historical copy avoidance basically a fairy tale.And not using mmap means that you have the cost of double caching in the kernel _and_ user space etc.
Quoted 8 lines
Quoted 4 lines
So
sendfile()as a concept (whether you use combinations ofsplice()system calls or the sendfile system call itsefl) isn't necessarily only about the zero-copy, it's really also about avoiding the user space memory management.I don't think so. Ok, maybe for webservers just serving tiny html files, that's true. But for me with Samba it's really the copy_to/from_iter() that is the major factor.
Is that copy also doing the ip checksum?
I really can't tell from the code (it does sometimes, even for tcp). But I can't help feeling that optimisation is well past its sell by date.
-- David
Quoted 34 lines
We can use
io_uringwithIOSQE_ASYNCin order to offload the memcpy cpu wasting to different cores, but it's still wasting a lot of resources.For the case of filesystem => socket, we can use
IORING_OP_SENDMSG_ZCand that at least removes thecopy_from_iter()in the sendmsg path, but theIORING_OP_READVof buffers in the sizes up to 8MBytes is wasting cpu incopy_to_iter().For the case with smbdirect and RDMA offload with 2x200GBit/s links changes from only ~33GBytes/s are used (and the server cpu even if using multiple cores) is the limit. Without the memcpy waste ~46GByte/s is easily reached
and the limit is just the network link.Maybe another solution could be having a version of copy_to/from_iter that uses
async_memcpy(), but didn't have the time to experiment with that yet. Maybe a new flag to preadv2/pwritev2 could control that, so that the application can decide what's better.But without an alternative please don't kill splice.
A lot of people are frustrated because they bought hardware that is able to handle a lot of throughput, but e.g. with the default of smb over tcp they get no higher than 3.5GByte/s on a 100GBit/s link that's able to handle ~11GBytes/s. And
io_uringand splice are a key factor to fix that.Thanks!
metze
Hi David,
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
So
sendfile()as a concept (whether you use combinations ofsplice()system calls or the sendfile system call itsefl) isn't necessarily only about the zero-copy, it's really also about avoiding the user space memory management.I don't think so. Ok, maybe for webservers just serving tiny html files, that's true. But for me with Samba it's really the copy_to/from_iter() that is the major factor.
Is that copy also doing the ip checksum?
Not in my tests. I guess there's offload in the network hardware for this.
At least at the syscall layer of sendmsg() there's no checksuming happening.
metze
Quoted 7 lines · On Fri, 5 Jun 2026 17:20:34 +0200 Stefan Metzmacher <[email protected]> wrote:
Hi David,
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
So
sendfile()as a concept (whether you use combinations ofsplice()system calls or the sendfile system call itsefl) isn't necessarily only about the zero-copy, it's really also about avoiding the user space memory management.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
I don't think so. Ok, maybe for webservers just serving tiny html files, that's true. But for me with Samba it's really the copy_to/from_iter() that is the major factor.
Is that copy also doing the ip checksum?
Not in my tests. I guess there's offload in the network hardware for this.
There will be, it is just whether the syscall checksum is actually being suppressed.
-- David
Quoted 6 lines
At least at the syscall layer of
sendmsg()there's no checksuming happening.metze
Quoted 10 lines · Andy Lutomirski
Quoted 8 lines · Linus Torvalds
Quoted 3 lines · Askar Safin
Pedro is talking here not about this vmsplice patch, but about my future hypothetical patch, which will remove splice-pagecache-to-pipe.
That absolutely would be my suggested next step.
Quoted 8 lines
Quoted 2 lines
Something like the attached - get rid of
filemap_splice_read()entirely, and just replace it withcopy_splice_read().Am I understanding correctly that this will completely break zerocopy sendfile? sendfile is, internally, splice-to-a-secret-per-task-pipe and then splice to the socket. How much to people care? These days, a lot of high-bandwidth network senders are sending encrypted data, which is not zerocopy frompagecache. But there are surely some users
You can do zerocopy from the page cache, even with TLS on top, by having
your (fancy) NIC do TLS offloading for you. See https://people.freebsd.org/~gallatin/talks/euro2019-ktls.pdf.
Linux works similarly. Slide 26 is particularly interesting.
(No KTLS I assume is using simple sendmsg()'s from user memory, SW TLS
and NIC KTLS are both sendfile(), per the slides)
TL;DR I really do think it matters.
Quoted 13 lines
Now maybe someone cares about a different path? Splice from socket to pipe to file? Splice from socket to pipe to other socket? Does anyone do any of this? One can, of course,
recv()directly to an mmapped file, but then you pay for page faults, so that probably a bad idea in most cases. At least all of these cases don't have spliced buffers that refer to a potentially read-only file.But I'm a little concerned that zerocopy sends from files to network are actually important.
--Andy
Signature · 1 line
Pedro
Jakub Kicinski
maintainerQuoted 11 lines · On Wed, 3 Jun 2026 12:43:54 +0100 Pedro Falcato wrote:
Quoted 5 lines
Am I understanding correctly that this will completely break zerocopy sendfile? sendfile is, internally, splice-to-a-secret-per-task-pipe and then splice to the socket. How much to people care? These days, a lot of high-bandwidth network senders are sending encrypted data, which is not zerocopy frompagecache. But there are surely some users
You can do zerocopy from the page cache, even with TLS on top, by having
your (fancy) NIC do TLS offloading for you. See https://people.freebsd.org/~gallatin/talks/euro2019-ktls.pdf.
Linux works similarly. Slide 26 is particularly interesting.
(No KTLS I assume is using simple sendmsg()'s from user memory, SW TLS
and NIC KTLS are bothsendfile(), per the slides)
FTR this datapoint should come with the caveat that kTLS _offload_ does not support TLS 1.3 today. So how much that configuration is used in practice is unclear.
Quoted 7 lines · Askar Safin
See recent discussion here:
https://lore.kernel.org/all/[email protected]/T/#uFor all these reasons I propose to make vmsplice a simple wrapper for preadv2/pwritev2.
I have no comment on the code or the history. But I'm 100% in favor of the solution. vmsplice is a crappy API, and would be incredibly complex to get the implementation right, and it should be removed. But it has users, and the approach of just mapping them straight to pread/pwrite makes perfect sense.
(If anyone wants to contemplate how bad the API is, contemplate gift mode. Or contemplate that, if you want correct results, you need to avoid modifying the memory until the recipient is done reading or you need to avoid reading the memory until the writer is done writing, and vmsplice *does not tell you when it's done*. And there isn't even a caller specification of whether they want to read or write. It's ... crap.)
--Andy
Matthew Wilcox
maintainerQuoted 9 lines · Andy Lutomirski
Quoted 7 lines · Askar Safin
See recent discussion here:
https://lore.kernel.org/all/[email protected]/T/#uFor all these reasons I propose to make vmsplice a simple wrapper for preadv2/pwritev2.
Quoted 5 lines
I have no comment on the code or the history. But I'm 100% in favor of the solution. vmsplice is a crappy API, and would be incredibly complex to get the implementation right, and it should be removed. But it has users, and the approach of just mapping them straight to pread/pwrite makes perfect sense.
I agree with Andy. I think it was appropriate to send this series, since (as far as I can tell) it's a completely different approach from the others taken. I'm not really qualified to judge whether the implementation is good (it's a bit outside my competency as a reviewer), but the described approach is more convincing to me than the other approaches.
Can we review this series properly?
Quoted 2 lines · Matthew Wilcox
Can we review this series properly?
Well, since it pretty much is what I suggested a few years ago, I certainly won't NAK it.
And the patches looked very straightforward to me. Just the final diffstat is worth quoting again because that certainly doesn't look problematic:
7 files changed, 33 insertions(+), 204 deletions(-)
and it removes that GIFT flag that was truly disgusting.
So I'm certainly ok with it from a "looking at the patch" standpoint. I didn't _test_ it. I don't have any workload that might remotely care.
I did a quick scan on debian code search for vmsplice, and after ten pages of entries that weren't actually *using* it but had lists of system calls, I grew bored. So there are likely users, but I don't know what they are and how much they care. It *might* be a big performance issue somewhere. Unlikely, but...
Linus
Christian Brauner
maintainerQuoted 19 lines · Linus Torvalds
Quoted 2 lines · Matthew Wilcox
Can we review this series properly?
Well, since it pretty much is what I suggested a few years ago, I certainly won't NAK it.
And the patches looked very straightforward to me. Just the final diffstat is worth quoting again because that certainly doesn't look problematic:
7 files changed, 33 insertions(+), 204 deletions(-)and it removes that GIFT flag that was truly disgusting.
So I'm certainly ok with it from a "looking at the patch" standpoint. I didn't _test_ it. I don't have any workload that might remotely care.
Quoted 5 lines
I did a quick scan on debian code search for vmsplice, and after ten pages of entries that weren't actually *using* it but had lists of system calls, I grew bored. So there are likely users, but I don't know what they are and how much they care. It *might* be a big performance issue somewhere. Unlikely, but...
As usual I would argue to accept it and revert in case we get actual regression reports...
Quoted 3 lines · Christian Brauner
As usual I would argue to accept it and revert in case we get actual regression reports...
Yes, likely the only way we'd ever find out ..
Linus
Quoted 2 lines · Linus Torvalds
Well, since it pretty much is what I suggested a few years ago, I certainly won't NAK it.
I've been wanting to get rid of vmsplice for a while, so I'm in favour of this too.
David
Quoted 8 lines · Askar Safin
This patchset is for VFS.
Recently we got a lot of vulnerabilities in splice/vmsplice.
Also vmsplice already was source of vulnerabilities in the past:
CVE-2020-29374 (see https://lwn.net/Articles/849638/ ).[...]
Applied to the vfs-7.2.vmsplice branch of the vfs/vfs.git tree. Patches in the vfs-7.2.vmsplice branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.2.vmsplice
[1/3] tee: fs/splice.c: remove unused parameter "flags" from "link_pipe"
https://git.kernel.org/vfs/vfs/c/a9f7db50ed2f [2/3] vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2 https://git.kernel.org/vfs/vfs/c/e2c0b2368081 [3/3] splice: remove PIPE_BUF_FLAG_GIFT https://git.kernel.org/vfs/vfs/c/7d75aa8edfce
Quoted 2 lines · Christian Brauner
Applied to the vfs-7.2.vmsplice branch of the vfs/vfs.git tree.
Btw, if people want to work further on this - assuming we don't get any huge screams of pain from having effectively gotten rid of vmsplice() - I don't think it would hurt to look at limiting the "regular" splice() too.
We already have the code to just turn it into a pure copy on the "splice to pipe" case: copy_splice_read(). In many ways it would be *lovely* to just always force that path.
We already do that explicitly for DAX and O_DIRECT, but we made a lot of special files do it implicitly too, so quite a lot of the splice reading cases already use that "just read() into a kernel space buffer" model for splicing.
It would be interesting to hear who would even notice if we just always used that copy case, and made "f_op->splice_read" never trigger at all.
And it turns out that the only thing that ever uses "f_op->splice_write" is splice_to_socket. Which was actually the problematic buggy case.
Everybody else pretty much seems to just use iter_file_splice_write(), which does the "emulate it with just a write from kernel buffers".
So *if* we get rid of f_op->splice_read, we do leave the case that really caused problems, but nobody will ever care. Because once splice only deals with private buffers that can't be shared with anything else, a f_op->splice_write() that gets things wrong is pretty much a non-event.
(We'd have to look at 'tee()' too: I don't think anybody really uses it, but it does do the "no copy linking" by just incrementing refcounts on the pipe buffers. So to really protect against splice_write users messing up, that should do copies too, but as long as it's all "private ephemeral buffers" that get their refcounts updated, I don't think anybody *really* cares)
TLDR: maybe we could ghet rid of "f_op->splice_read". *That* would be a big simplification.
Linus
Al Viro
maintainerQuoted 2 lines · Linus Torvalds
TLDR: maybe we could ghet rid of "
f_op->splice_read". *That* would be a big simplification.
FUSE might be interesting - fuse_dev_splice_read() and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...
splice-related logics in fs/fuse/dev.c is interesting; another place like this is kernel/trace/, but I'm less familiar with that one.
rostedt Cc'd (miklos already had been)
Quoted 10 lines · On Mon, 1 Jun 2026 18:33:25 +0100 Al Viro <[email protected]> wrote:
Quoted 2 lines · Linus Torvalds
TLDR: maybe we could ghet rid of "
f_op->splice_read". *That* would be a big simplification.FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...
Quoted 4 lines
splice-related logics in
fs/fuse/dev.cis interesting; another place like this iskernel/trace/, but I'm less familiar with that one.rostedt Cc'd (miklos already had been)
Thanks for the Cc. The tracing ring buffer was specifically made to be used by splice and the libtracefs has a lot of code to use it as well. As reading the ring buffer literally swaps out the write portion with a blank read portion, that portion (sub-buffer) is used to be directly fed into splice, providing a zero-copy of the trace data from the write of the event to going into a file.
trace-cmd defaults to using splice to copy the tracing ring buffer directly into files to avoid as much copying during live recordings as possible.
Whatever changes we make, I would like to make sure there's no regressions in performance of trace-cmd record.
Thanks,
-- Steve
Andrew Morton
maintainerQuoted 25 lines · On Mon, 1 Jun 2026 16:04:55 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 10 lines · On Mon, 1 Jun 2026 18:33:25 +0100 Al Viro <[email protected]> wrote:
Quoted 2 lines · Linus Torvalds
TLDR: maybe we could ghet rid of "
f_op->splice_read". *That* would be a big simplification.FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...Quoted 4 lines
splice-related logics in
fs/fuse/dev.cis interesting; another place like this iskernel/trace/, but I'm less familiar with that one.rostedt Cc'd (miklos already had been)
Thanks for the Cc. The tracing ring buffer was specifically made to be used by splice and the libtracefs has a lot of code to use it as well. As reading the ring buffer literally swaps out the write portion with a blank read portion, that portion (sub-buffer) is used to be directly fed into splice, providing a zero-copy of the trace data from the write of the event to going into a file.
Quoted 5 lines
trace-cmd defaults to using splice to copy the tracing ring buffer directly into files to avoid as much copying during live recordings as possible.
Whatever changes we make, I would like to make sure there's no regressions in performance of trace-cmd record.
Well yes, The patchset seems sensible from a quality POV. But to make a decision we should first have a decent understanding of its downside impact.
I haven't seen a description of that impact in the discussion thus far. And that description is owed, please.
I assume a small number of specialized applications are using vmsplice() to great effect? What are those applications? What is the impact of this change?
Once we are armed with that information, is there some middle ground in which we de-feature vmsplice()? Fall back to pread/pwrite in the tricky cases and still permit vmsplicing if the application is appropriately restrictive in it usage?
David Hildenbrand (Arm)
maintainerQuoted 27 lines · Andrew Morton
Quoted 25 lines · On Mon, 1 Jun 2026 16:04:55 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 11 lines · On Mon, 1 Jun 2026 18:33:25 +0100 Al Viro <[email protected]> wrote:
FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...splice-related logics in
fs/fuse/dev.cis interesting; another place like this iskernel/trace/, but I'm less familiar with that one.rostedt Cc'd (miklos already had been)
Thanks for the Cc. The tracing ring buffer was specifically made to be used by splice and the libtracefs has a lot of code to use it as well. As reading the ring buffer literally swaps out the write portion with a blank read portion, that portion (sub-buffer) is used to be directly fed into splice, providing a zero-copy of the trace data from the write of the event to going into a file.
trace-cmd defaults to using splice to copy the tracing ring buffer directly into files to avoid as much copying during live recordings as possible.
Quoted 6 lines
Quoted 2 lines
Whatever changes we make, I would like to make sure there's no regressions in performance of trace-cmd record.
Well yes, The patchset seems sensible from a quality POV. But to make a decision we should first have a decent understanding of its downside impact.
I guess most (all?) of us ... dislike ... vmsplice(), so trying to remove it entirely is certainly very appealing ...
Quoted 7 lines
I haven't seen a description of that impact in the discussion thus far. And that description is owed, please.
I assume a small number of specialized applications are using
vmsplice()to great effect? What are those applications? What is the impact of this change?
I did some digging, and the kernel crypto API documents using splice/vmsplice for zero-copy[1] and libkcapi [2].
I did not find performance numbers, how much vmsplice/splice actually gives us. Playing with the kcapi-speed tool [3] (specifying --vmsplice vs. --sendmsg) doesn't really reveal a big difference at least on my notebook. Not sure if the parameters I specify are reasonable.
I don't know whether downgrading vmsplice to preadv2/pwritev2 would perform significantly worse than sendmsg ... and I don't know what the default would usually be (default to vmsplice or sendmsg). I might try finding some time to play with it more, but I doubt it, so if anybody else has time ... :)
I'll note that we have a bunch of selftests (mostly around COW handling) that rely on vmsplice to test R/O pinning behavior. For R/W pinning, we can use iouring fixed buffers easily. The only alternative for R/O pinning is using the gup_test infrastructure that needs to be compiled into the kernel, unfortunately ...
So we'll have to adjust some tests there to use a different interface. I'm sure I can find someone to work on that once this change here landed and doesn't have to be yanked immediately again.
[1] https://www.kernel.org/doc/html/latest/crypto/userspace-if.html
[2] https://github.com/smuellerDD/libkcapi/blob/master/lib/kcapi-kernel-if.c
[3] https://github.com/smuellerDD/libkcapi/tree/master/speed-test
Signature · 3 lines
Cheers, David
Quoted 55 lines · David Hildenbrand (Arm)
Quoted 27 lines · Andrew Morton
Quoted 25 lines · On Mon, 1 Jun 2026 16:04:55 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 11 lines · On Mon, 1 Jun 2026 18:33:25 +0100 Al Viro <[email protected]> wrote:
FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...splice-related logics in
fs/fuse/dev.cis interesting; another place like this iskernel/trace/, but I'm less familiar with that one.rostedt Cc'd (miklos already had been)
Thanks for the Cc. The tracing ring buffer was specifically made to be used by splice and the libtracefs has a lot of code to use it as well. As reading the ring buffer literally swaps out the write portion with a blank read portion, that portion (sub-buffer) is used to be directly fed into splice, providing a zero-copy of the trace data from the write of the event to going into a file.
trace-cmd defaults to using splice to copy the tracing ring buffer directly into files to avoid as much copying during live recordings as possible.
Quoted 6 lines
Quoted 2 lines
Whatever changes we make, I would like to make sure there's no regressions in performance of trace-cmd record.
Well yes, The patchset seems sensible from a quality POV. But to make a decision we should first have a decent understanding of its downside impact.
I guess most (all?) of us ... dislike ...
vmsplice(), so trying to remove it entirely is certainly very appealing ...Quoted 7 lines
I haven't seen a description of that impact in the discussion thus far. And that description is owed, please.
I assume a small number of specialized applications are using
vmsplice()to great effect? What are those applications? What is the impact of this change?I did some digging, and the kernel crypto API documents using splice/vmsplice for zero-copy[1] and libkcapi [2].
I did not find performance numbers, how much vmsplice/splice actually gives us. Playing with the kcapi-speed tool [3] (specifying --vmsplice vs. --sendmsg) doesn't really reveal a big difference at least on my notebook. Not sure if the parameters I specify are reasonable.
Quoted 4 lines
I don't know whether downgrading vmsplice to preadv2/pwritev2 would perform significantly worse than sendmsg ... and I don't know what the default would usually be (default to vmsplice or sendmsg). I might try finding some time to play with it more, but I doubt it, so if anybody else has time ... :)
AF_ALG is a mistake and isn't commonly used. Using a userspace crypto library is faster and is what almost everyone does anyway, as it avoids the syscall overhead. There are many other issues with AF_ALG as well.
7.2 will mark AF_ALG as deprecated, mostly remove AF_ALG's zero-copy support, and remove AF_ALG's async I/O support:
https://lore.kernel.org/linux-crypto/[email protected]/ https://lore.kernel.org/linux-crypto/[email protected]/ https://lore.kernel.org/linux-crypto/[email protected]/
In practice, the programs that are keeping Linux distros from disabling AF_ALG in their kconfig outright are just iwd, cryptsetup, and bluez. They use AF_ALG just because it was mistakenly thought to be easier than using a userspace crypto library. They don't need maximum performance, nor do they use vmsplice, splice, or sendfile.
There is other highly niche code out there that does implement the AF_ALG + vmsplice + splice thing, e.g. libkcapi. But it's just not enough of a reason to keep zero-copy support, especially considering that AF_ALG has always been the wrong solution in the first place. The fallback to copying the data is fine for this deprecated API.
- Eric
David Hildenbrand (Arm)
maintainerQuoted 50 lines · Eric Biggers
Quoted 27 lines · David Hildenbrand (Arm)
Quoted 5 lines · Andrew Morton
Well yes, The patchset seems sensible from a quality POV. But to make a decision we should first have a decent understanding of its downside impact.
I guess most (all?) of us ... dislike ...
vmsplice(), so trying to remove it entirely is certainly very appealing ...Quoted 7 lines
I haven't seen a description of that impact in the discussion thus far. And that description is owed, please.
I assume a small number of specialized applications are using
vmsplice()to great effect? What are those applications? What is the impact of this change?I did some digging, and the kernel crypto API documents using splice/vmsplice for zero-copy[1] and libkcapi [2].
I did not find performance numbers, how much vmsplice/splice actually gives us. Playing with the kcapi-speed tool [3] (specifying --vmsplice vs. --sendmsg) doesn't really reveal a big difference at least on my notebook. Not sure if the parameters I specify are reasonable.
Quoted 4 lines
I don't know whether downgrading vmsplice to preadv2/pwritev2 would perform significantly worse than sendmsg ... and I don't know what the default would usually be (default to vmsplice or sendmsg). I might try finding some time to play with it more, but I doubt it, so if anybody else has time ... :)
AF_ALGis a mistake and isn't commonly used. Using a userspace crypto library is faster and is what almost everyone does anyway, as it avoids the syscall overhead. There are many other issues withAF_ALGas well.7.2 will mark
AF_ALGas deprecated, mostly remove AF_ALG's zero-copy support, and remove AF_ALG's async I/O support:https://lore.kernel.org/linux-crypto/[email protected]/ https://lore.kernel.org/linux-crypto/[email protected]/ https://lore.kernel.org/linux-crypto/[email protected]/In practice, the programs that are keeping Linux distros from disabling
AF_ALGin their kconfig outright are just iwd, cryptsetup, and bluez. They useAF_ALGjust because it was mistakenly thought to be easier than using a userspace crypto library. They don't need maximum performance, nor do they use vmsplice, splice, or sendfile.
Quoted 5 lines
There is other highly niche code out there that does implement the
AF_ALG+ vmsplice + splice thing, e.g. libkcapi. But it's just not enough of a reason to keep zero-copy support, especially considering thatAF_ALGhas always been the wrong solution in the first place. The fallback to copying the data is fine for this deprecated API.
Cool, thanks for sharing that Eric!
Signature · 3 lines
Cheers, David
Quoted 40 lines · Andrew Morton
Quoted 25 lines · On Mon, 1 Jun 2026 16:04:55 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 10 lines · On Mon, 1 Jun 2026 18:33:25 +0100 Al Viro <[email protected]> wrote:
Quoted 2 lines · Linus Torvalds
TLDR: maybe we could ghet rid of "
f_op->splice_read". *That* would be a big simplification.FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...Quoted 4 lines
splice-related logics in
fs/fuse/dev.cis interesting; another place like this iskernel/trace/, but I'm less familiar with that one.rostedt Cc'd (miklos already had been)
Thanks for the Cc. The tracing ring buffer was specifically made to be used by splice and the libtracefs has a lot of code to use it as well. As reading the ring buffer literally swaps out the write portion with a blank read portion, that portion (sub-buffer) is used to be directly fed into splice, providing a zero-copy of the trace data from the write of the event to going into a file.
Quoted 5 lines
trace-cmd defaults to using splice to copy the tracing ring buffer directly into files to avoid as much copying during live recordings as possible.
Whatever changes we make, I would like to make sure there's no regressions in performance of trace-cmd record.
Well yes, The patchset seems sensible from a quality POV. But to make a decision we should first have a decent understanding of its downside impact.
I haven't seen a description of that impact in the discussion thus far. And that description is owed, please.
Quoted 8 lines
I assume a small number of specialized applications are using
vmsplice()to great effect? What are those applications? What is the impact of this change?Once we are armed with that information, is there some middle ground in which we de-feature
vmsplice()? Fall back to pread/pwrite in the tricky cases and still permit vmsplicing if the application is appropriately restrictive in it usage?
I'm using vmsplice() + tee() + splice() in high-performance applications, load generators to be precise, and soon a cache. This is super convenient and extremely efficient:
- vmsplice() is used to prepare a "master" pipe with data to be sent over TCP or kTLS
- then for each request, we do tee() from this master pipe to per-request pipes.
- the per-request pipes are those that are used to deliver the data to the socket via splice().
So we effectively use vmsplice(), tee() and splice() here, and for exactly the reasons they were designed: only play with page refcount and not copy data. The code is here for the curious:
https://git.haproxy.org/?p=haproxy.git;a=blob;f=src/haterm.c
and its ancestor is here:
https://github.com/wtarreau/httpterm/blob/master/httpterm.c
It simply doubles the network bandwidth compared to not using that. (62 Gbps per core vs 31). I would seriously miss it if I couldn't use this anymore.
I also have mid-term plans for using vmsplice() to deliver contents from a cache to sockets as well via splice(). Right now our cache is split into too small chunks (1kB) to make that useful, but as soon as we can move to 4kB pages, it will make sense. There the same gains are expected, and I would particularly dislike the idea of no longer being able to implement zero-copy!
Maybe some arrangements are possible though. I'm not seeing any other way to achieve the same things differently, but possibly that the base of the problem is the easy abuse of vmsplice() to affect the page cache. Maybe placing certain restrictions such as he area only being mapped to anonymous pages, or anything similar could make sense. In my use case it wouldn't be that much of a constraint. Well, for the cache maybe it could be though, as it would prevent us from sharing it via persistent storage. Or maybe we could require a CAP_BACKED_VMSPLICE to be allowed to vmsplice file- backed pages, which could be sufficient to prevent easy LPE each time a bug is found ?
I think that the users of this APIs are rare enough that we can probably find a solution that anyone can reasonably adapt to with minimal constraints. But most likely each of these few users rely on this *a lot*.
Just my two cents,
Willy
Quoted 11 lines · Willy Tarreau
I'm using
vmsplice()+tee()+splice()in high-performance applications, load generators to be precise, and soon a cache. This is super convenient and extremely efficient:-
vmsplice()is used to prepare a "master" pipe with data to be sent over TCP or kTLS
- then for each request, we dotee()from this master pipe to per-request pipes.
- the per-request pipes are those that are used to deliver the data to the socket viasplice().
So most of those would actually not be affected by any of the existing
patches: the pipe->socket splice would remain, the tee() code would still just take a ref to the page count.
The vmsplice() would change, but looking at your haterm.c sources, it looks like it's mostly a fairly small thing ("common_response[]" being 16kB).
That is typically *faster* to just copy than look up pages.
HOWEVER.
It looks like you're actually doing exactly the thing that I thought was crazy and wouldn't even work reliably: you change the common_response[] contents dynamically *after* the vmsplice, and depend on the fact that changing it in user space changes the buffer in the pipe too.
So that would break *entirely* with the vmsplice() changes if I read the code right (which I might not do) simply because that looks like it really does require that "wrutably shared buffer after the fact".
Interesting. Because the vmsplice() code uses get_user_pages_fast(), and honestly, it never pinned the page reliably to the original source
- it breaks COW randomly in one direction or the other after fork() (and I thouht even after a page-out, but thinking more about it the swap cache may have made it work for that case).
Uhhuh. That does look like it makes the vmsplice() changes untenable.
But I may be reading your haproxy code entirely wrong.
Linus
Quoted 13 lines · Linus Torvalds
Quoted 11 lines · Willy Tarreau
I'm using
vmsplice()+tee()+splice()in high-performance applications, load generators to be precise, and soon a cache. This is super convenient and extremely efficient:-
vmsplice()is used to prepare a "master" pipe with data to be sent over TCP or kTLS
- then for each request, we dotee()from this master pipe to per-request pipes.
- the per-request pipes are those that are used to deliver the data to the socket viasplice().
Quoted 3 lines
So most of those would actually not be affected by any of the existing
patches: thepipe->socketsplice would remain, thetee()code would still just take a ref to the page count.
OK!
Quoted 1 line
The
vmsplice()would change,
OK but for this use case it's not dramatic (it could be more annyoing for the cache where I'd like this zero-copy from memory to the wire though).
Quoted 3 lines
but looking at your
haterm.csources, it
looks like it's mostly a fairly small thing ("common_response[]" being 16kB).
In this one it's indeed a 16kB block that is repeated into the same pipe by simplicity, in its ancestor it was 64kB. We try to make as large a pipe as we can, but that's all.
Quoted 9 lines
That is typically *faster* to just copy than look up pages.
HOWEVER.
It looks like you're actually doing exactly the thing that I thought was crazy and wouldn't even work reliably: you change the common_response[] contents dynamically *after* the vmsplice, and depend on the fact that changing it in user space changes the buffer in the pipe too.
No no, it's definitely not doing that (or it's a bug, but it's not supposed to happen). I'm perfectly aware that one must definitely not do that, and it's a guarantee the user of vmsplice() must provide.
Quoted 3 lines
So that would break *entirely* with the
vmsplice()changes if I read the code right (which I might not do) simply because that looks like it really does require that "wrutably shared buffer after the fact".
We agree that this would deliver complete garbage an I'm not interested in such a "feature" at all.
Quoted 3 lines
Interesting. Because the
vmsplice()code usesget_user_pages_fast(), and honestly, it never pinned the page reliably to the original source
- it breaks COW randomly in one direction or the other afterfork()
I must confess I never knew how it deals with pages shared over a fork(), and have been wondering if two processes could create a shared memory area on the fly just by using vmsplice() on each side and end up with the same pages (I don't need this but it could have very nice use cases).
Quoted 4 lines
(and I thouht even after a page-out, but thinking more about it the swap cache may have made it work for that case).
Uhhuh. That does look like it makes the
vmsplice()changes untenable.
No no don't worry, I'm not seeing any value in changing data after vmsplice() and that would just be a bug. My goal here is only to pre-fill a buffer with a pattern then prepare the pipe with that pattern, nothing less, nothing more.
Quoted 1 line
But I may be reading your haproxy code entirely wrong.
I think so, but I wouldn't be the one blaming you for this ;-)
Thanks for the clarifications!
Willy
Quoted 10 lines · Willy Tarreau
Quoted 6 lines
It looks like you're actually doing exactly the thing that I thought was crazy and wouldn't even work reliably: you change the common_response[] contents dynamically *after* the vmsplice, and depend on the fact that changing it in user space changes the buffer in the pipe too.
No no, it's definitely not doing that (or it's a bug, but it's not supposed to happen). I'm perfectly aware that one must definitely not do that, and it's a guarantee the user of
vmsplice()must provide.
Whew, good.
In that case, can you just try the vmsplice patch series (Christian already found a bug, but I don't think it will necessarily matter in practice - famous last words) and that test patch of mine, and see if it all (a) works for you and (b) if you have any numbers for performance that would be *great*.
There aren't many obvious splice users out there, and even if they were to exist they are typically specialized enough that you have to have a real use case to then tell if the patches make a difference in real life or not.
So you testing that thing would seem to be a great first test of whether any of this is realistic..
Linus
Quoted 12 lines · Linus Torvalds
Quoted 10 lines · Willy Tarreau
Quoted 6 lines
It looks like you're actually doing exactly the thing that I thought was crazy and wouldn't even work reliably: you change the common_response[] contents dynamically *after* the vmsplice, and depend on the fact that changing it in user space changes the buffer in the pipe too.
No no, it's definitely not doing that (or it's a bug, but it's not supposed to happen). I'm perfectly aware that one must definitely not do that, and it's a guarantee the user of
vmsplice()must provide.
Quoted 7 lines
Whew, good.
In that case, can you just try the vmsplice patch series (Christian already found a bug, but I don't think it will necessarily matter in practice - famous last words) and that test patch of mine, and see if it all (a) works for you and (b) if you have any numbers for performance that would be *great*.
Yes I wanted to do that and noted it on my todo list yesterday when noticing the ongoing discussion. Just been super busy with yesterday's by-yearly release ;-) But at least I wanted to share quick feedback in this thread about existing uses.
Quoted 4 lines
There aren't many obvious splice users out there, and even if they were to exist they are typically specialized enough that you have to have a real use case to then tell if the patches make a difference in real life or not.
I totally agree, that's why I want to share some feedback. I remember years ago when splice() was broken in 2.6.25, there were so few users that I was the one reporting an API issue to Eric who addressed it early by lack of users. And I even consider that due to the very few users, it's even acceptable to slightly change the way to use it if it can provide extra guarantees (like requiring a capability to access non-anonymous pages for example). It should not break that many apps, and as long as they can preserve their essential benefits, I think most will be OK to adapt.
Quoted 2 lines
So you testing that thing would seem to be a great first test of whether any of this is realistic..
Absolutely!
Willy
Willy Tarreau
Tested-byQuoted 21 lines · Willy Tarreau
Quoted 12 lines · Linus Torvalds
Quoted 10 lines · Willy Tarreau
Quoted 6 lines
It looks like you're actually doing exactly the thing that I thought was crazy and wouldn't even work reliably: you change the common_response[] contents dynamically *after* the vmsplice, and depend on the fact that changing it in user space changes the buffer in the pipe too.
No no, it's definitely not doing that (or it's a bug, but it's not supposed to happen). I'm perfectly aware that one must definitely not do that, and it's a guarantee the user of
vmsplice()must provide.Quoted 7 lines
Whew, good.
In that case, can you just try the vmsplice patch series (Christian already found a bug, but I don't think it will necessarily matter in practice - famous last words) and that test patch of mine, and see if it all (a) works for you and (b) if you have any numbers for performance that would be *great*.
Quoted 4 lines
Yes I wanted to do that and noted it on my todo list yesterday when noticing the ongoing discussion. Just been super busy with yesterday's by-yearly release ;-) But at least I wanted to share quick feedback in this thread about existing uses.
OK so I could run the test this afternoon, with:
- ddd664bbff63 Merge tag 'net-7.1-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
(v7.1-rc6-178)
- the same with Christian's vfs-7.2.vmsplice branch merged into it
( 8d86fcfc2857 include/linux/splice.h: trivial fix: declerations -> declarations)
Both show 71-72 Gbps of TLS traffic per core on my test utility (I stopped at 3 cores since having only 2x100G at the moment), so for this use case I'm not impacted by the change. I noted that I will have to reconsider other options for the cache (send(MSG_ZEROCOPY) probably) but in my case since the code doesn't exist yet it's not per-se a userland breakage, but a change of plans. I just hope I'll find my way through the alternate solution.
FWIW for Christian's branch:
Willy
Quoted 20 lines · Linus Torvalds
Quoted 10 lines · Willy Tarreau
Quoted 6 lines
It looks like you're actually doing exactly the thing that I thought was crazy and wouldn't even work reliably: you change the common_response[] contents dynamically *after* the vmsplice, and depend on the fact that changing it in user space changes the buffer in the pipe too.
No no, it's definitely not doing that (or it's a bug, but it's not supposed to happen). I'm perfectly aware that one must definitely not do that, and it's a guarantee the user of
vmsplice()must provide.Whew, good.
In that case, can you just try the vmsplice patch series (Christian already found a bug, but I don't think it will necessarily matter in practice - famous last words) and that test patch of mine, and see if it all (a) works for you and (b) if you have any numbers for performance that would be *great*.
Quoted 4 lines
There aren't many obvious splice users out there, and even if they were to exist they are typically specialized enough that you have to have a real use case to then tell if the patches make a difference in real life or not.
In the Rust standard library we use splice as one of several strategies in our generic io::copy[0] routine. It selects the strategy[1] based on source and sink types.
It tries
- copy_file_range
- sendfile
- splice
- fallback to userspace read-write loop
sendfile or splice are skipped when we can't uphold the "callers must ensure transferred portions in_fd remain unmodified" condition on the manpage, which unfortunately includes some particularly desirable combinations of sinks and sources (such as mutable files -> socket).
We primarily want this for reflink copies and to avoid the syscall overhead of a read-write loop with a small stack buffer.
Any additional zerocopy benefit, when it doesn't lead to unstable data, is welcome but not critical. E.g. it'd be nice if sendfile could do the following:
For a 1MB source and a socket with a 64kB sendbuffer it could zerocopy first ~900kB safely and then memcpy the last 64kB to ensure it can't be modified after the syscall returns. But a "just memcpy in kernel space instead of zerocopy" flag for sendfile would be ok too.
We're currently not making use of vmsplice. In theory we'd like to use it for copying from &'static [u8] sources since the type upholds the requirements of vmsplice, but type specialization currently is not powerful enough to select based on this lifetime and it's unclear if it'll ever be.
[0] https://doc.rust-lang.org/nightly/std/io/fn.copy.html
[1] https://github.com/rust-lang/rust/blob/ac6f3a3e778a586854bdbf8f15202e11e2348d9f/library/std/src/sys/io/kernel_copy/linux.rs#L210-L259
Quoted 6 lines
So you testing that thing would seem to be a great first test of whether any of this is realistic..
Linus
Quoted 68 lines · Willy Tarreau
Quoted 40 lines · Andrew Morton
Quoted 25 lines · On Mon, 1 Jun 2026 16:04:55 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 10 lines · On Mon, 1 Jun 2026 18:33:25 +0100 Al Viro <[email protected]> wrote:
Quoted 2 lines · Linus Torvalds
TLDR: maybe we could ghet rid of "
f_op->splice_read". *That* would be a big simplification.FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...Quoted 4 lines
splice-related logics in
fs/fuse/dev.cis interesting; another place like this iskernel/trace/, but I'm less familiar with that one.rostedt Cc'd (miklos already had been)
Thanks for the Cc. The tracing ring buffer was specifically made to be used by splice and the libtracefs has a lot of code to use it as well. As reading the ring buffer literally swaps out the write portion with a blank read portion, that portion (sub-buffer) is used to be directly fed into splice, providing a zero-copy of the trace data from the write of the event to going into a file.
Quoted 5 lines
trace-cmd defaults to using splice to copy the tracing ring buffer directly into files to avoid as much copying during live recordings as possible.
Whatever changes we make, I would like to make sure there's no regressions in performance of trace-cmd record.
Well yes, The patchset seems sensible from a quality POV. But to make a decision we should first have a decent understanding of its downside impact.
I haven't seen a description of that impact in the discussion thus far. And that description is owed, please.
Quoted 8 lines
I assume a small number of specialized applications are using
vmsplice()to great effect? What are those applications? What is the impact of this change?Once we are armed with that information, is there some middle ground in which we de-feature
vmsplice()? Fall back to pread/pwrite in the tricky cases and still permit vmsplicing if the application is appropriately restrictive in it usage?I'm using
vmsplice()+tee()+splice()in high-performance applications, load generators to be precise, and soon a cache. This is super convenient and extremely efficient:-
vmsplice()is used to prepare a "master" pipe with data to be sent over TCP or kTLS
- then for each request, we dotee()from this master pipe to per-request pipes.
- the per-request pipes are those that are used to deliver the data to the socket viasplice().So we effectively use
vmsplice(),tee()andsplice()here, and for exactly the reasons they were designed: only play with page refcount and not copy data. The code is here for the curious:https://git.haproxy.org/?p=haproxy.git;a=blob;f=src/haterm.c
Quoted 8 lines
and its ancestor is here:
https://github.com/wtarreau/httpterm/blob/master/httpterm.c
It simply doubles the network bandwidth compared to not using that. (62 Gbps per core vs 31). I would seriously miss it if I couldn't use this anymore.
Wait a moment. This is neat, but it's literally just a benchmark, right? I skimmed the code, and it doesn't look like a production workload, either. And you manage to get around the awfulness of the vmsplice API's complete failure to tell you when it's done with a buffer by ... never actually changing the contents of the buffer. Do you have any idea how you would write correct code that uses vmsplice for sends and then *ever* mutates the data without literally munmapping (or madvise or something) the data do you can safely mutate it?
Quoted 6 lines
I also have mid-term plans for using
vmsplice()to deliver contents from a cache to sockets as well viasplice(). Right now our cache is split into too small chunks (1kB) to make that useful, but as soon as we can move to 4kB pages, it will make sense. There the same gains are expected, and I would particularly dislike the idea of no longer being able to implement zero-copy!
If I'm understanding you correctly, you see (and measured!) a performance improvement, and you would like to use it in production.
It seems to me that this is an excellent opportunity to remember that vmsplice gets a performance boost in a highly synthetic situation that sort of resembles a cache scenario and then to deprecate vmsplice and build something better! Or discover that we already have something better, perhaps :)
https://man7.org/linux/man-pages/man3/io_uring_prep_send_zc.3.html
I see that this can submit a buffer without a syscall (tee + splice is *two* syscalls!) and that it has directly addressed what I see as the really big deficiency in vmsplice: "This second notification tells the application that the memory associated with the send is safe to get reused." If I were writing the user code, I would very much want that notification to be an explicit part of the API instead of making a wild guess as I think I would need to do with vmsplice.
--Andy
Quoted 73 lines · Andy Lutomirski
Quoted 72 lines · Willy Tarreau
Quoted 40 lines · Andrew Morton
Quoted 25 lines · On Mon, 1 Jun 2026 16:04:55 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 10 lines · On Mon, 1 Jun 2026 18:33:25 +0100 Al Viro <[email protected]> wrote:
Quoted 2 lines · Linus Torvalds
TLDR: maybe we could ghet rid of "
f_op->splice_read". *That* would be a big simplification.FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...Quoted 4 lines
splice-related logics in
fs/fuse/dev.cis interesting; another place like this iskernel/trace/, but I'm less familiar with that one.rostedt Cc'd (miklos already had been)
Thanks for the Cc. The tracing ring buffer was specifically made to be used by splice and the libtracefs has a lot of code to use it as well. As reading the ring buffer literally swaps out the write portion with a blank read portion, that portion (sub-buffer) is used to be directly fed into splice, providing a zero-copy of the trace data from the write of the event to going into a file.
Quoted 5 lines
trace-cmd defaults to using splice to copy the tracing ring buffer directly into files to avoid as much copying during live recordings as possible.
Whatever changes we make, I would like to make sure there's no regressions in performance of trace-cmd record.
Well yes, The patchset seems sensible from a quality POV. But to make a decision we should first have a decent understanding of its downside impact.
I haven't seen a description of that impact in the discussion thus far. And that description is owed, please.
Quoted 8 lines
I assume a small number of specialized applications are using
vmsplice()to great effect? What are those applications? What is the impact of this change?Once we are armed with that information, is there some middle ground in which we de-feature
vmsplice()? Fall back to pread/pwrite in the tricky cases and still permit vmsplicing if the application is appropriately restrictive in it usage?I'm using
vmsplice()+tee()+splice()in high-performance applications, load generators to be precise, and soon a cache. This is super convenient and extremely efficient:-
vmsplice()is used to prepare a "master" pipe with data to be sent over TCP or kTLS
- then for each request, we dotee()from this master pipe to per-request pipes.
- the per-request pipes are those that are used to deliver the data to the socket viasplice().So we effectively use
vmsplice(),tee()andsplice()here, and for exactly the reasons they were designed: only play with page refcount and not copy data. The code is here for the curious:https://git.haproxy.org/?p=haproxy.git;a=blob;f=src/haterm.c
and its ancestor is here:
Quoted 7 lines
Quoted 4 lines
It simply doubles the network bandwidth compared to not using that. (62 Gbps per core vs 31). I would seriously miss it if I couldn't use this anymore.
Wait a moment. This is neat, but it's literally just a benchmark, right?
No, it's a benchmark *tool*: it's being used to stress production code, which is important and super hard at high loads. You place it after your proxy and you measure the performance of the proxy (which is supposed not to be as capable as the testing tools otherwise the methodology revolves to testing the testing tools, which is not the point).
Quoted 8 lines
I skimmed the code, and it doesn't look like a production workload, either. And you manage to get around the awfulness of the vmsplice API's complete failure to tell you when it's done with a buffer by ... never actually changing the contents of the buffer. Do you have any idea how you would write correct code that uses vmsplice for sends and then *ever* mutates the data without literally munmapping (or madvise or something) the data do you can safely mutate it?
I'm not sure what you mean here Andy. I *do not* need to change the data, it's just a pre-made pattern.
Quoted 9 lines
Quoted 6 lines
I also have mid-term plans for using
vmsplice()to deliver contents from a cache to sockets as well viasplice(). Right now our cache is split into too small chunks (1kB) to make that useful, but as soon as we can move to 4kB pages, it will make sense. There the same gains are expected, and I would particularly dislike the idea of no longer being able to implement zero-copy!If I'm understanding you correctly, you see (and measured!) a performance improvement, and you would like to use it in production.
The prod for the tool is to be used to benchmark other tools. It does the job quite well. It's even more important when you use kTLS-enabled hardware where you can get zero-copy all along the line and delegate the crypto to the hardware. That's the beauty of all the nice work that was done in the stack along all these years. That code started to be used in clear maybe 15 years ago or so, but nowadays the gains are even more interesting.
Quoted 4 lines
It seems to me that this is an excellent opportunity to remember that vmsplice gets a performance boost in a highly synthetic situation that sort of resembles a cache scenario and then to deprecate vmsplice and build something better!
I've definitely been keeping vmsplice() on my radar for our cache, and we've progressively implemented various architectural updates in haproxy precisely for this.
Quoted 3 lines
Or discover that we already have something better, perhaps :)
https://man7.org/linux/man-pages/man3/io_uring_prep_send_zc.3.html
io_uring is different. We tried it "the dirty way" in the past, by emulating a poller, and it's not worth it this way. And in order to do it the right way, it needs to be done totally differently, which has impacts all over the stack. The code in the file pointed to above is just for the httpterm testing feature, but the rest is much more complex.
Quoted 7 lines
I see that this can submit a buffer without a syscall (tee + splice is *two* syscalls!) and that it has directly addressed what I see as the really big deficiency in vmsplice: "This second notification tells the application that the memory associated with the send is safe to get reused." If I were writing the user code, I would very much want that notification to be an explicit part of the API instead of making a wild guess as I think I would need to do with vmsplice.
I agree, for the cache it's something important (not for the load generator). But IIRC that's something you can also check via SIOCOUTQ which is normally sufficient for a cache's eviction system (though not fantastic).
Willy
Quoted 98 lines · Willy Tarreau
Quoted 73 lines · Andy Lutomirski
Quoted 72 lines · Willy Tarreau
Quoted 40 lines · Andrew Morton
Quoted 25 lines · On Mon, 1 Jun 2026 16:04:55 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 10 lines · On Mon, 1 Jun 2026 18:33:25 +0100 Al Viro <[email protected]> wrote:
Quoted 2 lines · Linus Torvalds
TLDR: maybe we could ghet rid of "
f_op->splice_read". *That* would be a big simplification.FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...Quoted 4 lines
splice-related logics in
fs/fuse/dev.cis interesting; another place like this iskernel/trace/, but I'm less familiar with that one.rostedt Cc'd (miklos already had been)
Thanks for the Cc. The tracing ring buffer was specifically made to be used by splice and the libtracefs has a lot of code to use it as well. As reading the ring buffer literally swaps out the write portion with a blank read portion, that portion (sub-buffer) is used to be directly fed into splice, providing a zero-copy of the trace data from the write of the event to going into a file.
Quoted 5 lines
trace-cmd defaults to using splice to copy the tracing ring buffer directly into files to avoid as much copying during live recordings as possible.
Whatever changes we make, I would like to make sure there's no regressions in performance of trace-cmd record.
Well yes, The patchset seems sensible from a quality POV. But to make a decision we should first have a decent understanding of its downside impact.
I haven't seen a description of that impact in the discussion thus far. And that description is owed, please.
Quoted 8 lines
I assume a small number of specialized applications are using
vmsplice()to great effect? What are those applications? What is the impact of this change?Once we are armed with that information, is there some middle ground in which we de-feature
vmsplice()? Fall back to pread/pwrite in the tricky cases and still permit vmsplicing if the application is appropriately restrictive in it usage?I'm using
vmsplice()+tee()+splice()in high-performance applications, load generators to be precise, and soon a cache. This is super convenient and extremely efficient:-
vmsplice()is used to prepare a "master" pipe with data to be sent over TCP or kTLS
- then for each request, we dotee()from this master pipe to per-request pipes.
- the per-request pipes are those that are used to deliver the data to the socket viasplice().So we effectively use
vmsplice(),tee()andsplice()here, and for exactly the reasons they were designed: only play with page refcount and not copy data. The code is here for the curious:https://git.haproxy.org/?p=haproxy.git;a=blob;f=src/haterm.c
and its ancestor is here:
Quoted 7 lines
Quoted 4 lines
It simply doubles the network bandwidth compared to not using that. (62 Gbps per core vs 31). I would seriously miss it if I couldn't use this anymore.
Wait a moment. This is neat, but it's literally just a benchmark, right?
No, it's a benchmark *tool*: it's being used to stress production code, which is important and super hard at high loads. You place it after your proxy and you measure the performance of the proxy (which is supposed not to be as capable as the testing tools otherwise the methodology revolves to testing the testing tools, which is not the point).
Quoted 8 lines
I skimmed the code, and it doesn't look like a production workload, either. And you manage to get around the awfulness of the vmsplice API's complete failure to tell you when it's done with a buffer by ... never actually changing the contents of the buffer. Do you have any idea how you would write correct code that uses vmsplice for sends and then *ever* mutates the data without literally munmapping (or madvise or something) the data do you can safely mutate it?
Quoted 2 lines
I'm not sure what you mean here Andy. I *do not* need to change the data, it's just a pre-made pattern.
What I mean is: this particular pattern seems limited for use in an actual webserver as a opposed to a load-tester.
Quoted 10 lines
Quoted 3 lines
Or discover that we already have something better, perhaps :)
https://man7.org/linux/man-pages/man3/io_uring_prep_send_zc.3.html
io_uringis different. We tried it "the dirty way" in the past, by emulating a poller, and it's not worth it this way. And in order to do it the right way, it needs to be done totally differently, which has impacts all over the stack. The code in the file pointed to above is just for the httpterm testing feature, but the rest is much more complex.
I'm curious how this kludge does:
https://github.com/amluto/zc_bench
I vibe-coded this up without much care, and I don't have the hardware needed to actually run it in an interesting manner. But, on a Linux VM on an Apple M4, I can push about 130Gbps on a single core over loopback. In theory this will do zerocopy sends (but not over loopback), and I would hope that it runs *faster* than vmsplice + tee.
(I have a fancy workstation that can do a whopping 2.5Gbps. I could probably jury-rig a test over Thunderbolt at higher speeds. I have systems that are not available for this test right now that can do 10Gbps. But someone probably needs 40Gbps or better hardware for a genuinely interesting test.)
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Miklos Szeredi
maintainerQuoted 6 lines · Al Viro
Quoted 2 lines · Linus Torvalds
TLDR: maybe we could ghet rid of "
f_op->splice_read". *That* would be a big simplification.
Quoted 7 lines
FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...splice-related logics in
fs/fuse/dev.cis interesting; another place like this iskernel/trace/, but I'm less familiar with that one.
[Cc: Joanne, fuse-devel]
I'd favor simplification, but care is needed to not regress performance.
Joanne might be in a better position to say something about relative performance of various transport modes in fuse.
Thanks,
Miklos
Hi,
Quoted 8 lines · Al Viro
Quoted 2 lines · Linus Torvalds
TLDR: maybe we could ghet rid of "
f_op->splice_read". *That* would be a big simplification.FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...
speaking of fuse_dev_splice……_write actually, this series has broken xdg-document-portal!
https://github.com/flatpak/xdg-desktop-portal/issues/2026
Specifically what happens is that the EINVAL is returned due to oh.len != nbytes:
fuse_dev_do_write: oh.len 16400 != nbytes 15526
(where 16400 == 16384 (read len) + 16, 15526 == 15510 (file len) + 16)
After reverting the series, there is no error because oh.len becomes 15526 too.
Thanks,
~val
Quoted 21 lines · Val Packett
Hi,
Quoted 8 lines · Al Viro
Quoted 2 lines · Linus Torvalds
TLDR: maybe we could ghet rid of "
f_op->splice_read". *That* would be a big simplification.FUSE might be interesting -
fuse_dev_splice_read()and its ilk. Communications between the kernel and fuse server at least used to seriously want that, so that would be one place to look for unhappy userland...speaking of fuse_dev_splice……_write actually, this series has broken xdg-document-portal!
https://github.com/flatpak/xdg-desktop-portal/issues/2026
Specifically what happens is that the EINVAL is returned due to oh.len != nbytes:
Quoted 6 lines
fuse_dev_do_write: oh.len 16400 != nbytes 15526(where 16400 == 16384 (read len) + 16, 15526 == 15510 (file len) + 16)
After reverting the series, there is no error because oh.len becomes 15526 too.
I think this is because of how libfuse handles eof / short reads. When it detects a short read, it fixes up the header length after the header was already vmspliced to the pipe because it assumes vmsplice mapped the header's page into the pipe by reference. It assumes that modifying the header length in place gets then reflected in what the pipe later splices out.
The logic for this happens in fuse_send_data_iov() [1]:
a) sets out->len = headerlen (16) + len (16384) = 16400 in the stack-allocated fuse_out_header
b) vmsplices the header to the pipe
c) splices the backing file to the pipe. if this hits EOF, it'll get back 15510 instead of 16384
d) detects the short read [2], fixes up the stack out->len = 16 + 15510 = 15526
e) splices the pipe to /dev/fuse
After this patch, step b) is a straight copy which means step d)'s fixup doesn't modify what's in the pipe. This could be fixed up in libfuse to not depend on modify-after-vmsplice, but I don't think this helps for applications using already-released libfuse versions. I think this patch needs to be reverted.
Thanks,
Joanne
[1] https://github.com/libfuse/libfuse/blob/master/lib/fuse_lowlevel.c#L846
[2] https://github.com/libfuse/libfuse/blob/master/lib/fuse_lowlevel.c#L956
Quoted 5 lines
Thanks,
~val
Joanne Koong <[email protected]>:
Quoted 37 lines
Quoted 8 lines
speaking of fuse_dev_splice……_write actually, this series has broken xdg-document-portal!
https://github.com/flatpak/xdg-desktop-portal/issues/2026
Specifically what happens is that the EINVAL is returned due to oh.len != nbytes:
Quoted 6 lines
fuse_dev_do_write: oh.len 16400 != nbytes 15526(where 16400 == 16384 (read len) + 16, 15526 == 15510 (file len) + 16)
After reverting the series, there is no error because oh.len becomes 15526 too.
I think this is because of how libfuse handles eof / short reads. When it detects a short read, it fixes up the header length after the header was already vmspliced to the pipe because it assumes vmsplice mapped the header's page into the pipe by reference. It assumes that modifying the header length in place gets then reflected in what the pipe later splices out.
The logic for this happens in
fuse_send_data_iov()[1]:
a) setsout->len= headerlen (16) + len (16384) = 16400 in the stack-allocatedfuse_out_header
b) vmsplices the header to the pipe
c) splices the backing file to the pipe. if this hits EOF, it'll get back 15510 instead of 16384
d) detects the short read [2], fixes up the stackout->len= 16 + 15510 = 15526
e) splices the pipe to/dev/fuseAfter this patch, step b) is a straight copy which means step d)'s fixup doesn't modify what's in the pipe. This could be fixed up in libfuse to not depend on modify-after-vmsplice, but I don't think this helps for applications using already-released libfuse versions. I think this patch needs to be reverted.
Quoted 5 lines
Thanks,
Joanne[1] https://github.com/libfuse/libfuse/blob/master/lib/fuse_lowlevel.c#L846
[2] https://github.com/libfuse/libfuse/blob/master/lib/fuse_lowlevel.c#L956
Uh, this is very unfortunate. But I still want to remove vmsplice. Maybe we can somehow save my patchsets? For example, let's return EINVAL for this particular combination (writable pipe + SPLICE_F_NONBLOCK).
Signature · 1 line
Askar Safin
Quoted 42 lines · Askar Safin
Joanne Koong <[email protected]>:
Quoted 40 lines
Quoted 8 lines
speaking of fuse_dev_splice……_write actually, this series has broken xdg-document-portal!
https://github.com/flatpak/xdg-desktop-portal/issues/2026
Specifically what happens is that the EINVAL is returned due to oh.len != nbytes:
Quoted 6 lines
fuse_dev_do_write: oh.len 16400 != nbytes 15526(where 16400 == 16384 (read len) + 16, 15526 == 15510 (file len) + 16)
After reverting the series, there is no error because oh.len becomes 15526 too.
I think this is because of how libfuse handles eof / short reads. When it detects a short read, it fixes up the header length after the header was already vmspliced to the pipe because it assumes vmsplice mapped the header's page into the pipe by reference. It assumes that modifying the header length in place gets then reflected in what the pipe later splices out.
The logic for this happens in
fuse_send_data_iov()[1]:
a) setsout->len= headerlen (16) + len (16384) = 16400 in the stack-allocatedfuse_out_header
b) vmsplices the header to the pipe
c) splices the backing file to the pipe. if this hits EOF, it'll get back 15510 instead of 16384
d) detects the short read [2], fixes up the stackout->len= 16 + 15510 = 15526
e) splices the pipe to/dev/fuseAfter this patch, step b) is a straight copy which means step d)'s fixup doesn't modify what's in the pipe. This could be fixed up in libfuse to not depend on modify-after-vmsplice, but I don't think this helps for applications using already-released libfuse versions. I think this patch needs to be reverted.
Thanks,
Joanne
Quoted 6 lines
Quoted 2 lines
[1] https://github.com/libfuse/libfuse/blob/master/lib/fuse_lowlevel.c#L846
[2] https://github.com/libfuse/libfuse/blob/master/lib/fuse_lowlevel.c#L956Uh, this is very unfortunate. But I still want to remove vmsplice. Maybe we can somehow save my patchsets? For example, let's return EINVAL for this particular combination (writable pipe +
SPLICE_F_NONBLOCK).
writable pipe + SPLICE_F_NONBLOCK is a valid vmsplice call today, so I think returning -EINVAL would still cause regressions. It happens to be a workaround for libfuse only because libfuse falls back to writev() when vmsplice fails, but I don't think we can assume other callers have the same fallback.
Thanks,
Joanne
Quoted 3 lines
--
Askar Safin
David Hildenbrand (Arm)
maintainerQuoted 32 lines · Joanne Koong
Quoted 31 lines · Askar Safin
Joanne Koong <[email protected]>:
Quoted 28 lines
I think this is because of how libfuse handles eof / short reads. When it detects a short read, it fixes up the header length after the header was already vmspliced to the pipe because it assumes vmsplice mapped the header's page into the pipe by reference. It assumes that modifying the header length in place gets then reflected in what the pipe later splices out.
The logic for this happens in
fuse_send_data_iov()[1]:
a) setsout->len= headerlen (16) + len (16384) = 16400 in the stack-allocatedfuse_out_header
b) vmsplices the header to the pipe
c) splices the backing file to the pipe. if this hits EOF, it'll get back 15510 instead of 16384
d) detects the short read [2], fixes up the stackout->len= 16 + 15510 = 15526
e) splices the pipe to/dev/fuseAfter this patch, step b) is a straight copy which means step d)'s fixup doesn't modify what's in the pipe. This could be fixed up in libfuse to not depend on modify-after-vmsplice, but I don't think this helps for applications using already-released libfuse versions. I think this patch needs to be reverted.
Thanks,
Joanne[1] https://github.com/libfuse/libfuse/blob/master/lib/fuse_lowlevel.c#L846
[2] https://github.com/libfuse/libfuse/blob/master/lib/fuse_lowlevel.c#L956
Quoted 6 lines
Quoted 3 lines
Uh, this is very unfortunate. But I still want to remove vmsplice. Maybe we can somehow save my patchsets? For example, let's return EINVAL for this particular combination (writable pipe +
SPLICE_F_NONBLOCK).writable pipe +
SPLICE_F_NONBLOCKis a valid vmsplice call today, so I think returning-EINVALwould still cause regressions.
I recall that, after the vmsplice vs. fork security issue happened, vmsplice was blocked in some container runtimes. e.g., [1] still seems to disable it, added in 2021 [2].
So maybe one could at least assume that many containerized workloads should be able to deal with vmsplice not being available nowadays. But in the general case I'm afraid Joanne is right.
[1] https://github.com/containers/common/blob/main/pkg/seccomp/seccomp.json
[2]
https://github.com/containers/common/commit/7ced5daafa0e36102eb931050ba3ff99f42bdfac
Signature · 3 lines
Cheers, David
Christian Brauner
maintainerQuoted 5 lines
After this patch, step b) is a straight copy which means step d)'s fixup doesn't modify what's in the pipe. This could be fixed up in libfuse to not depend on modify-after-vmsplice, but I don't think this helps for applications using already-released libfuse versions. I think this patch needs to be reverted.
Note, nothing was merged. I deliberately kept in -next though for a long time to see how quickly we'd see regressions.
Quoted 9 lines · Christian Brauner
Quoted 6 lines
After this patch, step b) is a straight copy which means step d)'s fixup doesn't modify what's in the pipe. This could be fixed up in libfuse to not depend on modify-after-vmsplice, but I don't think this helps for applications using already-released libfuse versions. I think this patch needs to be reverted.
Note, nothing was merged. I deliberately kept in -next though for a long time to see how quickly we'd see regressions.
The bait worked. CRIU wins a prize in this lottery.
The CRIU fifo test fails with this change. The problem is that vmsplice with SPLICE_F_NONBLOCK to a fifo file descriptor fails with -EOPNOTSUPP.
It seems we need a fix like this one:
fs/pipe.c +0 -0
@@ -1253,6 +1253,7 @@ static int fifo_open(struct inode *inode, struct
file *filp)
/* We can only do regular read/write on fifos */
stream_open(inode, filp);+ filp->f_mode |= FMODE_NOWAIT;
switch (filp->f_mode & (FMODE_READ | FMODE_WRITE)) {
case FMODE_READ:Quoted 9 lines · Andrei Vagin
Quoted 7 lines · Christian Brauner
Quoted 6 lines
After this patch, step b) is a straight copy which means step d)'s fixup doesn't modify what's in the pipe. This could be fixed up in libfuse to not depend on modify-after-vmsplice, but I don't think this helps for applications using already-released libfuse versions. I think this patch needs to be reverted.
Quoted 7 lines
Quoted 2 lines
Note, nothing was merged. I deliberately kept in -next though for a long time to see how quickly we'd see regressions.
The bait worked. CRIU wins a prize in this lottery.
The CRIU fifo test fails with this change. The problem is that vmsplice with
SPLICE_F_NONBLOCKto a fifo file descriptor fails with-EOPNOTSUPP.
Actually, this change introduces a performance and functional regression for CRIU.
Here is a brief overview of how CRIU currently dumps memory pages:
CRIU injects a parasite code blob into the target process's address space. The parasite invokes vmsplice() with the SPLICE_F_GIFT flag to pin physical pages directly inside a pipe without copying them. The main CRIU process then takes over from outside the target context, calling splice() on the other end of the pipe to stream the data directly into checkpoint image files or a remote network socket.
I ran a simple test that creates an anonymous mapping and touches every page within it:
Without this patch, CRIU takes 9 seconds to dump the test process. With this patch, It takes 18 seconds...
Plus, it obviously introduces some memory overhead.
If these changes are merged, we will need to completely rework the memory dumping mechanism in CRIU. Using vmsplice() in this proposed form no longer makes any sense for our architecture...
Thanks,
Andrei
Andrei Vagin <[email protected]>:
Quoted 17 lines
Actually, this change introduces a performance and functional regression for CRIU.
Here is a brief overview of how CRIU currently dumps memory pages:
CRIU injects a parasite code blob into the target process's address space. The parasite invokes
vmsplice()with theSPLICE_F_GIFTflag to pin physical pages directly inside a pipe without copying them. The main CRIU process then takes over from outside the target context, callingsplice()on the other end of the pipe to stream the data directly into checkpoint image files or a remote network socket.I ran a simple test that creates an anonymous mapping and touches every page within it:
Without this patch, CRIU takes 9 seconds to dump the test process. With this patch, It takes 18 seconds...
Quoted 5 lines
Plus, it obviously introduces some memory overhead.
If these changes are merged, we will need to completely rework the memory dumping mechanism in CRIU. Using
vmsplice()in this proposed form no longer makes any sense for our architecture...
I just have read some docs for CRIU. I found this statement:
Quoted 2 lines
#### Why
spliceis Better:
* **Consistency via COW**: TheSPLICE_F_GIFTflag ensures that if the process modifies a "gifted" page after resuming, the kernel performs a **Copy-on-Write (COW)**. The pipe buffer > continues to hold the *original* version of the page as it existed at the moment of thevmsplice()call, ensuring a perfectly consistent snapshot of that page.
This is wrong (with released kernels). I confirmed this by testing this on my current kernel (6.12.90).
See the code in the end of this message.
If you actually rely on mentioned consistency, then, it seems, CRIU is broken.
So, in fact, my patch actually brings consistency to CRIU. :)
Signature · 40 lines
Askar Safin
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <errno.h>
int
main (void)
{
int p[2];
if (pipe (p) != 0)
abort ();
char buf[1] = {'a'};
struct iovec iov[] = {
{
.iov_base = buf,
.iov_len = 1,
}
};
// I pass "SPLICE_F_NONBLOCK | SPLICE_F_GIFT" here, because this is what criu passes
if (vmsplice (p[1], iov, 1, SPLICE_F_NONBLOCK | SPLICE_F_GIFT) != 1)
abort ();
if (close (p[1]) != 0)
abort ();
buf[0] = 'b';
char buf2[1];
if (read (p[0], buf2, 1) != 1)
abort ();
printf ("[%c]\n", buf2[0]); // Prints "b" as opposed to "a" on Linux 6.12.90
return 0;
}Quoted 30 lines · Askar Safin
Andrei Vagin <[email protected]>:
Quoted 17 lines
Actually, this change introduces a performance and functional regression for CRIU.
Here is a brief overview of how CRIU currently dumps memory pages:
CRIU injects a parasite code blob into the target process's address space. The parasite invokes
vmsplice()with theSPLICE_F_GIFTflag to pin physical pages directly inside a pipe without copying them. The main CRIU process then takes over from outside the target context, callingsplice()on the other end of the pipe to stream the data directly into checkpoint image files or a remote network socket.I ran a simple test that creates an anonymous mapping and touches every page within it:
Without this patch, CRIU takes 9 seconds to dump the test process. With this patch, It takes 18 seconds...Quoted 5 lines
Plus, it obviously introduces some memory overhead.
If these changes are merged, we will need to completely rework the memory dumping mechanism in CRIU. Using
vmsplice()in this proposed form no longer makes any sense for our architecture...I just have read some docs for CRIU. I found this statement:
Quoted 2 lines
#### Why
spliceis Better:
* **Consistency via COW**: TheSPLICE_F_GIFTflag ensures that if the process modifies a "gifted" page after resuming, the kernel performs a **Copy-on-Write (COW)**. The pipe buffer > continues to hold the *original* version of the page as it existed at the moment of thevmsplice()call, ensuring a perfectly consistent snapshot of that page.
Quoted 7 lines
This is wrong (with released kernels). I confirmed this by testing this on my current kernel (6.12.90).
See the code in the end of this message.
If you actually rely on mentioned consistency, then, it seems, CRIU is broken.
So, in fact, my patch actually brings consistency to CRIU. :)
Askar, unfortunately, the statement about "Consistency via COW" is just "AI imagination". The under-the-hood docs were recently transferred from the criu.org wiki using some AI transformations, which introduced this wrong statement. The original document can be found here:
https://criu.org/Memory_dumping_and_restoring.
To clarify, CRIU does not rely on page consistency for intermediate pre-dumps. The pre-dump mechanism is designed to be iterative: During a pre-dump, tasks are briefly frozen to vmsplice dirty pages into pipes. Then the tasks are resumed, and CRIU drains the pipes. If the process modifies a page after it has been spliced, the data in the pipe may become inconsistent. However, any such modification is tracked by the soft-dirty page tracker. In the next pre-dump iteration (or the final dump), these modified pages will be identified as dirty again and re-dumped. During restore, the images are applied sequentially, and the final dump (taken while the process is fully frozen) ensures we reconstruct a consistent final state.
But what really matters in this scheme is the vmsplice performance. The proposed change significantly slows it down. In the case of CRIU, vmsplice performance is critical because the target process is frozen during these calls. Minimizing the freeze time is the primary goal of pre-dumping to make migration almost invisible to the user workload.
Thanks,
Andrei
Andrei Vagin <[email protected]>:
Quoted 17 lines
The CRIU fifo test fails with this change. The problem is that vmsplice with
SPLICE_F_NONBLOCKto a fifo file descriptor fails with-EOPNOTSUPP.It seems we need a fix like this one:
fs/pipe.c +1
-0@@ -1253,6 +1253,7 @@ static int fifo_open(struct inode *inode, struct file *filp)/* We can only do regular read/write on fifos */ stream_open (inode ,filp ); + filp->f_mode |=FMODE_NOWAIT ;switch (filp->f_mode & (FMODE_READ |FMODE_WRITE )) {
Quoted 1 line
case
FMODE_READ:
Does CRIU actually rely on ability to do SPLICE_F_NONBLOCK vmsplice into named fifos? Or this is merely a test?
If this is just a test, I think we need not to preserve this behavior.
I did debian code search with regex "vmsplice.*SPLICE_F_NONBLOCK" and I found very few packages. And it seems all them use pipes, not named fifos.
(On speed: I still think that my vmsplice patches are good thing, despite performance regressions in CRIU.)
Signature · 1 line
Askar Safin
Quoted 18 lines · Askar Safin
Andrei Vagin <[email protected]>:
Quoted 16 lines
The CRIU fifo test fails with this change. The problem is that vmsplice with
SPLICE_F_NONBLOCKto a fifo file descriptor fails with-EOPNOTSUPP.It seems we need a fix like this one:
fs/pipe.c +1
-0@@ -1253,6 +1253,7 @@ static int fifo_open(struct inode *inode, struct file *filp)/* We can only do regular read/write on fifos */ stream_open (inode ,filp ); + filp->f_mode |=FMODE_NOWAIT ;
Quoted 5 lines
Quoted 2 lines
fs/pipe.c +0
-0switch (filp->f_mode & (FMODE_READ |FMODE_WRITE )) {case
FMODE_READ:Does CRIU actually rely on ability to do
SPLICE_F_NONBLOCKvmsplice into named fifos? Or this is merely a test?
Yes, it does.
Quoted 5 lines
If this is just a test, I think we need not to preserve this behavior.
I did debian code search with regex "vmsplice.*SPLICE_F_NONBLOCK" and I found very few packages. And it seems all them use pipes, not named fifos.
In short, this isn't how such cases are handled in the kernel. The fix is simple and should be applied to avoid breaking random software.
Quoted 3 lines
(On speed: I still think that my vmsplice patches are good thing, despite performance regressions in CRIU.)
I already explained that this isn't just a perfomance degradation, it actually breaks the pre-dump mechanism in CRIU. vmsplice is invoked from our parasite code within the context of a user process, where execution speed is critical. A heavy performance penalty completely invalidates the pre-dump logic, making the feature useless.
Under normal circumstances, patches that cause this kind of breakage would never be merged. However, since there are exceptions to every rule, we should let the maintainers decide how to proceed here. In CRIU, we have a backup plan to utilize process_vm_readv to dump process memory. We already support this mode, but it isn't the default due to performance concerns. If these patches are merged, it will be the only option left for CRIU to implement pre-dumping.
However, we need to look at this case in a broader context. This is yet another example where the change introduces a workflow breakage, meaning there might be other workloads out there that could be broken by this change.
At a minimum, we may need to consider a deprecation plan where vmsplice with SPLICE_F_GIFT triggers a warning for a few releases before these changes are applied. Alternatively, we could introduce the proposed behavior alongside a sysctl to fall back to the old behavior and explicitly state that this fallback path will be completely deprecated in a future kernel version.
Thanks,
Andrei
Andrei Vagin <[email protected]>:
Quoted 5 lines · Askar Safin
Quoted 2 lines
Does CRIU actually rely on ability to do
SPLICE_F_NONBLOCKvmsplice into named fifos? Or this is merely a test?Yes, it does.
I. e. CRIU relies on that named fifo behavior? Okay, I just sent v2 version of my fixes. The patchset contains fix for named fifos.
Please, test that this fixes that named fifo problem.
Quoted 5 lines
I already explained that this isn't just a perfomance degradation, it actually breaks the pre-dump mechanism in CRIU. vmsplice is invoked from our parasite code within the context of a user process, where execution speed is critical. A heavy performance penalty completely invalidates the pre-dump logic, making the feature useless.
This is very unfortunate. But I still want to remove vmsplice.
Quoted 6 lines
At a minimum, we may need to consider a deprecation plan where vmsplice with
SPLICE_F_GIFTtriggers a warning for a few releases before these changes are applied. Alternatively, we could introduce the proposed behavior alongside a sysctl to fall back to the old behavior and explicitly state that this fallback path will be completely deprecated in a future kernel version.
My patches change not only SPLICE_F_GIFT behavior, but also vmsplice behavior in general.
Let other developers decide what to do (i. e. do nothing, remove vmsplice now or implement some deprecation scheme).
Signature · 1 line
Askar Safin
Val Packett <[email protected]>:
Quoted 8 lines
speaking of fuse_dev_splice……_write actually, this series has broken xdg-document-portal!
https://github.com/flatpak/xdg-desktop-portal/issues/2026
Specifically what happens is that the EINVAL is returned due to oh.len != nbytes:
Quoted 6 lines
fuse_dev_do_write: oh.len 16400 != nbytes 15526(where 16400 == 16384 (read len) + 16, 15526 == 15510 (file len) + 16)
After reverting the series, there is no error because oh.len becomes 15526 too.
Please, test v2 version of my fixes:
https://lore.kernel.org/lkml/[email protected]/ .
This should fix this bug.
Signature · 1 line
Askar Safin
Hi all,
Quoted 25 lines · Christian Brauner
Quoted 8 lines · Askar Safin
This patchset is for VFS.
Recently we got a lot of vulnerabilities in splice/vmsplice.
Also vmsplice already was source of vulnerabilities in the past:
CVE-2020-29374 (see https://lwn.net/Articles/849638/ ).[...]
Applied to the vfs-7.2.vmsplice branch of the vfs/vfs.git tree. Patches in the vfs-7.2.vmsplice branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.2.vmsplice
Quoted 6 lines
[1/3] tee:
fs/splice.c: remove unused parameter "flags" from "link_pipe"https://git.kernel.org/vfs/vfs/c/a9f7db50ed2f [2/3] vmsplice: make vmsplice a trivial wrapper for preadv2/pwritev2 https://git.kernel.org/vfs/vfs/c/e2c0b2368081 [3/3] splice: remove PIPE_BUF_FLAG_GIFT https://git.kernel.org/vfs/vfs/c/7d75aa8edfce
In GNU coreutils-9.11, released 2026-04-20, Pádraig Brady added the use of splice and vmsplice to the 'yes' command [1]. Afterward, I added the use of splice to the 'cat' command, which is now used if copy_file_range fails or cannot be used [2]. There were some minor adjustments that had to be made to those patches pre-release. However, as far as I am aware, they have not had any issues yet which was a bit surprising to me at least. Now it seems we are a bit unlucky with our timing...
Anyways, I figured you may be interested in seeing how these changes affect some applications. I built a kernel from the vfs-7.2.vmsplice branch and used a config based on my recent Fedora kernel.
Here is the throughput on my Fedora kernel:
$ uname -r
7.0.10-201.fc44.x86_64
$ yes --version | head -n 1
yes (GNU coreutils) 9.11.50-157bd
$ timeout 1m taskset 1 yes | taskset 2 pv -r > /dev/null
[36.9GiB/s]
$ cat --version | head -n 1
cat (GNU coreutils) 9.11.50-157bd
$ timeout 1m taskset 1 cat /dev/zero | taskset 2 pv -r > /dev/null
[9.34GiB/s]Here is the throughput on the vfs-7.2.vmsplice kernel:
$ uname -r
7.1.0-rc1+
$ yes --version | head -n 1
yes (GNU coreutils) 9.11.50-157bd
$ timeout 1m taskset 1 yes | taskset 2 pv -r > /dev/null
[3.41GiB/s]
$ cat --version | head -n 1
cat (GNU coreutils) 9.11.50-157bd
$ timeout 1m taskset 1 cat /dev/zero | taskset 2 pv -r > /dev/null
[9.50GiB/s]Unsurprisingly, 'cat' is not affected since it does not use vmsplice. On the other hand 'yes' is 10x slower. I dislike this, obviously. However, of course I realize that the average person uses the 'yes' command much less frequently than I do, if they use it at all. To them security is a far greater concern. Just want to make it clear that this message isn't an attempt at getting this change reverted or anything like that.
Anyways, hope the testing was at least somewhat useful.
Collin
[1] https://github.com/coreutils/coreutils/commit/2b1c059e6a06eebbb721d010b1221ec54200cc33
[2] https://github.com/coreutils/coreutils/commit/457f88513a128ce91160c4a60f821cc1612204be
P.S. It would be fun to test this branch on the machine where we got 'yes' to output at 175GiB/s. Sadly we do not have root access on it to install a new kernel, though.
Askar Safin <[email protected]>:
Quoted 2 lines
For all these reasons I propose to make vmsplice a simple wrapper for preadv2/pwritev2.
This patchset is already in next, but I still kindly ask people to carefully review it. I'm still a new contributor, and I can make mistakes.
For example, in vmsplice I do "CLASS(fd, f)(fd)" and then I pass "fd" (i. e. integer) to "do_writev/do_readv". I don't know whether this is okay to do so.
Signature · 1 line
Askar Safin
Quoted 4 lines · Askar Safin
For example, in vmsplice I do "
CLASS(fd, f)(fd)" and then I pass "fd" (i. e. integer) to "do_writev/do_readv". I don't know whether this is okay to do so.
Oh, good point.
It's ok in the sense that it will work, and it's not really going to cause problems, but it does mean that the 'struct file' will be looked up twice.
And *technically* it's a TOCTOU race, where the first time you look it up - in the vmsplice() wrapper - it could be one file, and you make decisions based on that. And then pass it off to do_writev(), and it will look it up again, and now it might be a different file.
Does it *matter*? No. Even if the file changed, and is now something else, it's just going to be a different file that the user does writev() on. do_writev() will still do all the appropriate safety checks etc, so it doesn't really change anything. It just means that you could pass what you *think* is a pipe (because you did that
+ if (!get_pipe_info(fd_file(f), /* for_splice = */ false))
+ return -EBADF;
and by the time do_writev() then looks up the fd again it might be something else, and now the user used vmsplice() as a really odd way to write to a another non-pipe file instead. But the user could have done that with a regular writev(), so it's just the user being silly - not something that really confuses the kernel.
Coimpletely harmless, in other words.
But it would probably be *cleaner* to pass in the 'struct file *' pointer that you already looked up once instead, and use vfs_writev() instead of do_writev().
And I do suspect that the wrapper system call should use the same
SYSCALL_DEFINE4(vmsplice, int, fd, ..
that the original used. Because it somebody crazy had the high bits set in 'fd', the old vmsplice() system call didn't care, but your new emulation system call will actually see the high bits on a 64-bit architecture.
Again - that doesn't actually *matter*, because "CLASS(fd)" takes an "int fd" and those high bits will be masked out at use time both in vmsplice() and in do_readv/writev().
So it won't affect any behavior, but it does look a bit odd in the conversion.
And I already answered Christian wrt the change in behavior: I think RWF_NOWAIT should always be set on the writing side - because splice() never waited after it filled a pipe - and instead that SPLICE_F_NONBLOCK flag should be used before write to check for whether we'll wait *before* doing the write like it used to do with
ret = wait_for_space(pipe, flags);
in vmsplice_to_pipe().
(On the other side, vmsplice_from_pipe() used to do pipe_clear_nowait(), but I think that becomes a non-issue with the conversion to readv()).
And once you need wait_for_space(), that probably means that the new vmsplice() wrapper simpler needs to remain inside fs/splice.c, and we just need to make vfs_readv/vfs_writev non-static.
Linus