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.
This commit is contained in:
1
NEWS
1
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)
|
||||
|
4
bpf.c
4
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("}");
|
||||
|
||||
|
@ -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])
|
||||
])
|
||||
|
||||
|
18
tests/bpf.c
18
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 <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
|
||||
|
||||
|
Reference in New Issue
Block a user