Skip to contentSkip to conversation

sys_vmsplice

PATCH In review Jens Axboe 5 participants 11 messages Apr 21, 2006

Subsystems (6)
lore
Share & tools
lore

Jens Axboe

author
#0 lore raw

PATCH 1/1 sys_vmsplice

Hi,

Here's the first implementation of sys_vmsplice(). I'm attaching a little test app as well for playing with it, it's also committed to the splice tools repo at:

git://brick.kernel.dk/data/git/splice.git

Patch is against current Linus -git, it's also included in the splice branch of the block git repo.

-----

sys_splice() moves data to/from pipes with a file input/output. sys_vmsplice() moves data to a pipe, with the input being a user address range instead.

---

 arch/ia64/kernel/entry.S     |    1 
 arch/powerpc/kernel/systbl.S |    1 
 fs/fcntl.c                   |    8 ++
 fs/splice.c                  |  181 +++++++++++++++++++++++++++++++++++-------
 include/asm-generic/fcntl.h  |    5 +
 include/asm-i386/unistd.h    |    3 -
 include/asm-ia64/unistd.h    |    1 
 include/asm-powerpc/unistd.h |    3 -
 include/asm-x86_64/unistd.h  |    4 +
 include/linux/syscalls.h     |    3 +
 10 files changed, 176 insertions(+), 34 deletions(-)

888642ed2f315862a4cc815c1a9029a328adbd33

arch/ia64/kernel/entry.S +1 -0
index e307988..bcb80ca 100644
@@ -1610,5 +1610,6 @@ sys_call_table:
 	data8 sys_get_robust_list
 	data8 sys_sync_file_range		// 1300
 	data8 sys_tee
+	data8 sys_vmsplice
 
 	.org sys_call_table + 8*NR_syscalls	// guard against failures to increase NR_syscalls
arch/powerpc/kernel/systbl.S +1 -0
index a14c964..9730315 100644
@@ -324,3 +324,4 @@ COMPAT_SYS(ppoll)
 SYSCALL(unshare)
 SYSCALL(splice)
 SYSCALL(tee)
+SYSCALL(vmsplice)
fs/fcntl.c +8 -0
index d35cbc6..56ac96e 100644
@@ -18,6 +18,7 @@ #include <linux/security.h>
 #include <linux/ptrace.h>
 #include <linux/signal.h>
 #include <linux/rcupdate.h>
+#include <linux/pipe_fs_i.h>
 
 #include <asm/poll.h>
 #include <asm/siginfo.h>
@@ -345,6 +346,13 @@ static long do_fcntl(int fd, unsigned in
 	case F_NOTIFY:
 		err = fcntl_dirnotify(fd, filp, arg);
 		break;
+	case F_SETPSZ:
+		err = -EINVAL;
+		break;
+	case F_GETPSZ:
+		/* this assumes user space can reliably tell PAGE_CACHE_SIZE */
+		err = PIPE_BUFFERS;
+		break;
 	default:
 		break;
 	}
fs/splice.c +150 -31

281 lines not on this page · raw message

