From: Daniel Colascione <dancol@google.com>
To: joelaf@google.com, ast@fb.com
Cc: linux-kernel@vger.kernel.org, timmurray@google.com,
Daniel Colascione <dancol@google.com>
Subject: [RFC] Add BPF_SYNCHRONIZE bpf(2) command
Date: Fri, 6 Jul 2018 18:56:16 -0700 [thread overview]
Message-ID: <20180707015616.25988-1-dancol@google.com> (raw)
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;
+ }
+
err = bpf_check_uarg_tail_zero(uattr, sizeof(attr), size);
if (err)
return err;
--
2.18.0.203.gfac676dfb9-goog
next reply other threads:[~2018-07-07 1:57 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-07 1:56 Daniel Colascione [this message]
2018-07-07 2:54 ` [RFC] Add BPF_SYNCHRONIZE bpf(2) command Alexei Starovoitov
2018-07-07 3:22 ` Daniel Colascione
2018-07-07 20:33 ` Joel Fernandes
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-27 19:17 ` [RFC] Add BPF_SYNCHRONIZE " Daniel Colascione
2018-07-10 5:13 ` 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=20180707015616.25988-1-dancol@google.com \
--to=dancol@google.com \
--cc=ast@fb.com \
--cc=joelaf@google.com \
--cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.