From: Joel Fernandes <joelaf@google.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Daniel Colascione <dancol@google.com>,
ast@fb.com, linux-kernel@vger.kernel.org, timmurray@google.com,
daniel@iogearbox.net, netdev@vger.kernel.org,
mathieu.desnoyers@efficios.com, fengc@google.com
Subject: Re: [RFC] Add BPF_SYNCHRONIZE bpf(2) command
Date: Sat, 7 Jul 2018 13:33:40 -0700 [thread overview]
Message-ID: <20180707203340.GA74719@joelaf.mtv.corp.google.com> (raw)
In-Reply-To: <20180707025426.ssxipi7hsehoiuyo@ast-mbp.dhcp.thefacebook.com>
On Fri, Jul 06, 2018 at 07:54:28PM -0700, Alexei Starovoitov wrote:
> On Fri, Jul 06, 2018 at 06:56:16PM -0700, Daniel Colascione wrote:
> > BPF_SYNCHRONIZE waits for any BPF programs active at the time of
> > BPF_SYNCHRONIZE to complete, allowing userspace to ensure atomicity of
> > RCU data structure operations with respect to active programs. For
> > example, userspace can update a map->map entry to point to a new map,
> > use BPF_SYNCHRONIZE to wait for any BPF programs using the old map to
> > complete, and then drain the old map without fear that BPF programs
> > may still be updating it.
> >
> > Signed-off-by: Daniel Colascione <dancol@google.com>
> > ---
> > include/uapi/linux/bpf.h | 1 +
> > kernel/bpf/syscall.c | 14 ++++++++++++++
> > 2 files changed, 15 insertions(+)
> >
> > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> > index b7db3261c62d..4365c50e8055 100644
> > --- a/include/uapi/linux/bpf.h
> > +++ b/include/uapi/linux/bpf.h
> > @@ -98,6 +98,7 @@ enum bpf_cmd {
> > BPF_BTF_LOAD,
> > BPF_BTF_GET_FD_BY_ID,
> > BPF_TASK_FD_QUERY,
> > + BPF_SYNCHRONIZE,
> > };
> >
> > enum bpf_map_type {
> > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > index d10ecd78105f..60ec7811846e 100644
> > --- a/kernel/bpf/syscall.c
> > +++ b/kernel/bpf/syscall.c
> > @@ -2272,6 +2272,20 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
> > if (sysctl_unprivileged_bpf_disabled && !capable(CAP_SYS_ADMIN))
> > return -EPERM;
> >
> > + if (cmd == BPF_SYNCHRONIZE) {
> > + if (uattr != NULL || size != 0)
> > + return -EINVAL;
> > + err = security_bpf(cmd, NULL, 0);
> > + if (err < 0)
> > + return err;
> > + /* BPF programs are run with preempt disabled, so
> > + * synchronize_sched is sufficient even with
> > + * RCU_PREEMPT.
> > + */
> > + synchronize_sched();
> > + return 0;
>
> I don't think it's necessary. sys_membarrier() can do this already
> and some folks use it exactly for this use case.
Alexei, the use of sys_membarrier for this purpose seems kind of weird to me
though. No where does the manpage say membarrier should be implemented this
way so what happens if the implementation changes?
Further, membarrier manpage says that a memory barrier should be matched with
a matching barrier. In this use case there is no matching barrier, so it
makes it weirder.
Lastly, sys_membarrier seems will not work on nohz-full systems, so its a bit
fragile to depend on it for this?
case MEMBARRIER_CMD_GLOBAL:
/* MEMBARRIER_CMD_GLOBAL is not compatible with nohz_full. */
if (tick_nohz_full_enabled())
return -EINVAL;
if (num_online_cpus() > 1)
synchronize_sched();
return 0;
Adding Mathieu as well who I believe is author/maintainer of membarrier.
thanks!
- Joel
next prev parent reply other threads:[~2018-07-07 20:33 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-07 1:56 [RFC] Add BPF_SYNCHRONIZE bpf(2) command Daniel Colascione
2018-07-07 2:54 ` Alexei Starovoitov
2018-07-07 3:22 ` Daniel Colascione
2018-07-07 20:33 ` Joel Fernandes [this message]
2018-07-08 20:54 ` Mathieu Desnoyers
2018-07-09 21:09 ` Alexei Starovoitov
2018-07-09 21:35 ` Mathieu Desnoyers
2018-07-09 22:19 ` Paul E. McKenney
2018-07-09 22:19 ` Alexei Starovoitov
2018-07-09 22:48 ` Paul E. McKenney
2018-07-09 21:36 ` Daniel Colascione
2018-07-09 22:10 ` Alexei Starovoitov
2018-07-09 22:21 ` Daniel Colascione
2018-07-09 22:34 ` Alexei Starovoitov
2018-07-10 5:25 ` Chenbo Feng
2018-07-10 23:52 ` Alexei Starovoitov
2018-07-11 2:46 ` Lorenzo Colitti
2018-07-11 3:40 ` Alexei Starovoitov
2018-07-14 18:18 ` Joel Fernandes
2018-07-16 15:29 ` Daniel Colascione
2018-07-16 20:23 ` Joel Fernandes
2018-07-26 16:51 ` [PATCH v2] Add BPF_SYNCHRONIZE_MAPS " Daniel Colascione
2018-07-10 5:13 ` [RFC] Add BPF_SYNCHRONIZE " Joel Fernandes
2018-07-10 16:42 ` Paul E. McKenney
2018-07-10 16:57 ` Joel Fernandes
2018-07-10 17:12 ` Paul E. McKenney
2018-07-10 17:29 ` Joel Fernandes
2018-07-10 17:42 ` Paul E. McKenney
-- strict thread matches above, loose matches on Subject: below --
2018-07-29 15:57 Alexei Starovoitov
2018-07-30 22:26 ` Joel Fernandes
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=20180707203340.GA74719@joelaf.mtv.corp.google.com \
--to=joelaf@google.com \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@fb.com \
--cc=dancol@google.com \
--cc=daniel@iogearbox.net \
--cc=fengc@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=netdev@vger.kernel.org \
--cc=timmurray@google.com \
/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