qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] linux-user: Fix pipe() vs. pipe2() usage for ALPHA, MIPS, S


From: Peter Maydell
Subject: Re: [PATCH] linux-user: Fix pipe() vs. pipe2() usage for ALPHA, MIPS, SH4 and SPARC
Date: Mon, 18 Jul 2022 15:33:37 +0100

On Mon, 18 Jul 2022 at 15:21, Helge Deller <deller@gmx.de> wrote:
> On 7/18/22 14:51, Peter Maydell wrote:
> > Why do we need to do this?
>
> Yep, we don't *need* to...
>
> > If the flags argument is 0,
> > then pipe2() is the same as pipe(), so we can safely
> > emulate it with the host pipe() call. It is, or at
> > least was, worth doing that, so that guests that use
> > pipe2(fds, 0) can still run on hosts that don't implement
> > the pipe2 syscall.
>
> True, but only for pipe2(fds,0), not e.g. for pipe2(fds,1).
> On the other side if a guest explicitly calls pipe2()
> and if it isn't available, then IMHO -ENOSYS should be returned.
> Let's assume userspace checks in configure/make scripts if pipe2()
> is available and succeeds due to pipe2(fds,0), it will assume pipe2()
> is generally available which isn't necessarily true.

Fair point. Did you run into this in practice, or is it just a
theoretical concern ?

NB that any probing code that does that will also get the wrong
answer on musl libc, though, because musl's pipe2() implementation
always calls pipe() for a zero-flags call:
https://git.musl-libc.org/cgit/musl/tree/src/unistd/pipe2.c

> > There's probably a reasonable argument to be made that we don't
> > care any more about hosts so old they don't have pipe2 and that
> > we could just dump do_pipe2() and the CONFIG_PIPE2 check, and
> > have do_pipe() unconditionally call pipe2(). Would just need
> > somebody to check what kernel/glibc versions pipe2() came in.
>
> Yes.

I just had a look, and the pipe2 syscall came in in Linux 2.6.27.
musl has implemented pipe2() since at least 2013, and glibc must
have had it for at least that long.

In fact current glibc always implements pipe() in terms of pipe2():
https://sourceware.org/git/?p=glibc.git;a=commit;h=efc6b2dbc47231dee7a7ac39beec808deb4e4d1f

So my preference would be that we should just say "we can assume
that pipe2 is always available and implemented on linux hosts" and
remove the code that handles the possibility that it isn't.

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]