bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <song@kernel.org>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, ast@kernel.org,  daniel@iogearbox.net,
	martin.lau@kernel.org, kernel-team@meta.com
Subject: Re: [PATCH bpf-next] libbpf: call dup2() syscall directly
Date: Fri, 19 Jan 2024 13:34:32 -0800	[thread overview]
Message-ID: <CAPhsuW7PZ4aMmtZrTHx-R9yyU6aJbHhmEVhxL=CB6L+4Og9BAw@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzaHz3VRUs=vHC7u5rZmTHE7CTs78oYcOHripWM266QA+A@mail.gmail.com>

On Fri, Jan 19, 2024 at 1:30 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Fri, Jan 19, 2024 at 1:21 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
> >
> > On Fri, Jan 19, 2024 at 1:18 PM Song Liu <song@kernel.org> wrote:
> > >
> > > On Fri, Jan 19, 2024 at 1:02 PM Andrii Nakryiko <andrii@kernel.org> wrote:
> > > >
> > > > We've ran into issues with using dup2() API in production setting, where
> > > > libbpf is linked into large production environment and ends up calling
> > > > uninteded custom implementations of dup2(). These custom implementations
> > >
> > > typo: unintended
> >
> > oops, but probably doesn't warrant respinning
> >
> > >
> > > > don't provide atomic FD replacement guarantees of dup2() syscall,
> > > > leading to subtle and hard to debug issues.
> > > >
> > > > To prevent this in the future and guarantee that no libc implementation
> > > > will do their own custom non-atomic dup2() implementation, call dup2()
> > > > syscall directly with syscall(SYS_dup2).
> > > >
> > > > Note that some architectures don't seem to provide dup2 and have dup3
> > > > instead. Try to detect and pick best syscall.
> > >
> > > I wonder whether we can just always use dup3().
> >
> > dup3() (according to my git foo) was added in 4.17, which is more
> > modern than some other usable BPF, so I don't want to just randomly
> > bump the minimal supported (by libbpf) kernel for something like this.
> >

I believe dup3() was added in 3.7.

>
> Btw, this #ifdef check is the same as what glibc does for its
> implementation of dup2() (except for fd equality check which isn't
> necessary for libbpf), see [0]
>
>   [0] https://github.com/bminor/glibc/blob/master/sysdeps/unix/sysv/linux/dup2.c

Yep, this looks good.

Thanks,
Song

  reply	other threads:[~2024-01-19 21:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 21:02 [PATCH bpf-next] libbpf: call dup2() syscall directly Andrii Nakryiko
2024-01-19 21:18 ` Song Liu
2024-01-19 21:21   ` Andrii Nakryiko
2024-01-19 21:29     ` Andrii Nakryiko
2024-01-19 21:34       ` Song Liu [this message]
2024-01-19 21:42         ` Andrii Nakryiko
2024-01-21  6:24 ` Yonghong Song
2024-01-23 23:40 ` patchwork-bot+netdevbpf

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='CAPhsuW7PZ4aMmtZrTHx-R9yyU6aJbHhmEVhxL=CB6L+4Og9BAw@mail.gmail.com' \
    --to=song@kernel.org \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@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).