[PATCH v2 1/2] bpf: support new field in BPF_MAP_LOOKUP_ELEM

Paul Chaignon paul.chaignon at gmail.com
Wed Nov 27 14:10:16 UTC 2019


* bpf_attr.h (BPF_MAP_LOOKUP_ELEM_struct): New field introduced by Linux
commit v5.1-rc1~178^2~375^2~4^2~3.
* xlat/bpf_map_lookup_elem_flags.in: New file.
* bpf.c: Include "xlat/bpf_map_lookup_elem_flags.h".
(BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_ELEM)): Decode the new field.
* tests/bpf.c (BPF_MAP_LOOKUP_ELEM_checks): Update expected outputs.

Signed-off-by: Paul Chaignon <paul.chaignon at gmail.com>
---
Changelogs:
  Changes in v2:
    - Fix commit title and message.

 bpf.c                             | 6 ++++++
 bpf_attr.h                        | 3 ++-
 tests/bpf.c                       | 6 ++++--
 xlat/bpf_map_lookup_elem_flags.in | 2 ++
 4 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 xlat/bpf_map_lookup_elem_flags.in

diff --git a/bpf.c b/bpf.c
index d376514d..9b6fb488 100644
--- a/bpf.c
+++ b/bpf.c
@@ -23,6 +23,7 @@
 #include "xlat/bpf_map_flags.h"
 #include "xlat/bpf_prog_types.h"
 #include "xlat/bpf_prog_flags.h"
+#include "xlat/bpf_map_lookup_elem_flags.h"
 #include "xlat/bpf_map_update_elem_flags.h"
 #include "xlat/bpf_attach_type.h"
 #include "xlat/bpf_attach_flags.h"
@@ -231,6 +232,11 @@ BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_ELEM)
 	PRINT_FIELD_FD("{", attr, map_fd, tcp);
 	PRINT_FIELD_ADDR64(", ", attr, key);
 	PRINT_FIELD_ADDR64(", ", attr, value);
+	/* flags field was added in Linux commit v5.1-rc1~178^2~375^2~4^2~3.  */
+	if (len <= offsetof(struct BPF_MAP_LOOKUP_ELEM_struct, flags))
+		break;
+	PRINT_FIELD_FLAGS(", ", attr, flags, bpf_map_lookup_elem_flags,
+			  "BPF_???");
 }
 END_BPF_CMD_DECODER(RVAL_DECODED)
 
diff --git a/bpf_attr.h b/bpf_attr.h
index ac8c9210..6695a2fe 100644
--- a/bpf_attr.h
+++ b/bpf_attr.h
@@ -59,11 +59,12 @@ struct BPF_MAP_LOOKUP_ELEM_struct {
 	uint32_t map_fd;
 	uint64_t ATTRIBUTE_ALIGNED(8) key;
 	uint64_t ATTRIBUTE_ALIGNED(8) value;
+	uint64_t ATTRIBUTE_ALIGNED(8) flags;
 };
 
 # define BPF_MAP_LOOKUP_ELEM_struct_size \
 	sizeof(struct BPF_MAP_LOOKUP_ELEM_struct)
-# define expected_BPF_MAP_LOOKUP_ELEM_struct_size 24
+# define expected_BPF_MAP_LOOKUP_ELEM_struct_size 32
 
 struct BPF_MAP_UPDATE_ELEM_struct {
 	uint32_t map_fd;
diff --git a/tests/bpf.c b/tests/bpf.c
index 71c2f8d4..a1dad79a 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -435,10 +435,12 @@ static const struct bpf_attr_check BPF_MAP_LOOKUP_ELEM_checks[] = {
 		.data = { .BPF_MAP_LOOKUP_ELEM_data = {
 			.map_fd = -1,
 			.key = 0xdeadbeef,
-			.value = 0xbadc0ded
+			.value = 0xbadc0ded,
+			.flags = 4
 		} },
-		.size = offsetofend(struct BPF_MAP_LOOKUP_ELEM_struct, value),
+		.size = offsetofend(struct BPF_MAP_LOOKUP_ELEM_struct, flags),
 		.str = "map_fd=-1, key=0xdeadbeef, value=0xbadc0ded"
+		       ", flags=BPF_F_LOCK"
 	}
 };
 
diff --git a/xlat/bpf_map_lookup_elem_flags.in b/xlat/bpf_map_lookup_elem_flags.in
new file mode 100644
index 00000000..68c936b7
--- /dev/null
+++ b/xlat/bpf_map_lookup_elem_flags.in
@@ -0,0 +1,2 @@
+BPF_ANY 0
+BPF_F_LOCK 4
-- 
2.17.1



More information about the Strace-devel mailing list