From: Jesper Dangaard Brouer <brouer@redhat.com>
To: David Ahern <dsahern@gmail.com>,
bpf@vger.kernel.org, netdev@vger.kernel.org
Cc: Jesper Dangaard Brouer <brouer@redhat.com>,
Daniel Borkmann <borkmann@iogearbox.net>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>
Subject: [PATCH bpf-next RFC 1/3] bpf: move struct bpf_devmap_val out of UAPI
Date: Fri, 29 May 2020 17:59:40 +0200 [thread overview]
Message-ID: <159076798058.1387573.3077178618799401182.stgit@firesoul> (raw)
In-Reply-To: <159076794319.1387573.8722376887638960093.stgit@firesoul>
The struct bpf_devmap_val doesn't belong in uapi/linux/bpf.h, because this
is a struct that BPF-progs can define themselves, and can provide different
sizes to the kernel.
While moving the struct change the union to be a named union, with the name
"bpf_prog". This makes it easier to identify with BTF in next patch.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
include/uapi/linux/bpf.h | 9 -------
kernel/bpf/devmap.c | 25 ++++++++++++++------
tools/include/uapi/linux/bpf.h | 9 -------
.../selftests/bpf/prog_tests/xdp_devmap_attach.c | 18 ++++++++++----
.../bpf/progs/test_xdp_with_devmap_helpers.c | 10 +++++++-
5 files changed, 39 insertions(+), 32 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 61ae81bf67de..970c44ecc472 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -3628,15 +3628,6 @@ struct xdp_md {
__u32 egress_ifindex; /* txq->dev->ifindex */
};
-/* DEVMAP values */
-struct bpf_devmap_val {
- __u32 ifindex; /* device index */
- union {
- int bpf_prog_fd; /* prog fd on map write */
- __u32 bpf_prog_id; /* prog id on map read */
- };
-};
-
enum sk_action {
SK_DROP = 0,
SK_PASS,
diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index defdd22caa4b..4ab67b2d8159 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -60,6 +60,15 @@ struct xdp_dev_bulk_queue {
unsigned int count;
};
+/* DEVMAP values */
+struct bpf_devmap_val {
+ __u32 ifindex; /* device index */
+ union {
+ int fd; /* prog fd on map write */
+ __u32 id; /* prog id on map read */
+ } bpf_prog;
+};
+
struct bpf_dtab_netdev {
struct net_device *dev; /* must be first member, due to tracepoint */
struct hlist_node index_hlist;
@@ -117,7 +126,7 @@ static int dev_map_init_map(struct bpf_dtab *dtab, union bpf_attr *attr)
*/
if (attr->max_entries == 0 || attr->key_size != 4 ||
(valsize != offsetofend(struct bpf_devmap_val, ifindex) &&
- valsize != offsetofend(struct bpf_devmap_val, bpf_prog_fd)) ||
+ valsize != offsetofend(struct bpf_devmap_val, bpf_prog.fd)) ||
attr->map_flags & ~DEV_CREATE_FLAG_MASK)
return -EINVAL;
@@ -609,8 +618,8 @@ static struct bpf_dtab_netdev *__dev_map_alloc_node(struct net *net,
if (!dev->dev)
goto err_out;
- if (val->bpf_prog_fd >= 0) {
- prog = bpf_prog_get_type_dev(val->bpf_prog_fd,
+ if (val->bpf_prog.fd >= 0) {
+ prog = bpf_prog_get_type_dev(val->bpf_prog.fd,
BPF_PROG_TYPE_XDP, false);
if (IS_ERR(prog))
goto err_put_dev;
@@ -622,10 +631,10 @@ static struct bpf_dtab_netdev *__dev_map_alloc_node(struct net *net,
dev->dtab = dtab;
if (prog) {
dev->xdp_prog = prog;
- dev->val.bpf_prog_id = prog->aux->id;
+ dev->val.bpf_prog.id = prog->aux->id;
} else {
dev->xdp_prog = NULL;
- dev->val.bpf_prog_id = 0;
+ dev->val.bpf_prog.id = 0;
}
dev->val.ifindex = val->ifindex;
@@ -643,7 +652,7 @@ static int __dev_map_update_elem(struct net *net, struct bpf_map *map,
void *key, void *value, u64 map_flags)
{
struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map);
- struct bpf_devmap_val val = { .bpf_prog_fd = -1 };
+ struct bpf_devmap_val val = { .bpf_prog.fd = -1 };
struct bpf_dtab_netdev *dev, *old_dev;
u32 i = *(u32 *)key;
@@ -660,7 +669,7 @@ static int __dev_map_update_elem(struct net *net, struct bpf_map *map,
if (!val.ifindex) {
dev = NULL;
/* can not specify fd if ifindex is 0 */
- if (val.bpf_prog_fd != -1)
+ if (val.bpf_prog.fd != -1)
return -EINVAL;
} else {
dev = __dev_map_alloc_node(net, dtab, &val, i);
@@ -690,7 +699,7 @@ static int __dev_map_hash_update_elem(struct net *net, struct bpf_map *map,
void *key, void *value, u64 map_flags)
{
struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map);
- struct bpf_devmap_val val = { .bpf_prog_fd = -1 };
+ struct bpf_devmap_val val = { .bpf_prog.fd = -1 };
struct bpf_dtab_netdev *dev, *old_dev;
u32 idx = *(u32 *)key;
unsigned long flags;
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 61ae81bf67de..970c44ecc472 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -3628,15 +3628,6 @@ struct xdp_md {
__u32 egress_ifindex; /* txq->dev->ifindex */
};
-/* DEVMAP values */
-struct bpf_devmap_val {
- __u32 ifindex; /* device index */
- union {
- int bpf_prog_fd; /* prog fd on map write */
- __u32 bpf_prog_id; /* prog id on map read */
- };
-};
-
enum sk_action {
SK_DROP = 0,
SK_PASS,
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
index caeea19f2772..b72a696fc6a8 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
@@ -8,11 +8,19 @@
#define IFINDEX_LO 1
+struct _bpf_devmap_val {
+ __u32 ifindex; /* device index */
+ union {
+ int fd; /* prog fd on map write */
+ __u32 id; /* prog id on map read */
+ } bpf_prog;
+};
+
void test_xdp_with_devmap_helpers(void)
{
struct test_xdp_with_devmap_helpers *skel;
struct bpf_prog_info info = {};
- struct bpf_devmap_val val = {
+ struct _bpf_devmap_val val = {
.ifindex = IFINDEX_LO,
};
__u32 id, len = sizeof(info);
@@ -40,15 +48,15 @@ void test_xdp_with_devmap_helpers(void)
if (CHECK_FAIL(err))
goto out_close;
- val.bpf_prog_fd = dm_fd;
+ val.bpf_prog.fd = dm_fd;
err = bpf_map_update_elem(map_fd, &idx, &val, 0);
CHECK(err, "Add program to devmap entry",
"err %d errno %d\n", err, errno);
err = bpf_map_lookup_elem(map_fd, &id, &val);
CHECK(err, "Read devmap entry", "err %d errno %d\n", err, errno);
- CHECK(info.id != val.bpf_prog_id, "Expected program id in devmap entry",
- "expected %u read %u\n", info.id, val.bpf_prog_id);
+ CHECK(info.id != val.bpf_prog.id, "Expected program id in devmap entry",
+ "expected %u read %u\n", info.id, val.bpf_prog.id);
/* can not attach BPF_XDP_DEVMAP program to a device */
err = bpf_set_link_xdp_fd(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE);
@@ -56,7 +64,7 @@ void test_xdp_with_devmap_helpers(void)
"should have failed\n");
val.ifindex = 1;
- val.bpf_prog_fd = bpf_program__fd(skel->progs.xdp_dummy_prog);
+ val.bpf_prog.fd = bpf_program__fd(skel->progs.xdp_dummy_prog);
err = bpf_map_update_elem(map_fd, &idx, &val, 0);
CHECK(err == 0, "Add non-BPF_XDP_DEVMAP program to devmap entry",
"should have failed\n");
diff --git a/tools/testing/selftests/bpf/progs/test_xdp_with_devmap_helpers.c b/tools/testing/selftests/bpf/progs/test_xdp_with_devmap_helpers.c
index 645f7f415857..126f6de514a1 100644
--- a/tools/testing/selftests/bpf/progs/test_xdp_with_devmap_helpers.c
+++ b/tools/testing/selftests/bpf/progs/test_xdp_with_devmap_helpers.c
@@ -3,10 +3,18 @@
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
+struct _bpf_devmap_val {
+ __u32 ifindex; /* device index */
+ union {
+ int fd; /* prog fd on map write */
+ __u32 id; /* prog id on map read */
+ } bpf_prog;
+};
+
struct {
__uint(type, BPF_MAP_TYPE_DEVMAP);
__uint(key_size, sizeof(__u32));
- __uint(value_size, sizeof(struct bpf_devmap_val));
+ __uint(value_size, sizeof(struct _bpf_devmap_val));
__uint(max_entries, 4);
} dm_ports SEC(".maps");
next prev parent reply other threads:[~2020-05-29 15:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-29 15:59 [PATCH bpf-next RFC 0/3] bpf: dynamic map-value config layout via BTF Jesper Dangaard Brouer
2020-05-29 15:59 ` Jesper Dangaard Brouer [this message]
2020-05-29 16:06 ` [PATCH bpf-next RFC 1/3] bpf: move struct bpf_devmap_val out of UAPI David Ahern
2020-05-29 16:28 ` Jesper Dangaard Brouer
2020-05-29 15:59 ` [PATCH bpf-next RFC 2/3] bpf: devmap dynamic map-value storage area based on BTF Jesper Dangaard Brouer
2020-05-29 16:39 ` Toke Høiland-Jørgensen
2020-06-02 8:59 ` Jesper Dangaard Brouer
2020-06-02 9:23 ` Toke Høiland-Jørgensen
2020-06-02 10:01 ` Jesper Dangaard Brouer
2020-05-30 7:19 ` Andrii Nakryiko
2020-05-30 14:36 ` Jesper Dangaard Brouer
2020-06-01 21:30 ` Alexei Starovoitov
2020-06-02 7:00 ` Jesper Dangaard Brouer
2020-06-02 18:27 ` Alexei Starovoitov
2020-06-03 9:11 ` Jesper Dangaard Brouer
2020-06-03 16:20 ` Alexei Starovoitov
2020-05-29 15:59 ` [PATCH bpf-next RFC 3/3] samples/bpf: change xdp_fwd to use new BTF config interface Jesper Dangaard Brouer
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=159076798058.1387573.3077178618799401182.stgit@firesoul \
--to=brouer@redhat.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=borkmann@iogearbox.net \
--cc=bpf@vger.kernel.org \
--cc=dsahern@gmail.com \
--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).