From 2d95b53db422529a6e0dba1662f6375794b8a851 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sun, 19 Nov 2017 23:38:58 +0000 Subject: [PATCH] bpf: update BPF_MAP_CREATE decoding 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 | 1 + bpf.c | 4 +++- configure.ac | 2 +- tests/bpf.c | 18 ++++++++++-------- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 45c32e5c..d1d7972d 100644 --- 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 7734b07a..4507d5e3 100644 --- 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("}"); diff --git a/configure.ac b/configure.ac index 4927a63a..b077791a 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) ]) diff --git a/tests/bpf.c b/tests/bpf.c index bec30f87..810f6cbd 100644 --- a/tests/bpf.c +++ b/tests/bpf.c @@ -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 @@ -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 -- 2.40.0