linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Oliver Giles" <ohw.giles@gmail.com>
To: "Johannes Berg" <johannes@sipsolutions.net>,
	<linux-kernel@vger.kernel.org>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Christoph Hellwig" <hch@lst.de>
Subject: Re: Splicing to/from a tty
Date: Sun, 17 Jan 2021 19:12:17 +1300	[thread overview]
Message-ID: <C8L7LWQDH7O9.1GHEPFD33W15X@oguc> (raw)
In-Reply-To: <f184764a283bdf3694478fa35ad41d2b3ec38850.camel@sipsolutions.net>

On Sun Jan 17, 2021 at 5:46 AM NZDT, Johannes Berg wrote:
> On Sat, 2021-01-16 at 20:35 +1300, Oliver Giles wrote:
> > Commit 36e2c7421f02 (fs: don't allow splice read/write without
> > explicit ops) broke my userspace application which talks to an SSL VPN
> > by splice()ing between "openssl s_client" and "pppd". The latter
> > operates over a pty, and since that commit there is no fallback for
> > splice()ing between a pipe and a pty, or any tty for that matter.
> > 
> > The above commit mentions switching them to the iter ops and using
> > generic_file_splice_read. IIUC, this would require implementing iter
> > ops also on the line disciplines, which sounds pretty disruptive.
> > 
> > For my case, I attempted to instead implement splice_write and
> > splice_read in tty_fops; I managed to get splice_write working calling
> > ld->ops->write, but splice_read is not so simple because the
> > tty_ldisc_ops read method expects a userspace buffer. So I cannot see
> > how to implement this without either (a) using set_fs, or (b)
> > implementing iter ops on all line disciplines.
> > 
> > Is splice()ing between a tty and a pipe worth supporting at all? Not a
> > big deal for my use case at least, but it used to work.
>
> Is it even strictly related to the tty?
>
> I was just now looking into why my cgit/fcgi/nginx setup no longer
> works, and the reason is getting -EINVAL from sendfile() when the input
> is a file and the output is a pipe().
>
> So I wrote a simple test program (below) and that errors out on kernel
> 5.10.4, while it works fine on the 5.9.16 I currently have. Haven't
> tried reverting anything yet, but now that I haev a test program it
> should be simple to even bisect.
>
> johannes
>
>
> #include <unistd.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <sys/sendfile.h>
> #include <stdio.h>
> #include <assert.h>
>
> int main(int argc, char **argv)
> {
> int in = open(argv[0], O_RDONLY);
> int p[2], out;
> off_t off = 0;
> int err;
>
> assert(in >= 0);
> assert(pipe(p) >= 0);
> out = p[1];
> err = sendfile(out, in, &off, 1024);
> if (err < 0)
> perror("sendfile");
> assert(err == 1024);
>
> return 0;
> }

I can confirm the behaviour you see, and that it starts occurring from the same
commit 36e2c7421f02a22 (fs: don't allow splice read/write without explicit ops).

In my tty case, it is clear that removing the default fallback would cause this
to fail, but assuming the sendfile() source is on a regular filesystem, I am
unsure why splice cannot find the appropriate splice_write method. Could be
connected to the fact that the message from warn_unsupported in fs/splice.c
outputs "splice write not supported for file  (pid: 983819 comm: test-sendfile)",
i.e. the file path is blank. In my case of directly calling splice on a pty, I
do see a path such as /ptyp0 in that error before implementing splice_(read/write)
callbacks. Maybe splice is getting a bogus file pointer from sendfile?

  reply	other threads:[~2021-01-17  6:14 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-16  7:35 Splicing to/from a tty Oliver Giles
2021-01-16 16:46 ` Johannes Berg
2021-01-17  6:12   ` Oliver Giles [this message]
2021-01-18  8:53   ` Christoph Hellwig
2021-01-18  8:58     ` Johannes Berg
2021-01-18 19:26       ` Linus Torvalds
2021-01-18 19:45         ` Al Viro
2021-01-18 19:49           ` Linus Torvalds
2021-01-18 19:56             ` Al Viro
2021-01-24 19:11           ` Linus Torvalds
2021-01-25  9:16             ` [PATCH] fs/pipe: allow sendfile() to pipe again Johannes Berg
2021-01-25 10:16               ` Christoph Hellwig
2021-01-25 20:34               ` Linus Torvalds
2021-01-26  6:07             ` Splicing to/from a tty Al Viro
2021-01-26  6:08               ` [PATCH 1/3] do_splice_to(): move the logics for limiting the read length in Al Viro
2021-01-26  6:09               ` [PATCH 2/3] take the guts of file-to-pipe splice into a helper function Al Viro
2021-01-26  6:09               ` [PATCH 3/3] teach sendfile(2) to handle send-to-pipe directly Al Viro
2021-01-26 18:57                 ` Linus Torvalds
2021-01-26 19:33                   ` Al Viro
2021-01-26 18:49               ` Splicing to/from a tty Linus Torvalds
2021-01-26 19:42                 ` Al Viro
2021-01-18 19:34     ` Al Viro
2021-01-18 19:46       ` Linus Torvalds
2021-01-18 19:54         ` Al Viro
2021-01-20 16:26           ` Al Viro
2021-01-20 19:11             ` Al Viro
2021-01-20 19:27               ` Linus Torvalds
2021-01-20 22:25                 ` David Laight
2021-01-20 23:02                   ` Al Viro
2021-01-20 23:14                 ` Al Viro
2021-01-20 23:40                   ` Linus Torvalds
2021-01-21  0:38                     ` Al Viro
2021-01-21  1:04                       ` Linus Torvalds
2021-01-21  1:45                         ` Al Viro
2021-01-21  3:38                           ` Linus Torvalds
2021-01-21  6:05                             ` Willy Tarreau
2021-01-21  8:04                               ` Johannes Berg
2021-01-21 10:08                         ` David Laight
2021-01-18  8:16 ` Christoph Hellwig
2021-01-18 19:36   ` Linus Torvalds
2021-01-18 20:24     ` Linus Torvalds
2021-01-18 21:35       ` Linus Torvalds
2021-01-18 21:54         ` Linus Torvalds
2021-01-18 22:03           ` Linus Torvalds
2021-01-18 22:20             ` Linus Torvalds
2021-01-19  1:38               ` Linus Torvalds
2021-01-19 11:53                 ` Greg Kroah-Hartman
2021-01-19 16:56                   ` Robert Karszniewicz
2021-01-19 17:10                     ` Robert Karszniewicz
2021-01-19 22:09                     ` Oliver Giles
2021-01-19 17:25                   ` Linus Torvalds
2021-01-19 20:24                   ` Linus Torvalds
2021-01-19 20:38                     ` Christoph Hellwig
2021-01-20  1:25                     ` Oliver Giles
2021-01-20  4:44                       ` Linus Torvalds
2021-01-20  8:15                         ` Oliver Giles
2021-01-21  1:18                         ` tty splice branch (was "Re: Splicing to/from a tty") Linus Torvalds
2021-01-21  8:44                           ` Greg Kroah-Hartman
2021-01-21  8:50                           ` Jiri Slaby
2021-01-21  8:58                             ` Jiri Slaby
2021-01-21 17:52                               ` Linus Torvalds
2021-01-21  8:58                             ` Greg Kroah-Hartman
2021-01-21 17:03                         ` Splicing to/from a tty Robert Karszniewicz
2021-01-21 18:43                           ` Linus Torvalds
2021-01-19 11:52         ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C8L7LWQDH7O9.1GHEPFD33W15X@oguc \
    --to=ohw.giles@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).