include/asm-generic/fcntl.h +5 -0
index b663520..1da0fba 100644
@@ -146,4 +146,9 @@ struct flock64 {
 #endif
 #endif /* !CONFIG_64BIT */
 
+#ifndef F_SETPSZ
+#define F_SETPSZ	15	/* for pipes. */
+#define F_GETPSZ	16	/* for pipes. */
+#endif
+
 #endif /* _ASM_GENERIC_FCNTL_H */
include/asm-i386/unistd.h +2 -1
index d81d6cf..eb4b152 100644
@@ -321,8 +321,9 @@ #define __NR_get_robust_list	312
 #define __NR_splice		313
 #define __NR_sync_file_range	314
 #define __NR_tee		315
+#define __NR_vmsplice		316
 
-#define NR_syscalls 316
+#define NR_syscalls 317
 
 /*
  * user-visible error numbers are in the range -1 - -128: see
include/asm-ia64/unistd.h +1 -0
index a40ebec..9aa3487 100644
@@ -290,6 +290,7 @@ #define __NR_set_robust_list		1298
 #define __NR_get_robust_list		1299
 #define __NR_sync_file_range		1300
 #define __NR_tee			1301
+#define __NR_vmsplice			1302
 
 #ifdef __KERNEL__
 
include/asm-powerpc/unistd.h +2 -1
index c612f1a..34325e2 100644
@@ -303,8 +303,9 @@ #define __NR_ppoll		281
 #define __NR_unshare		282
 #define __NR_splice		283
 #define __NR_tee		284
+#define __NR_vmsplice		285
 
-#define __NR_syscalls		285
+#define __NR_syscalls		286
 
 #ifdef __KERNEL__
 #define __NR__exit __NR_exit
include/asm-x86_64/unistd.h +3 -1
index 98c36ea..feb77cb 100644
@@ -615,8 +615,10 @@ #define __NR_tee		276
 __SYSCALL(__NR_tee, sys_tee)
 #define __NR_sync_file_range	277
 __SYSCALL(__NR_sync_file_range, sys_sync_file_range)
+#define __NR_vmsplice		278
+__SYSCALL(__NR_vmsplice, sys_vmsplice)
 
-#define __NR_syscall_max __NR_sync_file_range
+#define __NR_syscall_max __NR_vmsplice
 
 #ifndef __NO_STUBS
 
include/linux/syscalls.h +3 -0
index d3ebc0e..fc9392c 100644
@@ -574,6 +574,9 @@ asmlinkage long sys_splice(int fd_in, lo
 			   int fd_out, loff_t __user *off_out,
 			   size_t len, unsigned int flags);
 
+asmlinkage long sys_vmsplice(int fd, void __user *buffer, size_t len,
+			     unsigned int flags);
+
 asmlinkage long sys_tee(int fdin, int fdout, size_t len, unsigned int flags);
 
 asmlinkage long sys_sync_file_range(int fd, loff_t offset, loff_t nbytes,
Signature · 5 lines
1.3.0.g2473


-- 
Jens Axboe

/*
* Use vmsplice to fill some user memory into a pipe. vmsplice writes
* to stdout, so that must be a pipe.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/poll.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "splice.h"

#define ALIGN_BUF

#ifdef ALIGN_BUF
#define ALIGN_MASK (65535) /* 64k-1, should just be PAGE_SIZE - 1 */
#define ALIGN(buf) (void *) (((unsigned long) (buf) + ALIGN_MASK) & ~ALIGN_MASK)
#else
#define ALIGN_MASK (0)
#define ALIGN(buf) (buf)
#endif

int do_vmsplice(int fd, void *buffer, int len)

{
	struct pollfd pfd = { .fd = fd, .events = POLLOUT, };
	int written;

	while (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)
			return error("poll");

		written = vmsplice(fd, buffer, min(SPLICE_SIZE, len), 0);

		if (written <= 0)
			return error("vmsplice");

		len -= written;
	}

	return 0;
}

int main(int argc, char *argv[])

{
	unsigned char *buffer;
	struct stat sb;
	long page_size;
	int i, ret;

	if (fstat(STDOUT_FILENO, &sb) < 0)
		return error("stat");
	if (!S_ISFIFO(sb.st_mode)) {
		fprintf(stderr, "stdout must be a pipe\n");
		return 1;
	}

	ret = fcntl(STDOUT_FILENO, F_GETPSZ);
	if (ret < 0)
		return error("F_GETPSZ");

	page_size = sysconf(_SC_PAGESIZE);
	if (page_size < 0)
		return error("_SC_PAGESIZE");

	fprintf(stderr, "Pipe size: %d pages / %ld bytes\n", ret, ret * page_size);

	buffer = ALIGN(malloc(2 * SPLICE_SIZE + ALIGN_MASK));
	for (i = 0; i < 2 * SPLICE_SIZE; i++)
		buffer[i] = (i & 0xff);

	do {
		/*
		 * vmsplice the first half of the buffer into the pipe
		 */
		if (do_vmsplice(STDOUT_FILENO, buffer, SPLICE_SIZE))
			break;

		/*
		 * first half is now in pipe, but we don't quite know when
		 * we can reuse it.
		 */

		/*
		 * vmsplice second half
		 */
		if (do_vmsplice(STDOUT_FILENO, buffer + SPLICE_SIZE, SPLICE_SIZE))
			break;

		/*
		 * We still don't know when we can reuse the second half of
		 * the buffer, but we do now know that all parts of the first
		 * half have been consumed from the pipe - so we can reuse that.
		 */
	} while (0);

	return 0;
}
#1 lore raw
Quoted 10 lines · Jens Axboe

