]> granicus.if.org Git - strace/commitdiff
bpf: update BPF_MAP_CREATE decoding
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 27 Jul 2017 00:44:31 +0000 (00:44 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 27 Jul 2017 00:44:31 +0000 (00:44 +0000)
Implement decoding of map_flags and inner_map_fd fields of union bpf_attr
for BPF_MAP_CREATE command introduced by linux kernel commits
v4.6-rc1~91^2~108^2~6 and v4.12-rc1~64^3~373^2~2, respectively.

* configure.ac: Check for inner_map_fd member of union bpf_attr
instead of max_entries.
* xlat/bpf_map_flags.in: New file.
* bpf.c: Include "xlat/bpf_map_flags.h".
(decode_BPF_MAP_CREATE): Add map_flags and inner_map_fd fields
to the structure, print them.
* tests/bpf.c: Update macro guards of BPF_MAP_CREATE decoder test.
(init_BPF_MAP_CREATE_first, print_BPF_MAP_CREATE_attr): Update expected
output.
(init_BPF_MAP_CREATE_attr): Initialize map_flags and inner_map_fd
fields, update offset.

bpf.c
configure.ac
tests/bpf.c
xlat/bpf_map_flags.in [new file with mode: 0644]

diff --git a/bpf.c b/bpf.c
index 19109b5de10a1bfcd1bc8e0a85a207d55c84c6d4..c4f5074ed5daf8d7a3fa28503091653d351ccdc1 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -35,6 +35,7 @@
 
 #include "xlat/bpf_commands.h"
 #include "xlat/bpf_map_types.h"
+#include "xlat/bpf_map_flags.h"
 #include "xlat/bpf_prog_types.h"
 #include "xlat/bpf_prog_flags.h"
 #include "xlat/bpf_map_update_elem_flags.h"
@@ -88,7 +89,8 @@ decode_attr_extra_data(struct tcb *const tcp,
 DEF_BPF_CMD_DECODER(BPF_MAP_CREATE)
 {
        struct {
-               uint32_t map_type, key_size, value_size, max_entries;
+               uint32_t map_type, key_size, value_size, max_entries,
+                        map_flags, inner_map_fd;
        } attr = {};
        const unsigned int len = size < sizeof(attr) ? size : sizeof(attr);
 
@@ -99,6 +101,8 @@ DEF_BPF_CMD_DECODER(BPF_MAP_CREATE)
        PRINT_FIELD_U(", ", attr, key_size);
        PRINT_FIELD_U(", ", attr, value_size);
        PRINT_FIELD_U(", ", attr, max_entries);
+       PRINT_FIELD_FLAGS(", ", attr, map_flags, bpf_map_flags, "BPF_F_???");
+       PRINT_FIELD_FD(", ", attr, inner_map_fd, tcp);
        decode_attr_extra_data(tcp, data, size, sizeof(attr));
        tprints("}");
 
index 27a2ea12df8f3f0e3d92fe35d584e09b51ddde4e..7a9abf8fe0362a26aa6f077626cd5a169a067b4d 100644 (file)
@@ -431,7 +431,7 @@ AC_CHECK_HEADERS([linux/bpf.h], [
        st_CHECK_UNION_BPF_ATTR([attach_flags])
        st_CHECK_UNION_BPF_ATTR([bpf_fd])
        st_CHECK_UNION_BPF_ATTR([flags])
-       st_CHECK_UNION_BPF_ATTR([max_entries])
+       st_CHECK_UNION_BPF_ATTR([inner_map_fd])
        st_CHECK_UNION_BPF_ATTR([prog_flags])
 ])
 
index 83a92a901a052b7bf19fc00bf564ddfb8e519923..20a776c463df4c4959485d5029f17bd54537cead 100644 (file)
@@ -34,7 +34,7 @@
  && (defined HAVE_UNION_BPF_ATTR_ATTACH_FLAGS  \
   || defined HAVE_UNION_BPF_ATTR_BPF_FD                \
   || defined HAVE_UNION_BPF_ATTR_FLAGS         \
-  || defined HAVE_UNION_BPF_ATTR_MAX_ENTRIES   \
+  || defined HAVE_UNION_BPF_ATTR_INNER_MAP_FD  \
   || defined HAVE_UNION_BPF_ATTR_PROG_FLAGS)
 
 # include <stddef.h>
@@ -183,7 +183,7 @@ sys_bpf(kernel_ulong_t cmd, kernel_ulong_t attr, kernel_ulong_t size)
                  init_ ## cmd_ ## _attr, print_ ## cmd_ ## _attr)      \
        /* End of TEST_BPF definition. */
 
-# ifdef HAVE_UNION_BPF_ATTR_MAX_ENTRIES
+# ifdef HAVE_UNION_BPF_ATTR_INNER_MAP_FD
 
 static unsigned int
 init_BPF_MAP_CREATE_first(const unsigned long eop)
@@ -199,8 +199,8 @@ init_BPF_MAP_CREATE_first(const unsigned long eop)
 static void
 print_BPF_MAP_CREATE_first(const unsigned long addr)
 {
-       printf("map_type=BPF_MAP_TYPE_ARRAY, key_size=0"
-              ", value_size=0, max_entries=0");
+       printf("map_type=BPF_MAP_TYPE_ARRAY, key_size=0, value_size=0"
+              ", max_entries=0, map_flags=0, inner_map_fd=0");
 }
 
 static unsigned int
@@ -210,10 +210,12 @@ init_BPF_MAP_CREATE_attr(const unsigned long eop)
                .map_type = 1,
                .key_size = 4,
                .value_size = 8,
-               .max_entries = 256
+               .max_entries = 256,
+               .map_flags = 1,
+               .inner_map_fd = -1
        };
        static const unsigned int offset =
-               offsetofend(union bpf_attr, max_entries);
+               offsetofend(union bpf_attr, inner_map_fd);
        const unsigned long addr = eop - offset;
 
        memcpy((void *) addr, &attr, offset);
@@ -224,10 +226,11 @@ static void
 print_BPF_MAP_CREATE_attr(const unsigned long addr)
 {
        printf("map_type=BPF_MAP_TYPE_HASH, key_size=4"
-              ", value_size=8, max_entries=256");
+              ", value_size=8, max_entries=256"
+              ", map_flags=BPF_F_NO_PREALLOC, inner_map_fd=-1");
 }
 
-# endif /* HAVE_UNION_BPF_ATTR_MAX_ENTRIES */
+# endif /* HAVE_UNION_BPF_ATTR_INNER_MAP_FD */
 
 # ifdef HAVE_UNION_BPF_ATTR_FLAGS
 
@@ -544,7 +547,7 @@ main(void)
        page_size = get_page_size();
        end_of_page = (unsigned long) tail_alloc(1) + 1;
 
-# ifdef HAVE_UNION_BPF_ATTR_MAX_ENTRIES
+# ifdef HAVE_UNION_BPF_ATTR_INNER_MAP_FD
        TEST_BPF(BPF_MAP_CREATE);
 # endif
 
diff --git a/xlat/bpf_map_flags.in b/xlat/bpf_map_flags.in
new file mode 100644 (file)
index 0000000..6333800
--- /dev/null
@@ -0,0 +1 @@
+BPF_F_NO_PREALLOC      1