From: Lorenz Bauer <lmb@cloudflare.com>
To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net
Cc: bpf@vger.kernel.org, kernel-team@cloudflare.com,
Lorenz Bauer <lmb@cloudflare.com>
Subject: [RFC 7/9] bpf: split get_id and fd_by_id in bpf_attr
Date: Thu, 14 Oct 2021 15:34:33 +0100 [thread overview]
Message-ID: <20211014143436.54470-10-lmb@cloudflare.com> (raw)
In-Reply-To: <20211014143436.54470-1-lmb@cloudflare.com>
---
include/uapi/linux/bpf.h | 60 ++++++++++++++++++++++++++++++++--------
kernel/bpf/syscall.c | 18 ++++++------
2 files changed, 58 insertions(+), 20 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index d3acd12d98c1..13d126c201ce 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1422,17 +1422,43 @@ union bpf_attr {
__u32 cpu;
} test;
- struct { /* anonymous struct used by BPF_*_GET_*_ID */
- union {
- __u32 start_id;
- __u32 prog_id;
- __u32 map_id;
- __u32 btf_id;
- __u32 link_id;
- };
- __u32 next_id;
- __u32 open_flags;
- };
+ struct { /* used by BPF_PROG_GET_FD_BY_ID command */
+ __u32 id;
+ } prog_get_fd_by_id;
+
+ struct { /* used by BPF_MAP_GET_FD_BY_ID command */
+ __u32 id;
+ __u32 ingnored;
+ __u32 open_flags;
+ } map_get_fd_by_id;
+
+ struct { /* used by BPF_BTF_GET_FD_BY_ID command */
+ __u32 id;
+ } btf_get_fd_by_id;
+
+ struct { /* used by BPF_LINK_GET_FD_BY_ID command */
+ __u32 id;
+ } link_get_fd_by_id;
+
+ struct { /* used by BPF_PROG_GET_NEXT_ID command */
+ __u32 start_id;
+ __u32 next_id;
+ } prog_get_next_id;
+
+ struct { /* used by BPF_MAP_GET_NEXT_ID command */
+ __u32 start_id;
+ __u32 next_id;
+ } map_get_next_id;
+
+ struct { /* used by BPF_BTF_GET_NEXT_ID command */
+ __u32 start_id;
+ __u32 next_id;
+ } btf_get_next_id;
+
+ struct { /* used by BPF_LINK_GET_NEXT_ID command */
+ __u32 start_id;
+ __u32 next_id;
+ } link_get_next_id;
struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
__u32 bpf_fd;
@@ -1557,6 +1583,18 @@ union bpf_attr {
};
__u64 flags;
};
+
+ struct { /* anonymous struct used by BPF_*_GET_*_ID */
+ union {
+ __u32 start_id;
+ __u32 prog_id;
+ __u32 map_id;
+ __u32 btf_id;
+ __u32 link_id;
+ };
+ __u32 next_id;
+ __u32 open_flags;
+ };
} __attribute__((aligned(8)));
/* The description below is an attempt at providing documentation to eBPF
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index c4aecdbb390e..234860bd05bf 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3367,7 +3367,7 @@ struct bpf_prog *bpf_prog_get_curr_or_next(u32 *id)
return prog;
}
-#define BPF_PROG_GET_FD_BY_ID_LAST_FIELD prog_id
+#define BPF_PROG_GET_FD_BY_ID_LAST_FIELD prog_get_fd_by_id.id
struct bpf_prog *bpf_prog_by_id(u32 id)
{
@@ -3389,7 +3389,7 @@ struct bpf_prog *bpf_prog_by_id(u32 id)
static int bpf_prog_get_fd_by_id(const union bpf_attr *attr)
{
struct bpf_prog *prog;
- u32 id = attr->prog_id;
+ u32 id = attr->prog_get_fd_by_id.id;
int fd;
if (CHECK_ATTR(BPF_PROG_GET_FD_BY_ID))
@@ -3409,12 +3409,12 @@ static int bpf_prog_get_fd_by_id(const union bpf_attr *attr)
return fd;
}
-#define BPF_MAP_GET_FD_BY_ID_LAST_FIELD open_flags
+#define BPF_MAP_GET_FD_BY_ID_LAST_FIELD map_get_fd_by_id.open_flags
static int bpf_map_get_fd_by_id(const union bpf_attr *attr)
{
struct bpf_map *map;
- u32 id = attr->map_id;
+ u32 id = attr->map_get_fd_by_id.id;
int f_flags;
int fd;
@@ -3425,7 +3425,7 @@ static int bpf_map_get_fd_by_id(const union bpf_attr *attr)
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- f_flags = bpf_get_file_flag(attr->open_flags);
+ f_flags = bpf_get_file_flag(attr->map_get_fd_by_id.open_flags);
if (f_flags < 0)
return f_flags;
@@ -3984,7 +3984,7 @@ static int bpf_btf_load(const union bpf_attr *attr, bpfptr_t uattr)
return btf_new_fd(attr, uattr);
}
-#define BPF_BTF_GET_FD_BY_ID_LAST_FIELD btf_id
+#define BPF_BTF_GET_FD_BY_ID_LAST_FIELD btf_get_fd_by_id.id
static int bpf_btf_get_fd_by_id(const union bpf_attr *attr)
{
@@ -3994,7 +3994,7 @@ static int bpf_btf_get_fd_by_id(const union bpf_attr *attr)
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- return btf_get_fd_by_id(attr->btf_id);
+ return btf_get_fd_by_id(attr->btf_get_fd_by_id.id);
}
static int bpf_task_fd_query_copy(const union bpf_attr *attr,
@@ -4369,12 +4369,12 @@ struct bpf_link *bpf_link_by_id(u32 id)
return link;
}
-#define BPF_LINK_GET_FD_BY_ID_LAST_FIELD link_id
+#define BPF_LINK_GET_FD_BY_ID_LAST_FIELD link_get_fd_by_id.id
static int bpf_link_get_fd_by_id(const union bpf_attr *attr)
{
struct bpf_link *link;
- u32 id = attr->link_id;
+ u32 id = attr->link_get_fd_by_id.id;
int fd;
if (CHECK_ATTR(BPF_LINK_GET_FD_BY_ID))
--
2.30.2
next prev parent reply other threads:[~2021-10-14 14:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-14 14:34 [RFC 0/9] uapi/bpf.h for robots Lorenz Bauer
2021-10-14 14:34 ` [RFC 1/9] bpf: name enums used from userspace Lorenz Bauer
2021-10-14 14:34 ` [RFC 2/9] bpf: various constants Lorenz Bauer
2021-10-14 14:43 ` Greg KH
2021-10-14 14:47 ` Lorenz Bauer
2021-10-14 14:56 ` Greg KH
2021-10-14 14:34 ` [RFC 3/9] bpf: move up __bpf_md_ptr Lorenz Bauer
2021-10-14 14:34 ` [RFC 4/9] bpf: name __u64 member of __bpf_md_ptr Lorenz Bauer
2021-10-14 14:34 ` [RFC 5/9] bpf: enum bpf_map_create_attr Lorenz Bauer
2021-10-14 14:34 ` [RFC 5/9] bpf: introduce CHECK_ATTR_TAIL Lorenz Bauer
2021-10-14 14:34 ` [RFC 6/9] bpf: split map modification structs Lorenz Bauer
2021-10-20 17:13 ` Alexei Starovoitov
2021-10-14 14:34 ` [RFC 6/9] bpf: struct bpf_map_create_attr Lorenz Bauer
2021-10-14 14:34 ` Lorenz Bauer [this message]
2021-10-20 17:15 ` [RFC 7/9] bpf: split get_id and fd_by_id in bpf_attr Alexei Starovoitov
2021-10-21 15:59 ` Lorenz Bauer
2021-10-27 18:20 ` Alexei Starovoitov
2021-10-29 14:01 ` Lorenz Bauer
2021-10-14 14:34 ` [RFC 7/9] bpf: split map modification structs Lorenz Bauer
2021-10-14 14:34 ` [RFC 8/9] selftests: sync bpf.h Lorenz Bauer
2021-10-14 14:34 ` [RFC 9/9] libbpf: use new-style syscall args Lorenz Bauer
2021-10-20 17:19 ` Alexei Starovoitov
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=20211014143436.54470-10-lmb@cloudflare.com \
--to=lmb@cloudflare.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@cloudflare.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).