[PATCH v2] bpf: support new commands BPF_MAP_*_BATCH
Paul Chaignon
paul.chaignon at gmail.com
Sun Mar 8 17:33:54 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>
---
Changelogs:
Changes in v2:
- Add ATTRIBUTE_ALIGNED(8) to uint64_t attributes.
- Rebase on master.
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 8c2ddfda..bbf03cc6 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,9 @@ Noteworthy changes in release ?.? (????-??-??)
* Ability to set precision for the absolute timestamp, relative timestamp,
and syscall time output (using --absolute-timestamps,
--relative-timestamps, and --syscall-times options, respectively).
+ * 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 c432181c..4ed034e9 100644
--- a/bpf.c
+++ b/bpf.c
@@ -954,6 +954,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[] = {
@@ -981,6 +1000,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 cb6ef0a3..b229d11e 100644
--- a/bpf_attr.h
+++ b/bpf_attr.h
@@ -361,4 +361,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 ATTRIBUTE_ALIGNED(8) elem_flags;
+ uint64_t ATTRIBUTE_ALIGNED(8) 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 c72bc9d9..6bcbe764 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -80,6 +80,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];
};
@@ -1316,6 +1317,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_) \
{ \
@@ -1352,6 +1378,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