From: Daniel Colascione <dancol@google.com>
To: joelaf@google.com
Cc: linux-kernel@vger.kernel.org, timmurray@google.com,
netdev@vger.kernel.org,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Lorenzo Colitti <lorenzo@google.com>,
Chenbo Feng <fengc@google.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Daniel Colascione <dancol@google.com>
Subject: [PATCH v2] Add BPF_SYNCHRONIZE_MAPS bpf(2) command
Date: Thu, 26 Jul 2018 09:51:05 -0700 [thread overview]
Message-ID: <20180726165105.8634-1-dancol@google.com> (raw)
In-Reply-To: <20180716202301.GB160902@joelaf.mtv.corp.google.com>
BPF_SYNCHRONIZE_MAPS waits for the release of any references to a BPF
map made by a BPF program that is running at the time the
BPF_SYNCHRONIZE_MAPS command is issued. The purpose of this command is
to provide a means for userspace to replace a BPF map with another,
newer version, then ensure that no component is still using the "old"
map before manipulating the "old" map in some way.
Signed-off-by: Daniel Colascione <dancol@google.com>
---
include/uapi/linux/bpf.h | 9 +++++++++
kernel/bpf/syscall.c | 13 +++++++++++++
2 files changed, 22 insertions(+)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index b7db3261c62d..5b27e9117d3e 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -75,6 +75,14 @@ struct bpf_lpm_trie_key {
__u8 data[0]; /* Arbitrary size */
};
+/* BPF_SYNCHRONIZE_MAPS waits for the release of any references to a
+ * BPF map made by a BPF program that is running at the time the
+ * BPF_SYNCHRONIZE_MAPS command is issued. The purpose of this command
+ * is to provide a means for userspace to replace a BPF map with
+ * another, newer version, then ensure that no component is still
+ * using the "old" map before manipulating the "old" map in some way.
+ */
+
/* BPF syscall commands, see bpf(2) man-page for details. */
enum bpf_cmd {
BPF_MAP_CREATE,
@@ -98,6 +106,7 @@ enum bpf_cmd {
BPF_BTF_LOAD,
BPF_BTF_GET_FD_BY_ID,
BPF_TASK_FD_QUERY,
+ BPF_SYNCHRONIZE_MAPS,
};
enum bpf_map_type {
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index a31a1ba0f8ea..8bbd1a5d01d1 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2274,6 +2274,19 @@ 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_MAPS) {
+ if (uattr != NULL || size != 0)
+ return -EINVAL;
+ err = security_bpf(cmd, NULL, 0);
+ if (err < 0)
+ return err;
+ /* BPF programs always enter a critical section while
+ * they have a map reference outstanding.
+ */
+ synchronize_rcu();
+ return 0;
+ }
+
err = bpf_check_uarg_tail_zero(uattr, sizeof(attr), size);
if (err)
return err;
--
2.18.0.233.g985f88cf7e-goog
next prev parent reply other threads:[~2018-07-26 16:51 UTC|newest]
Thread overview: 34+ 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
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 ` Daniel Colascione [this message]
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
2018-07-29 15:51 [PATCH v2] Add BPF_SYNCHRONIZE_MAPS " Alexei Starovoitov
2018-07-31 2:01 ` Joel Fernandes
2018-07-31 2:06 ` Joel Fernandes
2018-07-31 4:03 ` Y Song
2018-07-31 21:56 ` Joel Fernandes
2018-07-31 22:30 ` Daniel Borkmann
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=20180726165105.8634-1-dancol@google.com \
--to=dancol@google.com \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=fengc@google.com \
--cc=joelaf@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo@google.com \
--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;
as well as URLs for NNTP newsgroup(s).