netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roman Gushchin <guro@fb.com>
To: <netdev@vger.kernel.org>
Cc: <kernel-team@fb.com>, <tj@kernel.org>,
	Roman Gushchin <guro@fb.com>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>
Subject: [PATCH bpf-net 03/14] bpf: pass a pointer to a cgroup storage using pcpu variable
Date: Thu, 28 Jun 2018 09:34:47 -0700	[thread overview]
Message-ID: <20180628163458.27193-4-guro@fb.com> (raw)
In-Reply-To: <20180628163458.27193-1-guro@fb.com>

This commit introduces the bpf_cgroup_storage_set() helper,
which will be used to pass a pointer to a cgroup storage
to the bpf helper.

Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
---
 include/linux/bpf-cgroup.h | 14 ++++++++++++++
 kernel/bpf/local_storage.c |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index b4e2e42c1d2a..128fb0e39b4d 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -20,6 +20,8 @@ struct bpf_cgroup_storage;
 extern struct static_key_false cgroup_bpf_enabled_key;
 #define cgroup_bpf_enabled static_branch_unlikely(&cgroup_bpf_enabled_key)
 
+DECLARE_PER_CPU(void*, bpf_cgroup_storage);
+
 struct bpf_cgroup_storage_map;
 
 struct bpf_storage_buffer {
@@ -96,6 +98,17 @@ int __cgroup_bpf_run_filter_sock_ops(struct sock *sk,
 int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor,
 				      short access, enum bpf_attach_type type);
 
+static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage *storage)
+{
+	struct bpf_storage_buffer *buf;
+
+	if (!storage)
+		return;
+
+	buf = rcu_dereference(storage->buf);
+	this_cpu_write(bpf_cgroup_storage, &buf->data[0]);
+}
+
 struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog);
 void bpf_cgroup_storage_free(struct bpf_cgroup_storage *storage);
 void bpf_cgroup_storage_link(struct bpf_cgroup_storage *storage,
@@ -223,6 +236,7 @@ struct cgroup_bpf {};
 static inline void cgroup_bpf_put(struct cgroup *cgrp) {}
 static inline int cgroup_bpf_inherit(struct cgroup *cgrp) { return 0; }
 
+static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage *storage) {}
 static inline int bpf_cgroup_storage_assign(struct bpf_prog *prog,
 					    struct bpf_map *map) { return 0; }
 static inline void bpf_cgroup_storage_release(struct bpf_prog *prog,
diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c
index 940889eda2c7..38810a712971 100644
--- a/kernel/bpf/local_storage.c
+++ b/kernel/bpf/local_storage.c
@@ -7,6 +7,8 @@
 #include <linux/rbtree.h>
 #include <linux/slab.h>
 
+DEFINE_PER_CPU(void*, bpf_cgroup_storage);
+
 #ifdef CONFIG_CGROUP_BPF
 
 struct bpf_cgroup_storage_map {
-- 
2.14.4

  parent reply	other threads:[~2018-06-28 16:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-28 16:34 [PATCH bpf-net 00/14] bpf: cgroup local storage Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 01/14] bpf: add ability to charge bpf maps memory dynamically Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 02/14] bpf: introduce cgroup storage maps Roman Gushchin
2018-06-28 16:34 ` Roman Gushchin [this message]
2018-06-28 16:34 ` [PATCH bpf-net 04/14] bpf: allocate cgroup storage entries on attaching bpf programs Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 05/14] bpf: extend bpf_prog_array to store pointers to the cgroup storage Roman Gushchin
2018-06-28 22:21   ` kbuild test robot
2018-06-28 16:34 ` [PATCH bpf-net 06/14] bpf/verifier: introduce BPF_PTR_TO_MAP_VALUE Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 07/14] bpf: don't allow create maps of cgroup local storages Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 08/14] bpf: introduce the bpf_get_local_storage() helper function Roman Gushchin
2018-06-29  4:37   ` kbuild test robot
2018-06-28 16:34 ` [PATCH bpf-net 09/14] bpf: sync bpf.h to tools/ Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 10/14] bpftool: add support for CGROUP_STORAGE maps Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 11/14] bpf/test_run: support cgroup local storage Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 12/14] selftests/bpf: add verifier cgroup storage tests Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 13/14] selftests/bpf: add a cgroup storage test Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 14/14] samples/bpf: extend test_cgrp2_attach2 test to use cgroup storage Roman Gushchin
2018-06-28 16:46 ` [PATCH bpf-net 00/14] bpf: cgroup local storage Roman Gushchin

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=20180628163458.27193-4-guro@fb.com \
    --to=guro@fb.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=tj@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).