]> granicus.if.org Git - strace/commitdiff
bpf: update BPF_MAP_CREATE decoding
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 19 Nov 2017 23:38:58 +0000 (23:38 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 20 Nov 2017 21:39:59 +0000 (21:39 +0000)
Implement decoding of union bpf_attr.numa_node field for BPF_MAP_CREATE
command introduced by linux kernel commit v4.14-rc1~130^2~196^2~1.

* configure.ac: Check for numa_node member of union bpf_attr
instead of inner_map_fd.
(decode_BPF_MAP_CREATE): Add numa_node field to the structure, print it.
* NEWS: Mention this.
* 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 numa_node field, update offset.

NEWS
bpf.c
configure.ac
tests/bpf.c

diff --git a/NEWS b/NEWS
index 45c32e5cfa6ce19ef3f8ee1458e3c78fefca8afd..d1d7972d78eff32d9a9ee60b18d50e4a90588d8d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ Noteworthy changes in release ?.?? (????-??-??)
   * Implemented decoding of hugetlb page size selection flags.
   * Enhanced decoding of getsockopt and setsockopt syscalls for SOL_NETLINK
     level.
+  * Enhanced decoding of BPF_MAP_CREATE command of bpf syscall.
   * Updated lists of MSG_* and SHM_* constants.
 
 Noteworthy changes in release 4.20 (2017-11-13)
diff --git a/bpf.c b/bpf.c
index 7734b07ab80e307823cb370b5fc90519d38dcee0..4507d5e36dc35587c428f590042e3ed804c307ae 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -90,7 +90,7 @@ DEF_BPF_CMD_DECODER(BPF_MAP_CREATE)
 {
        struct {
                uint32_t map_type, key_size, value_size, max_entries,
-                        map_flags, inner_map_fd;
+                        map_flags, inner_map_fd, numa_node;
        } attr = {};
        const unsigned int len = size < sizeof(attr) ? size : sizeof(attr);
 
@@ -103,6 +103,8 @@ DEF_BPF_CMD_DECODER(BPF_MAP_CREATE)
        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);
+       if (attr.map_flags & BPF_F_NUMA_NODE)
+               PRINT_FIELD_U(", ", attr, numa_node);
        decode_attr_extra_data(tcp, data, size, sizeof(attr));
        tprints("}");
 
index 4927a63aa0122ea36bd7799f228767fee388449e..b077791a72cee54449b349e13b0a1a27a3d43d1d 100644 (file)
@@ -462,7 +462,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([inner_map_fd])
+       st_CHECK_UNION_BPF_ATTR([numa_node])
        st_CHECK_UNION_BPF_ATTR([prog_flags])
 ])
 
index bec30f87f5520d3fa5ca1ad2642b7473a5c7b8bd..810f6cbde34f7b0e918810f55b7691ee2251c17b 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_INNER_MAP_FD  \
+  || defined HAVE_UNION_BPF_ATTR_NUMA_NODE     \
   || 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_INNER_MAP_FD
+# ifdef HAVE_UNION_BPF_ATTR_NUMA_NODE
 
 static unsigned int
 init_BPF_MAP_CREATE_first(const unsigned long eop)
@@ -211,11 +211,12 @@ init_BPF_MAP_CREATE_attr(const unsigned long eop)
                .key_size = 4,
                .value_size = 8,
                .max_entries = 256,
-               .map_flags = 1,
-               .inner_map_fd = -1
+               .map_flags = 7,
+               .inner_map_fd = -1,
+               .numa_node = 42
        };
        static const unsigned int offset =
-               offsetofend(union bpf_attr, inner_map_fd);
+               offsetofend(union bpf_attr, numa_node);
        const unsigned long addr = eop - offset;
 
        memcpy((void *) addr, &attr, offset);
@@ -227,10 +228,11 @@ 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"
-              ", map_flags=BPF_F_NO_PREALLOC, inner_map_fd=-1");
+              ", map_flags=BPF_F_NO_PREALLOC|BPF_F_NO_COMMON_LRU"
+              "|BPF_F_NUMA_NODE, inner_map_fd=-1, numa_node=42");
 }
 
-# endif /* HAVE_UNION_BPF_ATTR_INNER_MAP_FD */
+# endif /* HAVE_UNION_BPF_ATTR_NUMA_NODE */
 
 # ifdef HAVE_UNION_BPF_ATTR_FLAGS
 
@@ -565,7 +567,7 @@ main(void)
        page_size = get_page_size();
        end_of_page = (unsigned long) tail_alloc(1) + 1;
 
-# ifdef HAVE_UNION_BPF_ATTR_INNER_MAP_FD
+# ifdef HAVE_UNION_BPF_ATTR_NUMA_NODE
        TEST_BPF(BPF_MAP_CREATE);
 # endif