From: Ming Lei <tom.leiming@gmail.com>
To: linux-kernel@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <kafai@fb.com>, Ming Lei <tom.leiming@gmail.com>
Subject: [PATCH 3/9] bpf: introduce percpu verion of lookup/update in bpf_map_ops
Date: Mon, 11 Jan 2016 23:56:55 +0800 [thread overview]
Message-ID: <1452527821-12276-4-git-send-email-tom.leiming@gmail.com> (raw)
In-Reply-To: <1452527821-12276-1-git-send-email-tom.leiming@gmail.com>
This patch is preparing for supporting percpu map, which
will be done in the following patches.
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
include/linux/bpf.h | 5 +++++
kernel/bpf/arraymap.c | 6 ++++++
kernel/bpf/bpf_map.h | 4 ++++
kernel/bpf/hashtab.c | 4 ++++
kernel/bpf/map.c | 11 +++++++++++
5 files changed, 30 insertions(+)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 83d1926..7fa339f 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -25,6 +25,11 @@ struct bpf_map_ops {
int (*map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags);
int (*map_delete_elem)(struct bpf_map *map, void *key);
+ /* funcs callable from userspace and from eBPF programs */
+ void *(*map_lookup_elem_percpu)(struct bpf_map *map, void *key, u32 cpu);
+ int (*map_update_elem_percpu)(struct bpf_map *map, void *key,
+ void *value, u64 flags, u32 cpu);
+
/* funcs called by prog_array and perf_event_array map */
void *(*map_fd_get_ptr) (struct bpf_map *map, int fd);
void (*map_fd_put_ptr) (void *ptr);
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 9ad9031..20b9f2c 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -139,6 +139,8 @@ static const struct bpf_map_ops array_ops = {
.map_lookup_elem = array_map_lookup_elem,
.map_update_elem = array_map_update_elem,
.map_delete_elem = map_delete_elem_nop,
+ .map_lookup_elem_percpu = map_lookup_elem_percpu_nop,
+ .map_update_elem_percpu = map_update_elem_percpu_nop,
};
static struct bpf_map_type_list array_type __read_mostly = {
@@ -258,6 +260,8 @@ static const struct bpf_map_ops prog_array_ops = {
.map_delete_elem = fd_array_map_delete_elem,
.map_fd_get_ptr = prog_fd_array_get_ptr,
.map_fd_put_ptr = prog_fd_array_put_ptr,
+ .map_lookup_elem_percpu = map_lookup_elem_percpu_nop,
+ .map_update_elem_percpu = map_update_elem_percpu_nop,
};
static struct bpf_map_type_list prog_array_type __read_mostly = {
@@ -324,6 +328,8 @@ static const struct bpf_map_ops perf_event_array_ops = {
.map_delete_elem = fd_array_map_delete_elem,
.map_fd_get_ptr = perf_event_fd_array_get_ptr,
.map_fd_put_ptr = perf_event_fd_array_put_ptr,
+ .map_lookup_elem_percpu = map_lookup_elem_percpu_nop,
+ .map_update_elem_percpu = map_update_elem_percpu_nop,
};
static struct bpf_map_type_list perf_event_array_type __read_mostly = {
diff --git a/kernel/bpf/bpf_map.h b/kernel/bpf/bpf_map.h
index 7e596c1..adab4e6 100644
--- a/kernel/bpf/bpf_map.h
+++ b/kernel/bpf/bpf_map.h
@@ -5,5 +5,9 @@
extern void *map_lookup_elem_nop(struct bpf_map *map, void *key);
extern int map_delete_elem_nop(struct bpf_map *map, void *key);
+extern void *map_lookup_elem_percpu_nop(struct bpf_map *map, void *key,
+ u32 cpu);
+extern int map_update_elem_percpu_nop(struct bpf_map *map, void *key,
+ void *value, u64 flags, u32 cpu);
#endif
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index c5b30fd..893e2e4 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -14,6 +14,8 @@
#include <linux/filter.h>
#include <linux/vmalloc.h>
+#include "bpf_map.h"
+
struct bucket {
struct hlist_head head;
raw_spinlock_t lock;
@@ -384,6 +386,8 @@ static const struct bpf_map_ops htab_ops = {
.map_lookup_elem = htab_map_lookup_elem,
.map_update_elem = htab_map_update_elem,
.map_delete_elem = htab_map_delete_elem,
+ .map_lookup_elem_percpu = map_lookup_elem_percpu_nop,
+ .map_update_elem_percpu = map_update_elem_percpu_nop,
};
static struct bpf_map_type_list htab_type __read_mostly = {
diff --git a/kernel/bpf/map.c b/kernel/bpf/map.c
index bf113fb..b94458a 100644
--- a/kernel/bpf/map.c
+++ b/kernel/bpf/map.c
@@ -24,3 +24,14 @@ int map_delete_elem_nop(struct bpf_map *map, void *key)
return -EINVAL;
}
+void *map_lookup_elem_percpu_nop(struct bpf_map *map, void *key, u32 cpu)
+{
+ return NULL;
+}
+
+int map_update_elem_percpu_nop(struct bpf_map *map, void *key, void *value,
+ u64 flags, u32 cpu)
+{
+ return -EINVAL;
+}
+
--
1.9.1
next prev parent reply other threads:[~2016-01-11 15:56 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-11 15:56 [PATCH 0/9] bpf: support percpu ARRAY map Ming Lei
2016-01-11 15:56 ` [PATCH 1/9] bpf: prepare for moving map common stuff into one place Ming Lei
2016-01-11 18:24 ` kbuild test robot
2016-01-11 15:56 ` [PATCH 2/9] bpf: array map: use pre-defined nop map function Ming Lei
2016-01-11 19:08 ` Alexei Starovoitov
2016-01-11 15:56 ` Ming Lei [this message]
2016-01-11 15:56 ` [PATCH 4/9] bpf: add percpu version of lookup/update element helpers Ming Lei
2016-01-11 15:56 ` [PATCH 5/9] bpf: syscall: add percpu version of lookup/update elem Ming Lei
2016-01-11 19:02 ` Alexei Starovoitov
2016-01-12 5:00 ` Ming Lei
2016-01-12 5:49 ` Alexei Starovoitov
2016-01-12 11:05 ` Ming Lei
2016-01-12 19:10 ` Martin KaFai Lau
2016-01-13 0:38 ` Ming Lei
2016-01-13 2:22 ` Martin KaFai Lau
2016-01-13 3:17 ` Ming Lei
2016-01-13 5:30 ` Alexei Starovoitov
2016-01-13 14:56 ` Ming Lei
2016-01-14 1:19 ` Alexei Starovoitov
2016-01-14 2:42 ` Ming Lei
2016-01-14 5:08 ` Alexei Starovoitov
2016-01-14 7:16 ` Ming Lei
2016-01-11 15:56 ` [PATCH 6/9] bpf: arraymap: introduce BPF_MAP_TYPE_ARRAY_PERCPU Ming Lei
2016-01-11 19:14 ` Alexei Starovoitov
2016-01-11 15:56 ` [PATCH 7/9] sample/bpf: introduces helpers for percpu array example Ming Lei
2016-01-11 15:57 ` [PATCH 8/9] sample/bpf: sockex1: user percpu array map Ming Lei
2016-01-11 15:57 ` [PATCH 9/9] samples/bpf: test " Ming Lei
2016-01-12 15:44 ` David Laight
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=1452527821-12276-4-git-send-email-tom.leiming@gmail.com \
--to=tom.leiming@gmail.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kafai@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).