Skip to contentSkip to conversation

samples: bpf: refactor BPF map test with libbpf

PATCH Applied Daniel T. Lee 3 participants 9 messages Jul 7, 2020 – Jul 8, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover samples: bpf: refactor BPF map test with libbpf

There have been many changes in how the current bpf program defines map. The development of libbbpf has led to the new method called BTF-defined map, which is a new way of defining BPF maps, and thus has a lot of differences from the existing MAP definition method.

Although bpf_load was also internally using libbbpf, fragmentation in its implementation began to occur, such as using its own structure, bpf_load_map_def, to define the map.

Therefore, in this patch set, map test programs, which are closely related to changes in the definition method of BPF map, were refactored with libbbpf.

---
Changes in V2:
- instead of changing event from __x64_sys_connect to __sys_connect, fetch and set register values directly
- fix wrong error check logic with bpf_program
- set numa_node 0 declaratively at map definition instead of setting it from user-space
- static initialization of ARRAY_OF_MAPS element with '.values'

Daniel T. Lee (4):
samples: bpf: fix bpf programs with kprobe/sys_connect event
samples: bpf: refactor BPF map in map test with libbpf
samples: bpf: refactor BPF map performance test with libbpf
selftests: bpf: remove unused bpf_map_def_legacy struct

 samples/bpf/Makefile                     |   2 +-
 samples/bpf/map_perf_test_kern.c         | 188 ++++++++++++-----------
 samples/bpf/map_perf_test_user.c         | 164 +++++++++++++-------
 samples/bpf/test_map_in_map_kern.c       |  94 ++++++------
 samples/bpf/test_map_in_map_user.c       |  53 ++++++-
 samples/bpf/test_probe_write_user_kern.c |   9 +-
 tools/testing/selftests/bpf/bpf_legacy.h |  14 --
 7 files changed, 305 insertions(+), 219 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/4 samples: bpf: fix bpf programs with kprobe/sys_connect event

Currently, BPF programs with kprobe/sys_connect does not work properly.

Commit 34745aed515c ("samples/bpf: fix kprobe attachment issue on x64") This commit modifies the bpf_load behavior of kprobe events in the x64 architecture. If the current kprobe event target starts with "sys_*", add the prefix "__x64_" to the front of the event.

Appending "__x64_" prefix with kprobe/sys_* event was appropriate as a solution to most of the problems caused by the commit below.

commit d5a00528b58c ("syscalls/core, syscalls/x86: Rename struct pt_regs-based sys_*() to __x64_sys_*()")

However, there is a problem with the sys_connect kprobe event that does not work properly. For __sys_connect event, parameters can be fetched normally, but for __x64_sys_connect, parameters cannot be fetched.

    ffffffff818d3520 <__x64_sys_connect>:
    ffffffff818d3520: e8 fb df 32 00        callq   0xffffffff81c01520
    <__fentry__>
    ffffffff818d3525: 48 8b 57 60           movq    96(%rdi), %rdx
    ffffffff818d3529: 48 8b 77 68           movq    104(%rdi), %rsi
    ffffffff818d352d: 48 8b 7f 70           movq    112(%rdi), %rdi
    ffffffff818d3531: e8 1a ff ff ff        callq   0xffffffff818d3450
    <__sys_connect>
    ffffffff818d3536: 48 98                 cltq
    ffffffff818d3538: c3                    retq
    ffffffff818d3539: 0f 1f 80 00 00 00 00  nopl    (%rax)

As the assembly code for __x64_sys_connect shows, parameters should be fetched and set into rdi, rsi, rdx registers prior to calling __sys_connect.

Because of this problem, this commit fixes the sys_connect event by first getting the value of the rdi register and then the value of the rdi, rsi, and rdx register through an offset based on that value.

Fixes 34745aed515c ("samples/bpf: fix kprobe attachment issue on x64")