...

sys_splice() moves data to/from pipes with a file input/output. sys_vmsplice() moves data to a pipe, with the input being a user address range instead.

...

fs/splice.c +2 -0
+static void *user_page_pipe_buf_map(struct file *file,
+				    struct pipe_inode_info *pipe,

fs/splice.c static void page_cache_pipe_buf_unmap(st · line 154

Quoted 10 lines
fs/splice.c +10 -0
+				    struct pipe_buffer *buf)
+{
+	return kmap(buf->page);
+}
+
+static void user_page_pipe_buf_unmap(struct pipe_inode_info *pipe,
+				     struct pipe_buffer *buf)
+{
+	kunmap(buf->page);
+}

All these new kmaps and kunmaps hurt. It's supposed to be kinda-deprecated and scales poorly. Oh well.

fs/splice.c static ssize_t move_to_pipe(struct pipe_ · line 277

Quoted 4 lines
fs/splice.c +2 -2
-	while (i < nr_pages)
-		page_cache_release(pages[i++]);
+	while (i < spd->nr_pages)
+		page_cache_release(spd->pages[i++]);

grumble. I'm going to march over there and take away your `i' key. Or make it emit "page_nr".

Quoted 10 lines
fs/splice.c +10 -0
+static long do_vmsplice(struct file *file, void __user *buffer, size_t len,
+			unsigned int flags)
+{
+	unsigned long uaddr = (unsigned long) buffer;
+	struct pipe_inode_info *pipe;
+	struct page *pages[PIPE_BUFFERS];
+	unsigned int nr_pages;
+	struct splice_pipe_desc spd = {
+		.pages = pages,
+		.len = len,

fs/splice.c static long do_splice(struct file *in, l · line 1094

Quoted 10 lines
fs/splice.c +10 -0
+		.flags = flags,
+		.ops = &user_page_pipe_buf_ops,
+	};
+
+	pipe = file->f_dentry->d_inode->i_pipe;
+	if (unlikely(!pipe))
+		return -EBADF;
+
+	spd.offset = uaddr & ~PAGE_CACHE_MASK;
+	nr_pages = (len + spd.offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;

Can I feed this 16TB of memory? If so, we just overflowed `nr_pages'.

include/asm-powerpc/unistd.h #define __NR_ppoll 281 · line 309

Quoted 11 lines
include/asm-powerpc/unistd.h +2 -1
@@ -303,8 +303,9 @@ #define __NR_ppoll		281
 #define __NR_unshare		282
 #define __NR_splice		283
 #define __NR_tee		284
+#define __NR_vmsplice		285
 
-#define __NR_syscalls		285
+#define __NR_syscalls		286
 

Every time we do this the spufs build breaks:

long spu_sys_callback(struct spu_syscall_block *s)

{
	long (*syscall)(u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 a6);

	BUILD_BUG_ON(ARRAY_SIZE(spu_syscall_table) != __NR_syscalls);
author
#2 lore raw
Quoted 9 lines · Andrew Morton
Quoted 8 lines · Jens Axboe

...

sys_splice() moves data to/from pipes with a file input/output. sys_vmsplice() moves data to a pipe, with the input being a user address range instead.

...

Quoted 15 lines

fs/splice.c static void page_cache_pipe_buf_unmap(st · line 154

Quoted 12 lines
fs/splice.c +12 -0
+static void *user_page_pipe_buf_map(struct file *file,
+				    struct pipe_inode_info *pipe,
+				    struct pipe_buffer *buf)
+{
+	return kmap(buf->page);
+}
+
+static void user_page_pipe_buf_unmap(struct pipe_inode_info *pipe,
+				     struct pipe_buffer *buf)
+{
+	kunmap(buf->page);
+}

All these new kmaps and kunmaps hurt. It's supposed to be kinda-deprecated and scales poorly. Oh well.

I know, it's not a new complaint and I fully agree. It's not too bad to fix, it just needs 1/2 new pipe_buffer_ops hooks to split the mapping from the 'checking' part. For now we blissfully ignore highmem boxes and rejoice on 64-bit machines :-)

Quoted 7 lines

fs/splice.c static ssize_t move_to_pipe(struct pipe_ · line 277

Quoted 4 lines
fs/splice.c +2 -2
-	while (i < nr_pages)
-		page_cache_release(pages[i++]);
+	while (i < spd->nr_pages)
+		page_cache_release(spd->pages[i++]);

grumble. I'm going to march over there and take away your `i' key. Or make it emit "page_nr".

;-)

Quoted 14 lines
Quoted 14 lines
fs/splice.c +14 -0
+static long do_vmsplice(struct file *file, void __user *buffer, size_t len,
+			unsigned int flags)
+{
+	unsigned long uaddr = (unsigned long) buffer;
+	struct pipe_inode_info *pipe;
+	struct page *pages[PIPE_BUFFERS];
+	unsigned int nr_pages;
+	struct splice_pipe_desc spd = {
+		.pages = pages,
+		.len = len,
+		.flags = flags,
+		.ops = &user_page_pipe_buf_ops,
+	};
+
Quoted 8 lines

fs/splice.c static long do_splice(struct file *in, l · line 1094

Quoted 6 lines
fs/splice.c +6 -0
+	pipe = file->f_dentry->d_inode->i_pipe;
+	if (unlikely(!pipe))
+		return -EBADF;
+
+	spd.offset = uaddr & ~PAGE_CACHE_MASK;
+	nr_pages = (len + spd.offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;

Can I feed this 16TB of memory? If so, we just overflowed `nr_pages'.

I'll make it a long type instead.

Quoted 14 lines

include/asm-powerpc/unistd.h #define __NR_ppoll 281 · line 309

Quoted 11 lines
include/asm-powerpc/unistd.h +2 -1
@@ -303,8 +303,9 @@ #define __NR_ppoll		281
 #define __NR_unshare		282
 #define __NR_splice		283
 #define __NR_tee		284
+#define __NR_vmsplice		285
 
-#define __NR_syscalls		285
+#define __NR_syscalls		286
 

Every time we do this the spufs build breaks:

Quoted 5 lines

long spu_sys_callback(struct spu_syscall_block *s)

{
	long (*syscall)(u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 a6);

	BUILD_BUG_ON(ARRAY_SIZE(spu_syscall_table) != __NR_syscalls);

I'll leave the ppc syscall update out of it.

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 8 lines · Jens Axboe
Quoted 6 lines

long spu_sys_callback(struct spu_syscall_block *s)

{
	long (*syscall)(u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 a6);

	BUILD_BUG_ON(ARRAY_SIZE(spu_syscall_table) != __NR_syscalls);

I'll leave the ppc syscall update out of it.

It might be better to just stick the new entry into the spufs table, make sure that the powerpc guys see it go in. That way, ppc64 people (Linus, maybe you?) can test it.

I guess mapping it onto sys_ni_syscall would be safest.

(It's been broken since sys_tee went in, btw).

author
#4 lore raw
Quoted 6 lines · Andrew Morton
Quoted 5 lines · Jens Axboe
Quoted 5 lines

long spu_sys_callback(struct spu_syscall_block *s)

{
	long (*syscall)(u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 a6);
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
	BUILD_BUG_ON(ARRAY_SIZE(spu_syscall_table) != __NR_syscalls);

I'll leave the ppc syscall update out of it.

It might be better to just stick the new entry into the spufs table, make sure that the powerpc guys see it go in. That way, ppc64 people (Linus, maybe you?) can test it.

No ppc64 here unfortunately, and my ppc box (powerbook) has since moved on to more relaxing pastures (my wife inherited it). But certainly, I'll update it then.

Quoted 3 lines

I guess mapping it onto sys_ni_syscall would be safest.

(It's been broken since sys_tee went in, btw).

Noted.

Signature · 1 line
Jens Axboe
maintainer
#5 lore raw
In reply to Andrew Morton
Quoted 7 lines · Andrew Morton

It might be better to just stick the new entry into the spufs table, make sure that the powerpc guys see it go in.  That way, ppc64 people (Linus, maybe you?) can test it.

I guess mapping it onto sys_ni_syscall would be safest.

(It's been broken since sys_tee went in, btw).

The BUILD_BUG_ON in there was just overkill. How about if we just add a small comment to the systbl on powerpc to remind people about the fact that there is another file to edit? Patch follows.

	Arnd <><
maintainer
#6 lore raw

PATCH 1/1 fix spu_callbacks BUILD_BUG_ON

Every time a new syscall gets added, a BUILD_BUG_ON in arch/powerpc/platforms/cell/spu_callbacks.c gets triggered. Since the addition of a new syscall is rather harmless, the error should just be removed.

While we're here, add sys_tee to the list and add a comment to systbl.S to remind people that there is another list on powerpc.

arch/powerpc/platforms/cell/spu_callbacks.c +2 -3
@@ -317,17 +317,16 @@ void *spu_syscall_table[] = {
 	[__NR_ppoll]			sys_ni_syscall, /* sys_ppoll */
 	[__NR_unshare]			sys_unshare,
 	[__NR_splice]			sys_splice,
+	[__NR_tee]			sys_tee,
 };
 
 long spu_sys_callback(struct spu_syscall_block *s)
 {
 	long (*syscall)(u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 a6);
 
-	BUILD_BUG_ON(ARRAY_SIZE(spu_syscall_table) != __NR_syscalls);
-
 	syscall = spu_syscall_table[s->nr_ret];
 
-	if (s->nr_ret >= __NR_syscalls) {
+	if (s->nr_ret >= ARRAY_SIZE(spu_syscall_table)) {
 		pr_debug("%s: invalid syscall #%ld", __FUNCTION__, s->nr_ret);
 		return -ENOSYS;
 	}
arch/powerpc/kernel/systbl.S +5 -0
Index: linus-2.6/arch/powerpc/kernel/systbl.S
===================================================================
@@ -324,3 +324,8 @@ COMPAT_SYS(ppoll)
 SYSCALL(unshare)
 SYSCALL(splice)
 SYSCALL(tee)
+
+/*
+ * please add new calls to arch/powerpc/platforms/cell/spu_callbacks.c
+ * as well when appropriate.
+ */
#7 lore raw

Re: [PATCH] fix spu_callbacks BUILD_BUG_ON

arch/powerpc/platforms/cell/spu_callbacks.c void *spu_syscall_table[] = { · line 320

Quoted 8 lines
arch/powerpc/platforms/cell/spu_callbacks.c +1 -0
@@ -317,17 +317,16 @@ void *spu_syscall_table[] = {
 	[__NR_ppoll]			sys_ni_syscall, /* sys_ppoll */
 	[__NR_unshare]			sys_unshare,
 	[__NR_splice]			sys_splice,
+	[__NR_tee]			sys_tee,

+ [__NR_syscalls] = NULL,

arch/powerpc/platforms/cell/spu_callbacks.c void *spu_syscall_table[] = { · line 329

Quoted 12 lines
arch/powerpc/platforms/cell/spu_callbacks.c +1 -3
 };
 
 long spu_sys_callback(struct spu_syscall_block *s)
 {
 	long (*syscall)(u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 a6);
 
-	BUILD_BUG_ON(ARRAY_SIZE(spu_syscall_table) != __NR_syscalls);
-
 	syscall = spu_syscall_table[s->nr_ret];
 
-	if (s->nr_ret >= __NR_syscalls) {
+	if (s->nr_ret >= ARRAY_SIZE(spu_syscall_table)) {

+ if(syscall == NULL) {

That way, syscalls could be added in the master table while spu does not break. Comments?

Jan Engelhardt

maintainer
#8 lore raw

Re: [PATCH] fix spu_callbacks BUILD_BUG_ON

Quoted 8 lines · Jan Engelhardt

+      [__NR_syscalls] = NULL,

Quoted 5 lines

};

-      if (s->nr_ret >= __NR_syscalls) {
+      if (s->nr_ret >= ARRAY_SIZE(spu_syscall_table)) {

Quoted 6 lines

+       if(syscall == NULL) {

That way, syscalls could be added in the master table while spu does not break. Comments?

Hmm, my idea was not having to check for NULL pointers when we know that they are valid function calls. But you are right that your approach is more robust. It also means that we might just leave out all the assignments to sys_ni_syscall in order to make the source a little shorter.

	Arnd <><
#9 lore raw
In reply to Jens Axboe
Quoted 4 lines · Jens Axboe

Here's the first implementation of sys_vmsplice(). I'm attaching a little test app as well for playing with it, it's also committed to the splice tools repo at:

Btw, I think we'll have to think a bit more about the buffer size issues:

fs/fcntl.c static long do_fcntl(int fd, unsigned in · line 355

Quoted 11 lines
fs/fcntl.c +7 -0
@@ -345,6 +346,13 @@ static long do_fcntl(int fd, unsigned in
 	case F_NOTIFY:
 		err = fcntl_dirnotify(fd, filp, arg);
 		break;
+	case F_SETPSZ:
+		err = -EINVAL;
+		break;
+	case F_GETPSZ:
+		/* this assumes user space can reliably tell PAGE_CACHE_SIZE */
+		err = PIPE_BUFFERS;
+		break;

The above obviously isn't incorrect, but it really isn't enough to handle the case I was talking about - for somebody to be able to re-use a vmsplice'd page, it's not enough that his buffer is bigger than the pipe buffer, it needs to be bigger than the end-to-end buffer. Or rather, bigger than the "end-to-copy" buffer.

Ie there may be more buffering after the local pipe buffer - other pipes, network buffers, etc etc.

It may even be that my idea to try to limit the buffer size just isn't workable, and that we need to do it in a page-per-page basis (ie instead of depending on the buffer sizes, actually inspect the page and wait for it to be flushed all the way).

So while thinking about that, it might be best to forget about the pipe buffer size issue until the final solution is clearer. The pipe buffer may well be a _part_ of it, though.

Linus

author
#10 lore raw
Quoted 31 lines · Linus Torvalds
Quoted 4 lines · Jens Axboe

Here's the first implementation of sys_vmsplice(). I'm attaching a little test app as well for playing with it, it's also committed to the splice tools repo at:

Btw, I think we'll have to think a bit more about the buffer size issues:

fs/fcntl.c static long do_fcntl(int fd, unsigned in · line 355

Quoted 11 lines
fs/fcntl.c +7 -0
@@ -345,6 +346,13 @@ static long do_fcntl(int fd, unsigned in
 	case F_NOTIFY:
 		err = fcntl_dirnotify(fd, filp, arg);
 		break;
+	case F_SETPSZ:
+		err = -EINVAL;
+		break;
+	case F_GETPSZ:
+		/* this assumes user space can reliably tell PAGE_CACHE_SIZE */
+		err = PIPE_BUFFERS;
+		break;

The above obviously isn't incorrect, but it really isn't enough to handle the case I was talking about - for somebody to be able to re-use a vmsplice'd page, it's not enough that his buffer is bigger than the pipe buffer, it needs to be bigger than the end-to-end buffer. Or rather, bigger than the "end-to-copy" buffer.

Ie there may be more buffering after the local pipe buffer - other pipes, network buffers, etc etc.

Quoted 8 lines

It may even be that my idea to try to limit the buffer size just isn't workable, and that we need to do it in a page-per-page basis (ie instead of depending on the buffer sizes, actually inspect the page and wait for it to be flushed all the way).

So while thinking about that, it might be best to forget about the pipe buffer size issue until the final solution is clearer. The pipe buffer may well be a _part_ of it, though.

Obviously the posted patch doesn't handle the reuse case yet. If you play with the splice tools and do:

# vmsplice | ktee-net bla port | cat > file

with the vmsplice modified to memset the first half of the buffer after the second half has been vmspliced, you'll see bad data going out over the network.

One way that works fine but is hackish is just to monitor the page count. So don't rely solely on reusing the page once ->release has been called, but also check buf->page on reuse if the ->release function hasn't cleared ->page (the page cache ops would, the user_page would not) so move_to_pipe() can break out appropriately just like if pipe->nr_buffers was too large. Works, is easily doable, but isn't a very nice design - it basically works around the problem that ->release() is called too early.

The better way is imho to forget ->sendpage() and do a proper hook that actually accepts the pipe buffer. Then you don't have to work around premature release. And hey, it'd be more efficient too. With tee and friends, you'd want to keep them referenced as well.

This all provided that the method of choice for signalling safe reuse is still either blocking on vmsplice or using poll() intelligently to do that.

Signature · 1 line
Jens Axboe