From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06BC0C433ED for ; Fri, 7 May 2021 18:05:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D564E6145A for ; Fri, 7 May 2021 18:05:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229476AbhEGSGx (ORCPT ); Fri, 7 May 2021 14:06:53 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:53470 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbhEGSGw (ORCPT ); Fri, 7 May 2021 14:06:52 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lf4rH-0000TI-MY; Fri, 07 May 2021 18:05:51 +0000 From: Colin Ian King To: Christoph Hellwig Cc: Kees Cook , Al Viro , linux-fsdevel Subject: splice() from /dev/zero to a pipe does not work (5.9+) Message-ID: <2add1129-d42e-176d-353d-3aca21280ead@canonical.com> Date: Fri, 7 May 2021 19:05:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 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 #include #include #include #include #include #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; }