[PATCH 4/4] bpf: support new commands BPF_MAP_*_BATCH
Paul Chaignon
paul.chaignon at gmail.com
Sun Feb 23 10:13:36 UTC 2020
* xlat/bpf_commands.in (BPF_MAP_LOOKUP_BATCH): New constant introduced
by Linux commit v5.6-rc1~151^2~46^2~23^2~7.
(BPF_MAP_LOOKUP_AND_DELETE_BATCH): New constant introduced by Linux
commit v5.6-rc1~151^2~46^2~23^2~4.
(BPF_MAP_UPDATE_BATCH, BPF_MAP_DELETE_BATCH): New constants introduced
by Linux commit v5.6-rc1~151^2~46^2~23^2~6.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_BATCH),
BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_AND_DELETE_BATCH),
BEGIN_BPF_CMD_DECODER(BPF_MAP_UPDATE_BATCH),
BEGIN_BPF_CMD_DECODER(BPF_MAP_DELETE_BATCH)): Decode the new commands.
* bpf_attr.h (BPF_MAP_LOOKUP_BATCH_struct,
BPF_MAP_LOOKUP_AND_DELETE_BATCH_struct, BPF_MAP_UPDATE_BATCH_struct,
BPF_MAP_DELETE_BATCH_struct): New structs introduced by Linux commit
v5.6-rc1~151^2~46^2~23^2~7.
* NEWS: Mention this.
* tests/bpf.c (BPF_MAP_LOOKUP_BATCH_checks): Tests for the new commands.
Signed-off-by: Paul Chaignon <paul.chaignon at gmail.com>
---
NEWS | 3 +++
bpf.c | 23 +++++++++++++++++++++++
bpf_attr.h | 24 ++++++++++++++++++++++++
tests/bpf.c | 27 +++++++++++++++++++++++++++
xlat/bpf_commands.in | 4 ++++
5 files changed, 81 insertions(+)
diff --git a/NEWS b/NEWS
index 4c7ebe1c..e68f2ada 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ Noteworthy changes in release ?.? (????-??-??)
==============================================
* Improvements
+ * Implemented decoding of BPF_MAP_LOOKUP_BATCH,
+ BPF_MAP_LOOKUP_AND_DELETE_BATCH, BPF_MAP_UPDATE_BATCH, and
+ BPF_MAP_DELETE_BATCH bpf syscall commands.
* Enhanced decoding of BPF_MAP_CREATE and BPF_PROG_ATTACH bpf syscall
commands.
* Updated lists of BPF_* constants.
diff --git a/bpf.c b/bpf.c
index b2335d69..bcb70d8a 100644
--- a/bpf.c
+++ b/bpf.c
@@ -949,6 +949,25 @@ BEGIN_BPF_CMD_DECODER(BPF_TASK_FD_QUERY)
}
END_BPF_CMD_DECODER(RVAL_DECODED)
+BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_BATCH)
+{
+ PRINT_FIELD_ADDR64("{", attr, in_batch);
+ PRINT_FIELD_ADDR64(", ", attr, out_batch);
+ PRINT_FIELD_ADDR64(", ", attr, keys);
+ PRINT_FIELD_ADDR64(", ", attr, values);
+ PRINT_FIELD_U(", ", attr, count);
+ PRINT_FIELD_FD(", ", attr, map_fd, tcp);
+ PRINT_FIELD_FLAGS(", ", attr, elem_flags, bpf_map_lookup_elem_flags,
+ "BPF_???");
+ PRINT_FIELD_U64(", ", attr, flags);
+
+}
+END_BPF_CMD_DECODER(RVAL_DECODED)
+
+#define decode_BPF_MAP_LOOKUP_AND_DELETE_BATCH decode_BPF_MAP_LOOKUP_BATCH
+#define decode_BPF_MAP_UPDATE_BATCH decode_BPF_MAP_LOOKUP_BATCH
+#define decode_BPF_MAP_DELETE_BATCH decode_BPF_MAP_LOOKUP_BATCH
+
SYS_FUNC(bpf)
{
static const bpf_cmd_decoder_t bpf_cmd_decoders[] = {
@@ -976,6 +995,10 @@ SYS_FUNC(bpf)
BPF_CMD_ENTRY(BPF_MAP_LOOKUP_AND_DELETE_ELEM),
BPF_CMD_ENTRY(BPF_MAP_FREEZE),
BPF_CMD_ENTRY(BPF_BTF_GET_NEXT_ID),
+ BPF_CMD_ENTRY(BPF_MAP_LOOKUP_BATCH),
+ BPF_CMD_ENTRY(BPF_MAP_LOOKUP_AND_DELETE_BATCH),
+ BPF_CMD_ENTRY(BPF_MAP_UPDATE_BATCH),
+ BPF_CMD_ENTRY(BPF_MAP_DELETE_BATCH),
};
const unsigned int cmd = tcp->u_arg[0];
diff --git a/bpf_attr.h b/bpf_attr.h
index e4826ec0..db5cb6c9 100644
--- a/bpf_attr.h
+++ b/bpf_attr.h
@@ -360,4 +360,28 @@ struct bpf_prog_info_struct {
sizeof(struct bpf_prog_info_struct)
# define expected_bpf_prog_info_struct_size 208
+struct BPF_MAP_LOOKUP_BATCH_struct /* batch */ {
+ uint64_t ATTRIBUTE_ALIGNED(8) in_batch;
+ uint64_t ATTRIBUTE_ALIGNED(8) out_batch;
+ uint64_t ATTRIBUTE_ALIGNED(8) keys;
+ uint64_t ATTRIBUTE_ALIGNED(8) values;
+ uint32_t count;
+ uint32_t map_fd;
+ uint64_t elem_flags;
+ uint64_t flags;
+};
+
+# define BPF_MAP_LOOKUP_BATCH_struct_size \
+ sizeof(struct BPF_MAP_LOOKUP_BATCH_struct)
+# define expected_BPF_MAP_LOOKUP_BATCH_struct_size 56
+
+# define BPF_MAP_LOOKUP_AND_DELETE_BATCH_struct BPF_MAP_LOOKUP_BATCH_struct
+# define BPF_MAP_LOOKUP_AND_DELETE_BATCH_struct_size BPF_MAP_LOOKUP_BATCH_struct_size
+
+# define BPF_MAP_UPDATE_BATCH_struct BPF_MAP_LOOKUP_BATCH_struct
+# define BPF_MAP_UPDATE_BATCH_struct_size BPF_MAP_LOOKUP_BATCH_struct_size
+
+# define BPF_MAP_DELETE_BATCH_struct BPF_MAP_LOOKUP_BATCH_struct
+# define BPF_MAP_DELETE_BATCH_struct_size BPF_MAP_LOOKUP_BATCH_struct_size
+
#endif /* !STRACE_BPF_ATTR_H */
diff --git a/tests/bpf.c b/tests/bpf.c
index d9e349af..8166f1dc 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -79,6 +79,7 @@ union bpf_attr_data {
BPF_ATTR_DATA_FIELD(BPF_BTF_GET_FD_BY_ID);
BPF_ATTR_DATA_FIELD(BPF_TASK_FD_QUERY);
BPF_ATTR_DATA_FIELD(BPF_MAP_FREEZE);
+ BPF_ATTR_DATA_FIELD(BPF_MAP_LOOKUP_BATCH);
char char_data[256];
};
@@ -1280,6 +1281,31 @@ static const struct bpf_attr_check BPF_TASK_FD_QUERY_checks[] = {
}
};
+static const struct bpf_attr_check BPF_MAP_LOOKUP_BATCH_checks[] = {
+ {
+ .data = { .BPF_MAP_LOOKUP_BATCH_data = { .map_fd = -1 } },
+ .size = offsetofend(struct BPF_MAP_LOOKUP_BATCH_struct, map_fd ),
+ .str = "in_batch=NULL, out_batch=NULL, keys=NULL, values=NULL"
+ ", count=0, map_fd=-1, elem_flags=BPF_ANY, flags=0"
+ },
+ {
+ .data = { .BPF_MAP_LOOKUP_BATCH_data = {
+ .in_batch = 0xfacefeed,
+ .out_batch = 0xbadc0ded,
+ .keys = 0xdeadf00d,
+ .values = 0xfffffffe,
+ .count = 3,
+ .map_fd = -1,
+ .elem_flags = 4,
+ .flags = 4
+ } },
+ .size = offsetofend(struct BPF_MAP_LOOKUP_BATCH_struct, flags),
+ .str = "in_batch=0xfacefeed, out_batch=0xbadc0ded"
+ ", keys=0xdeadf00d, values=0xfffffffe, count=3"
+ ", map_fd=-1, elem_flags=BPF_F_LOCK, flags=4"
+ }
+};
+
#define CHK(cmd_) \
{ \
@@ -1316,6 +1342,7 @@ main(void)
CHK(BPF_MAP_LOOKUP_AND_DELETE_ELEM),
CHK(BPF_MAP_FREEZE),
CHK(BPF_BTF_GET_NEXT_ID),
+ CHK(BPF_MAP_LOOKUP_BATCH),
};
page_size = get_page_size();
diff --git a/xlat/bpf_commands.in b/xlat/bpf_commands.in
index 63166fb5..2b95264b 100644
--- a/xlat/bpf_commands.in
+++ b/xlat/bpf_commands.in
@@ -23,3 +23,7 @@ BPF_TASK_FD_QUERY 20
BPF_MAP_LOOKUP_AND_DELETE_ELEM 21
BPF_MAP_FREEZE 22
BPF_BTF_GET_NEXT_ID 23
+BPF_MAP_LOOKUP_BATCH 24
+BPF_MAP_LOOKUP_AND_DELETE_BATCH 25
+BPF_MAP_UPDATE_BATCH 26
+BPF_MAP_DELETE_BATCH 27
--
2.20.1
More information about the Strace-devel
mailing list