All of lore.kernel.org
 help / color / mirror / Atom feed
* splice() from /dev/zero to a pipe does not work (5.9+)
@ 2021-05-07 18:05 Colin Ian King
  2021-05-07 18:21 ` Kees Cook
  0 siblings, 1 reply; 7+ messages in thread
From: Colin Ian King @ 2021-05-07 18:05 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Kees Cook, Al Viro, linux-fsdevel

Hi,

While doing some micro benchmarking with stress-ng I discovered that
since linux 5.9 the splicing from /dev/zero to a pipe now fails with
-EINVAL.

I bisected this down to the following commit:

36e2c7421f02a22f71c9283e55fdb672a9eb58e7 is the first bad commit
commit 36e2c7421f02a22f71c9283e55fdb672a9eb58e7
Author: Christoph Hellwig <hch@lst.de>
Date:   Thu Sep 3 16:22:34 2020 +0200

    fs: don't allow splice read/write without explicit ops

I'm not sure if this has been reported before, or if it's intentional
behavior or not. As it stands, it's a regression in the stress-ng splice
test case.

Prior to that commit, splicing worked from /dev/zero to a pipe. Below is
an example of the reproducer:

--- reproducer below ---

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

#define FAIL(x) { perror(x); exit(1); }

int main(void)
{
        int fd_in, fd_out, fds[2];
        ssize_t ret;
        loff_t off_in, off_out;
        const size_t len = 4096;

        if ((fd_in = open("/dev/zero", O_RDONLY)) < 0)
                FAIL("open /dev/zero failed");

        /*
         *   /dev/zero -> pipe splice -> pipe splice -> /dev/null
         */
        if (pipe(fds) < 0)
                FAIL("pipe FAILed\n");

        if ((fd_out = open("/dev/null", O_WRONLY)) < 0)
                FAIL("open /dev/null failed");

        ret = splice(fd_in, NULL, fds[1], NULL, len, SPLICE_F_MOVE);
        if (ret < 0)
                FAIL("splice failed");

        ret = splice(fds[0], NULL, fd_out, NULL, len, SPLICE_F_MOVE);
        if (ret < 0)
                FAIL("splice failed");

        return 0;
}

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-12 15:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 18:05 splice() from /dev/zero to a pipe does not work (5.9+) Colin Ian King
2021-05-07 18:21 ` Kees Cook
2021-05-07 19:06   ` Linus Torvalds
2021-05-07 19:17     ` Al Viro
2021-05-07 19:29       ` Linus Torvalds
2021-05-07 20:31         ` Al Viro
2021-05-12 15:13   ` Colin Ian King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.