---
Changes in V2:
- instead of changing event from __x64_sys_connect to __sys_connect, fetch and set register values directly

 samples/bpf/map_perf_test_kern.c         | 9 ++++++---
 samples/bpf/test_map_in_map_kern.c       | 9 ++++++---
 samples/bpf/test_probe_write_user_kern.c | 9 ++++++---
 3 files changed, 18 insertions(+), 9 deletions(-)
samples/bpf/map_perf_test_kern.c +6 -3
index 12e91ae64d4d..c9b31193ca12 100644
@@ -11,6 +11,8 @@
 #include <bpf/bpf_helpers.h>
 #include "bpf_legacy.h"
 #include <bpf/bpf_tracing.h>
+#include <bpf/bpf_core_read.h>
+#include "trace_common.h"
 
 #define MAX_ENTRIES 1000
 #define MAX_NR_CPUS 1024
@@ -154,9 +156,10 @@ int stress_percpu_hmap_alloc(struct pt_regs *ctx)
 	return 0;
 }
 
-SEC("kprobe/sys_connect")
+SEC("kprobe/" SYSCALL(sys_connect))
 int stress_lru_hmap_alloc(struct pt_regs *ctx)
 {
+	struct pt_regs *real_regs = (struct pt_regs *)PT_REGS_PARM1_CORE(ctx);
 	char fmt[] = "Failed at stress_lru_hmap_alloc. ret:%dn";
 	union {
 		u16 dst6[8];
@@ -175,8 +178,8 @@ int stress_lru_hmap_alloc(struct pt_regs *ctx)
 	long val = 1;
 	u32 key = 0;
 
-	in6 = (struct sockaddr_in6 *)PT_REGS_PARM2(ctx);
-	addrlen = (int)PT_REGS_PARM3(ctx);
+	in6 = (struct sockaddr_in6 *)PT_REGS_PARM2_CORE(real_regs);
+	addrlen = (int)PT_REGS_PARM3_CORE(real_regs);
 
 	if (addrlen != sizeof(*in6))
 		return 0;
samples/bpf/test_map_in_map_kern.c +6 -3
index 6cee61e8ce9b..36a203e69064 100644
@@ -13,6 +13,8 @@
 #include <bpf/bpf_helpers.h>
 #include "bpf_legacy.h"
 #include <bpf/bpf_tracing.h>
+#include <bpf/bpf_core_read.h>
+#include "trace_common.h"
 
 #define MAX_NR_PORTS 65536
 
@@ -102,9 +104,10 @@ static __always_inline int do_inline_hash_lookup(void *inner_map, u32 port)
 	return result ? *result : -ENOENT;
 }
 
-SEC("kprobe/sys_connect")
+SEC("kprobe/" SYSCALL(sys_connect))
 int trace_sys_connect(struct pt_regs *ctx)
 {
+	struct pt_regs *real_regs = (struct pt_regs *)PT_REGS_PARM1_CORE(ctx);
 	struct sockaddr_in6 *in6;
 	u16 test_case, port, dst6[8];
 	int addrlen, ret, inline_ret, ret_key = 0;
@@ -112,8 +115,8 @@ int trace_sys_connect(struct pt_regs *ctx)
 	void *outer_map, *inner_map;
 	bool inline_hash = false;
 
-	in6 = (struct sockaddr_in6 *)PT_REGS_PARM2(ctx);
-	addrlen = (int)PT_REGS_PARM3(ctx);
+	in6 = (struct sockaddr_in6 *)PT_REGS_PARM2_CORE(real_regs);
+	addrlen = (int)PT_REGS_PARM3_CORE(real_regs);
 
 	if (addrlen != sizeof(*in6))
 		return 0;
samples/bpf/test_probe_write_user_kern.c +6 -3
index f033f36a13a3..fd651a65281e 100644
@@ -10,6 +10,8 @@
 #include <linux/version.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
+#include <bpf/bpf_core_read.h>
+#include "trace_common.h"
 
 struct bpf_map_def SEC("maps") dnat_map = {
 	.type = BPF_MAP_TYPE_HASH,
@@ -26,13 +28,14 @@ struct bpf_map_def SEC("maps") dnat_map = {
  * This example sits on a syscall, and the syscall ABI is relatively stable
  * of course, across platforms, and over time, the ABI may change.
  */
-SEC("kprobe/sys_connect")
+SEC("kprobe/" SYSCALL(sys_connect))
 int bpf_prog1(struct pt_regs *ctx)
 {
+	struct pt_regs *real_regs = (struct pt_regs *)PT_REGS_PARM1_CORE(ctx);
+	void *sockaddr_arg = (void *)PT_REGS_PARM2_CORE(real_regs);
+	int sockaddr_len = (int)PT_REGS_PARM3_CORE(real_regs);
 	struct sockaddr_in new_addr, orig_addr = {};
 	struct sockaddr_in *mapped_addr;
-	void *sockaddr_arg = (void *)PT_REGS_PARM2(ctx);
-	int sockaddr_len = (int)PT_REGS_PARM3(ctx);
 
 	if (sockaddr_len > sizeof(orig_addr))
 		return 0;
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/4 samples: bpf: refactor BPF map in map test with libbpf

In reply to Daniel T. Lee

From commit 646f02ffdd49 ("libbpf: Add BTF-defined map-in-map support"), a way to define internal map in BTF-defined map has been added.

Instead of using previous 'inner_map_idx' definition, the structure to be used for the inner map can be directly defined using array directive.

__array(values, struct inner_map)

This commit refactors map in map test program with libbpf by explicitly defining inner map with BTF-defined format.

---
Changes in V2:
- fix wrong error check logic with bpf_program

 samples/bpf/Makefile               |  2 +-
 samples/bpf/test_map_in_map_kern.c | 85 +++++++++++++++---------------
 samples/bpf/test_map_in_map_user.c | 53 +++++++++++++++++--
 3 files changed, 91 insertions(+), 49 deletions(-)
samples/bpf/Makefile +1 -1
index 8403e4762306..f87ee02073ba 100644
@@ -93,7 +93,7 @@ sampleip-objs := sampleip_user.o $(TRACE_HELPERS)
 tc_l2_redirect-objs := bpf_load.o tc_l2_redirect_user.o
 lwt_len_hist-objs := bpf_load.o lwt_len_hist_user.o
 xdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o
-test_map_in_map-objs := bpf_load.o test_map_in_map_user.o
+test_map_in_map-objs := test_map_in_map_user.o
 per_socket_stats_example-objs := cookie_uid_helper_example.o
 xdp_redirect-objs := xdp_redirect_user.o
 xdp_redirect_map-objs := xdp_redirect_map_user.o
samples/bpf/test_map_in_map_kern.c +42 -43

109 lines not on this page · raw message

samples/bpf/test_map_in_map_user.c +48 -5

73 lines not on this page · raw message

Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 3/4 samples: bpf: refactor BPF map performance test with libbpf

In reply to Daniel T. Lee

Previously, in order to set the numa_node attribute at the time of map creation using "libbpf", it was necessary to call bpf_create_map_node() directly (bpf_load approach), instead of calling bpf_object_load() that handles everything on its own, including map creation. And because of this problem, this sample had problems with refactoring from bpf_load to libbbpf.

However, by commit 1bdb6c9a1c43 ("libbpf: Add a bunch of attribute getters/setters for map definitions") added the numa_node attribute and allowed it to be set in the map.

By using libbpf instead of bpf_load, the inner map definition has been explicitly declared with BTF-defined format. Also, the element of ARRAY_OF_MAPS was also statically specified using the BTF format. And for this reason some logic in fixup_map() was not needed and changed or removed.

---
Changes in V2:
- set numa_node 0 declaratively at map definition instead of setting it from user-space
- static initialization of ARRAY_OF_MAPS element with '.values'

 samples/bpf/map_perf_test_kern.c | 179 ++++++++++++++++---------------
 samples/bpf/map_perf_test_user.c | 164 ++++++++++++++++++----------
 2 files changed, 196 insertions(+), 147 deletions(-)
samples/bpf/map_perf_test_kern.c +91 -88
index c9b31193ca12..8773f22b6a98 100644
@@ -9,7 +9,6 @@
 #include <linux/version.h>
 #include <uapi/linux/bpf.h>
 #include <bpf/bpf_helpers.h>
-#include "bpf_legacy.h"
 #include <bpf/bpf_tracing.h>
 #include <bpf/bpf_core_read.h>
 #include "trace_common.h"
@@ -17,89 +16,93 @@
 #define MAX_ENTRIES 1000
 #define MAX_NR_CPUS 1024
 
-struct bpf_map_def_legacy SEC("maps") hash_map = {
-	.type = BPF_MAP_TYPE_HASH,
-	.key_size = sizeof(u32),
-	.value_size = sizeof(long),
-	.max_entries = MAX_ENTRIES,
+struct {
+	__uint(type, BPF_MAP_TYPE_HASH);
+	__type(key, u32);
+	__type(value, long);
+	__uint(max_entries, MAX_ENTRIES);
+} hash_map SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_LRU_HASH);
+	__type(key, u32);
+	__type(value, long);
+	__uint(max_entries, 10000);
+} lru_hash_map SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_LRU_HASH);
+	__type(key, u32);
+	__type(value, long);
+	__uint(max_entries, 10000);
+	__uint(map_flags, BPF_F_NO_COMMON_LRU);
+} nocommon_lru_hash_map SEC(".maps");
+
+struct inner_lru {
+	__uint(type, BPF_MAP_TYPE_LRU_HASH);
+	__type(key, u32);
+	__type(value, long);
+	__uint(max_entries, MAX_ENTRIES);
+	__uint(map_flags, BPF_F_NUMA_NODE);
+	__uint(numa_node, 0);
+} inner_lru_hash_map SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
+	__uint(max_entries, MAX_NR_CPUS);
+	__uint(key_size, sizeof(u32));
+	__array(values, struct inner_lru); /* use inner_lru as inner map */
+} array_of_lru_hashs SEC(".maps") = {
+	/* statically initialize the first element */
+	.values = { &inner_lru_hash_map },
 };
 
-struct bpf_map_def_legacy SEC("maps") lru_hash_map = {
-	.type = BPF_MAP_TYPE_LRU_HASH,
-	.key_size = sizeof(u32),
-	.value_size = sizeof(long),
-	.max_entries = 10000,
-};
-
-struct bpf_map_def_legacy SEC("maps") nocommon_lru_hash_map = {
-	.type = BPF_MAP_TYPE_LRU_HASH,
-	.key_size = sizeof(u32),
-	.value_size = sizeof(long),
-	.max_entries = 10000,
-	.map_flags = BPF_F_NO_COMMON_LRU,
-};
-
-struct bpf_map_def_legacy SEC("maps") inner_lru_hash_map = {
-	.type = BPF_MAP_TYPE_LRU_HASH,
-	.key_size = sizeof(u32),
-	.value_size = sizeof(long),
-	.max_entries = MAX_ENTRIES,
-	.map_flags = BPF_F_NUMA_NODE,
-	.numa_node = 0,
-};
-
-struct bpf_map_def_legacy SEC("maps") array_of_lru_hashs = {
-	.type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
-	.key_size = sizeof(u32),
-	.max_entries = MAX_NR_CPUS,
-};
-
-struct bpf_map_def_legacy SEC("maps") percpu_hash_map = {
-	.type = BPF_MAP_TYPE_PERCPU_HASH,
-	.key_size = sizeof(u32),
-	.value_size = sizeof(long),
-	.max_entries = MAX_ENTRIES,
-};
-
-struct bpf_map_def_legacy SEC("maps") hash_map_alloc = {
-	.type = BPF_MAP_TYPE_HASH,
-	.key_size = sizeof(u32),
-	.value_size = sizeof(long),
-	.max_entries = MAX_ENTRIES,
-	.map_flags = BPF_F_NO_PREALLOC,
-};
-
-struct bpf_map_def_legacy SEC("maps") percpu_hash_map_alloc = {
-	.type = BPF_MAP_TYPE_PERCPU_HASH,
-	.key_size = sizeof(u32),
-	.value_size = sizeof(long),
-	.max_entries = MAX_ENTRIES,
-	.map_flags = BPF_F_NO_PREALLOC,
-};
-
-struct bpf_map_def_legacy SEC("maps") lpm_trie_map_alloc = {
-	.type = BPF_MAP_TYPE_LPM_TRIE,
-	.key_size = 8,
-	.value_size = sizeof(long),
-	.max_entries = 10000,
-	.map_flags = BPF_F_NO_PREALLOC,
-};
-
-struct bpf_map_def_legacy SEC("maps") array_map = {
-	.type = BPF_MAP_TYPE_ARRAY,
-	.key_size = sizeof(u32),
-	.value_size = sizeof(long),
-	.max_entries = MAX_ENTRIES,
-};
-
-struct bpf_map_def_legacy SEC("maps") lru_hash_lookup_map = {
-	.type = BPF_MAP_TYPE_LRU_HASH,
-	.key_size = sizeof(u32),
-	.value_size = sizeof(long),
-	.max_entries = MAX_ENTRIES,
-};
-
-SEC("kprobe/sys_getuid")
+struct {
+	__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
+	__uint(key_size, sizeof(u32));
+	__uint(value_size, sizeof(long));
+	__uint(max_entries, MAX_ENTRIES);
+} percpu_hash_map SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_HASH);
+	__type(key, u32);
+	__type(value, long);
+	__uint(max_entries, MAX_ENTRIES);
+	__uint(map_flags, BPF_F_NO_PREALLOC);
+} hash_map_alloc SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
+	__uint(key_size, sizeof(u32));
+	__uint(value_size, sizeof(long));
+	__uint(max_entries, MAX_ENTRIES);
+	__uint(map_flags, BPF_F_NO_PREALLOC);
+} percpu_hash_map_alloc SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_LPM_TRIE);
+	__uint(key_size, 8);
+	__uint(value_size, sizeof(long));
+	__uint(max_entries, 10000);
+	__uint(map_flags, BPF_F_NO_PREALLOC);
+} lpm_trie_map_alloc SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__type(key, u32);
+	__type(value, long);
+	__uint(max_entries, MAX_ENTRIES);
+} array_map SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_LRU_HASH);
+	__type(key, u32);
+	__type(value, long);
+	__uint(max_entries, MAX_ENTRIES);
+} lru_hash_lookup_map SEC(".maps");
+
+SEC("kprobe/" SYSCALL(sys_getuid))
 int stress_hmap(struct pt_regs *ctx)
 {
 	u32 key = bpf_get_current_pid_tgid();
@@ -114,7 +117,7 @@ int stress_hmap(struct pt_regs *ctx)
 	return 0;
 }
 
