From: Roman Gushchin <guro@fb.com>
To: <netdev@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <kernel-team@fb.com>,
Roman Gushchin <guro@fb.com>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Subject: [PATCH v6 bpf-next 03/14] bpf: pass a pointer to a cgroup storage using pcpu variable
Date: Wed, 1 Aug 2018 15:37:29 -0700 [thread overview]
Message-ID: <20180801223740.11252-4-guro@fb.com> (raw)
In-Reply-To: <20180801223740.11252-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 | 15 +++++++++++++++
kernel/bpf/local_storage.c | 2 ++
2 files changed, 17 insertions(+)
diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index 7d00d58869ed..9a144ddbbc8f 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -4,6 +4,7 @@
#include <linux/errno.h>
#include <linux/jump_label.h>
+#include <linux/percpu.h>
#include <linux/rbtree.h>
#include <uapi/linux/bpf.h>
@@ -21,6 +22,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 {
@@ -97,6 +100,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 = READ_ONCE(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,
@@ -250,6 +264,7 @@ static inline int cgroup_bpf_prog_query(const union bpf_attr *attr,
return -EINVAL;
}
+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 fd5edabc48b3..cd0b115c2395 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
#define LOCAL_STORAGE_CREATE_FLAG_MASK \
--
2.14.4
next prev parent reply other threads:[~2018-08-02 0:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-01 22:37 [PATCH v6 bpf-next 00/14] bpf: cgroup local storage Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 01/14] bpf: add ability to charge bpf maps memory dynamically Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 02/14] bpf: introduce cgroup storage maps Roman Gushchin
2018-08-01 22:37 ` Roman Gushchin [this message]
2018-08-01 22:37 ` [PATCH v6 bpf-next 04/14] bpf: allocate cgroup storage entries on attaching bpf programs Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 05/14] bpf: extend bpf_prog_array to store pointers to the cgroup storage Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 06/14] bpf/verifier: introduce BPF_PTR_TO_MAP_VALUE Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 07/14] bpf: don't allow create maps of cgroup local storages Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 08/14] bpf: introduce the bpf_get_local_storage() helper function Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 09/14] bpf: sync bpf.h to tools/ Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 10/14] bpftool: add support for CGROUP_STORAGE maps Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 11/14] bpf/test_run: support cgroup local storage Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 12/14] selftests/bpf: add verifier cgroup storage tests Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 13/14] selftests/bpf: add a cgroup storage test Roman Gushchin
2018-08-01 22:37 ` [PATCH v6 bpf-next 14/14] samples/bpf: extend test_cgrp2_attach2 test to use cgroup storage Roman Gushchin
2018-08-02 8:53 ` [PATCH v6 bpf-next 00/14] bpf: cgroup local storage 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=20180801223740.11252-4-guro@fb.com \
--to=guro@fb.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.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).