-SEC("kprobe/sys_geteuid")
+SEC("kprobe/" SYSCALL(sys_geteuid))
 int stress_percpu_hmap(struct pt_regs *ctx)
 {
 	u32 key = bpf_get_current_pid_tgid();
@@ -128,7 +131,7 @@ int stress_percpu_hmap(struct pt_regs *ctx)
 	return 0;
 }
 
-SEC("kprobe/sys_getgid")
+SEC("kprobe/" SYSCALL(sys_getgid))
 int stress_hmap_alloc(struct pt_regs *ctx)
 {
 	u32 key = bpf_get_current_pid_tgid();
@@ -142,7 +145,7 @@ int stress_hmap_alloc(struct pt_regs *ctx)
 	return 0;
 }
 
-SEC("kprobe/sys_getegid")
+SEC("kprobe/" SYSCALL(sys_getegid))
 int stress_percpu_hmap_alloc(struct pt_regs *ctx)
 {
 	u32 key = bpf_get_current_pid_tgid();
@@ -236,7 +239,7 @@ int stress_lru_hmap_alloc(struct pt_regs *ctx)
 	return 0;
 }
 
-SEC("kprobe/sys_gettid")
+SEC("kprobe/" SYSCALL(sys_gettid))
 int stress_lpm_trie_map_alloc(struct pt_regs *ctx)
 {
 	union {
@@ -258,7 +261,7 @@ int stress_lpm_trie_map_alloc(struct pt_regs *ctx)
 	return 0;
 }
 
-SEC("kprobe/sys_getpgid")
+SEC("kprobe/" SYSCALL(sys_getpgid))
 int stress_hash_map_lookup(struct pt_regs *ctx)
 {
 	u32 key = 1, i;
@@ -271,7 +274,7 @@ int stress_hash_map_lookup(struct pt_regs *ctx)
 	return 0;
 }
 
-SEC("kprobe/sys_getppid")
+SEC("kprobe/" SYSCALL(sys_getppid))
 int stress_array_map_lookup(struct pt_regs *ctx)
 {
 	u32 key = 1, i;
samples/bpf/map_perf_test_user.c +105 -59

241 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

PATCH v2 4/4 selftests: bpf: remove unused bpf_map_def_legacy struct

In reply to Daniel T. Lee

samples/bpf no longer use bpf_map_def_legacy and instead use the libbpf's bpf_map_def or new BTF-defined MAP format. This commit removes unused bpf_map_def_legacy struct from selftests/bpf/bpf_legacy.h.

---
 tools/testing/selftests/bpf/bpf_legacy.h | 14 --------------
 1 file changed, 14 deletions(-)
tools/testing/selftests/bpf/bpf_legacy.h +0 -14
index 6f8988738bc1..719ab56cdb5d 100644
@@ -2,20 +2,6 @@
 #ifndef __BPF_LEGACY__
 #define __BPF_LEGACY__
 
-/*
- * legacy bpf_map_def with extra fields supported only by bpf_load(), do not
- * use outside of samples/bpf
- */
-struct bpf_map_def_legacy {
-	unsigned int type;
-	unsigned int key_size;
-	unsigned int value_size;
-	unsigned int max_entries;
-	unsigned int map_flags;
-	unsigned int inner_map_idx;
-	unsigned int numa_node;
-};
-
 #define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val)		\
 	struct ____btf_map_##name {				\
 		type_key key;					\
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH bpf-next v2 4/4] selftests: bpf: remove unused bpf_map_def_legacy struct

Quoted 7 lines · Daniel T. Lee

samples/bpf no longer use bpf_map_def_legacy and instead use the libbpf's bpf_map_def or new BTF-defined MAP format. This commit removes unused bpf_map_def_legacy struct from selftests/bpf/bpf_legacy.h.

---

Next time please don't forget to keep Ack's you've received on previous revision.

Quoted 31 lines
 tools/testing/selftests/bpf/bpf_legacy.h | 14 --------------
 1 file changed, 14 deletions(-)
tools/testing/selftests/bpf/bpf_legacy.h +0 -15
index 6f8988738bc1..719ab56cdb5d 100644
@@ -2,20 +2,6 @@
 #ifndef __BPF_LEGACY__
 #define __BPF_LEGACY__
 
-/*
- * legacy bpf_map_def with extra fields supported only by bpf_load(), do not
- * use outside of samples/bpf
- */
-struct bpf_map_def_legacy {
-       unsigned int type;
-       unsigned int key_size;
-       unsigned int value_size;
-       unsigned int max_entries;
-       unsigned int map_flags;
-       unsigned int inner_map_idx;
-       unsigned int numa_node;
-};
-
 #define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val)         \
        struct ____btf_map_##name {                             \
                type_key key;                                   \
--

2.25.1

#6 lore raw

Re: [PATCH bpf-next v2 4/4] selftests: bpf: remove unused bpf_map_def_legacy struct

Quoted 7 lines · Andrii Nakryiko
Quoted 5 lines · Daniel T. Lee

samples/bpf no longer use bpf_map_def_legacy and instead use the libbpf's bpf_map_def or new BTF-defined MAP format. This commit removes unused bpf_map_def_legacy struct from selftests/bpf/bpf_legacy.h.

Quoted 6 lines
Quoted 2 lines

---

Next time please don't forget to keep Ack's you've received on previous revision.

I'll keep that in mind.

Thank you for your time and effort for the review. Daniel.

Quoted 31 lines
Quoted 31 lines
 tools/testing/selftests/bpf/bpf_legacy.h | 14 --------------
 1 file changed, 14 deletions(-)
tools/testing/selftests/bpf/bpf_legacy.h +0 -15
index 6f8988738bc1..719ab56cdb5d 100644
@@ -2,20 +2,6 @@
 #ifndef __BPF_LEGACY__
 #define __BPF_LEGACY__
 
-/*
- * legacy bpf_map_def with extra fields supported only by bpf_load(), do not
- * use outside of samples/bpf
- */
-struct bpf_map_def_legacy {
-       unsigned int type;
-       unsigned int key_size;
-       unsigned int value_size;
-       unsigned int max_entries;
-       unsigned int map_flags;
-       unsigned int inner_map_idx;
-       unsigned int numa_node;
-};
-
 #define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val)         \
        struct ____btf_map_##name {                             \
                type_key key;                                   \
--

2.25.1

Acked-by on the v2 series
#7 lore raw
In reply to Daniel T. Lee
Quoted 10 lines · Daniel T. Lee

There have been many changes in how the current bpf program defines map. The development of libbbpf has led to the new method called BTF-defined map, which is a new way of defining BPF maps, and thus has a lot of differences from the existing MAP definition method.

Although bpf_load was also internally using libbbpf, fragmentation in its implementation began to occur, such as using its own structure, bpf_load_map_def, to define the map.

Quoted 5 lines

Therefore, in this patch set, map test programs, which are closely related to changes in the definition method of BPF map, were refactored with libbbpf.

---

For the series:

Quoted 26 lines

Changes in V2:
- instead of changing event from __x64_sys_connect to __sys_connect, fetch and set register values directly
- fix wrong error check logic with bpf_program
- set numa_node 0 declaratively at map definition instead of setting it from user-space
- static initialization of ARRAY_OF_MAPS element with '.values'

Daniel T. Lee (4):
samples: bpf: fix bpf programs with kprobe/sys_connect event
samples: bpf: refactor BPF map in map test with libbpf
samples: bpf: refactor BPF map performance test with libbpf
selftests: bpf: remove unused bpf_map_def_legacy struct

 samples/bpf/Makefile                     |   2 +-
 samples/bpf/map_perf_test_kern.c         | 188 ++++++++++++-----------
 samples/bpf/map_perf_test_user.c         | 164 +++++++++++++-------
 samples/bpf/test_map_in_map_kern.c       |  94 ++++++------
 samples/bpf/test_map_in_map_user.c       |  53 ++++++-
 samples/bpf/test_probe_write_user_kern.c |   9 +-
 tools/testing/selftests/bpf/bpf_legacy.h |  14 --
 7 files changed, 305 insertions(+), 219 deletions(-)

--
2.25.1

maintainer Applied
#8 lore raw
Quoted 15 lines · Andrii Nakryiko
Quoted 14 lines · Daniel T. Lee

There have been many changes in how the current bpf program defines map. The development of libbbpf has led to the new method called BTF-defined map, which is a new way of defining BPF maps, and thus has a lot of differences from the existing MAP definition method.

Although bpf_load was also internally using libbbpf, fragmentation in its implementation began to occur, such as using its own structure, bpf_load_map_def, to define the map.

Therefore, in this patch set, map test programs, which are closely related to changes in the definition method of BPF map, were refactored with libbbpf.

Quoted 5 lines
Quoted 1 line

---

For the series:

Applied, thanks everyone!