summaryrefslogtreecommitdiffstats
path: root/samples/bpf
diff options
context:
space:
mode:
authorJoe Stringer <joe@ovn.org>2016-12-14 17:43:38 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-12-15 14:25:47 -0500
commitd40fc181ebec6b1d560e2167208276baa4f3bbf0 (patch)
treee0dc5c768d21f920de3f7595dbcf52cb6c0c31d3 /samples/bpf
parenta5580c7f7a6d078696458d283df5d6547ad1c740 (diff)
samples/bpf: Make samples more libbpf-centric
Switch all of the sample code to use the function names from tools/lib/bpf so that they're consistent with that, and to declare their own log buffers. This allow the next commit to be purely devoted to getting rid of the duplicate library in samples/bpf. Committer notes: Testing it: On a fedora rawhide container, with clang/llvm 3.9, sharing the host linux kernel git tree: # make O=/tmp/build/linux/ headers_install # make O=/tmp/build/linux -C samples/bpf/ Since I forgot to make it privileged, just tested it outside the container, using what it generated: # uname -a Linux jouet 4.9.0-rc8+ #1 SMP Mon Dec 12 11:20:49 BRT 2016 x86_64 x86_64 x86_64 GNU/Linux # cd /var/lib/docker/devicemapper/mnt/c43e09a53ff56c86a07baf79847f00e2cc2a17a1e2220e1adbf8cbc62734feda/rootfs/tmp/build/linux/samples/bpf/ # ls -la offwaketime -rwxr-xr-x. 1 root root 24200 Dec 15 12:19 offwaketime # file offwaketime offwaketime: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=c940d3f127d5e66cdd680e42d885cb0b64f8a0e4, not stripped # readelf -SW offwaketime_kern.o | grep PROGBITS [ 2] .text PROGBITS 0000000000000000 000040 000000 00 AX 0 0 4 [ 3] kprobe/try_to_wake_up PROGBITS 0000000000000000 000040 0000d8 00 AX 0 0 8 [ 5] tracepoint/sched/sched_switch PROGBITS 0000000000000000 000118 000318 00 AX 0 0 8 [ 7] maps PROGBITS 0000000000000000 000430 000050 00 WA 0 0 4 [ 8] license PROGBITS 0000000000000000 000480 000004 00 WA 0 0 1 [ 9] version PROGBITS 0000000000000000 000484 000004 00 WA 0 0 4 # ./offwaketime | head -5 swapper/1;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule;__schedule;-;---;; 106 CPU 0/KVM;entry_SYSCALL_64_fastpath;sys_ioctl;do_vfs_ioctl;kvm_vcpu_ioctl;kvm_arch_vcpu_ioctl_run;kvm_vcpu_block;schedule;__schedule;-;try_to_wake_up;swake_up_locked;swake_up;apic_timer_expired;apic_timer_fn;__hrtimer_run_queues;hrtimer_interrupt;local_apic_timer_interrupt;smp_apic_timer_interrupt;__irqentry_text_start;cpuidle_enter;call_cpuidle;cpu_startup_entry;start_secondary;;swapper/3 2 Compositor;entry_SYSCALL_64_fastpath;sys_futex;do_futex;futex_wait;futex_wait_queue_me;schedule;__schedule;-;try_to_wake_up;futex_requeue;do_futex;sys_futex;entry_SYSCALL_64_fastpath;;SoftwareVsyncTh 5 firefox;entry_SYSCALL_64_fastpath;sys_poll;do_sys_poll;poll_schedule_timeout;schedule_hrtimeout_range;schedule_hrtimeout_range_clock;schedule;__schedule;-;try_to_wake_up;pollwake;__wake_up_common;__wake_up_sync_key;pipe_write;__vfs_write;vfs_write;sys_write;entry_SYSCALL_64_fastpath;;Timer 13 JS Helper;entry_SYSCALL_64_fastpath;sys_futex;do_futex;futex_wait;futex_wait_queue_me;schedule;__schedule;-;try_to_wake_up;do_futex;sys_futex;entry_SYSCALL_64_fastpath;;firefox 2 # Signed-off-by: Joe Stringer <joe@ovn.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexei Starovoitov <ast@fb.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Wang Nan <wangnan0@huawei.com> Cc: netdev@vger.kernel.org Link: http://lkml.kernel.org/r/20161214224342.12858-2-joe@ovn.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'samples/bpf')
-rw-r--r--samples/bpf/bpf_load.c17
-rw-r--r--samples/bpf/bpf_load.h3
-rw-r--r--samples/bpf/fds_example.c9
-rw-r--r--samples/bpf/lathist_user.c2
-rw-r--r--samples/bpf/libbpf.c23
-rw-r--r--samples/bpf/libbpf.h18
-rw-r--r--samples/bpf/lwt_len_hist_user.c6
-rw-r--r--samples/bpf/offwaketime_user.c8
-rw-r--r--samples/bpf/sampleip_user.c4
-rw-r--r--samples/bpf/sock_example.c12
-rw-r--r--samples/bpf/sockex1_user.c6
-rw-r--r--samples/bpf/sockex2_user.c4
-rw-r--r--samples/bpf/sockex3_user.c4
-rw-r--r--samples/bpf/spintest_user.c8
-rw-r--r--samples/bpf/tc_l2_redirect_user.c4
-rw-r--r--samples/bpf/test_cgrp2_array_pin.c4
-rw-r--r--samples/bpf/test_cgrp2_attach.c11
-rw-r--r--samples/bpf/test_cgrp2_attach2.c7
-rw-r--r--samples/bpf/test_cgrp2_sock.c6
-rw-r--r--samples/bpf/test_current_task_under_cgroup_user.c8
-rw-r--r--samples/bpf/test_lru_dist.c32
-rw-r--r--samples/bpf/test_probe_write_user_user.c2
-rw-r--r--samples/bpf/trace_event_user.c14
-rw-r--r--samples/bpf/trace_output_user.c2
-rw-r--r--samples/bpf/tracex2_user.c10
-rw-r--r--samples/bpf/tracex3_user.c4
-rw-r--r--samples/bpf/tracex4_user.c4
-rw-r--r--samples/bpf/tracex6_user.c2
-rw-r--r--samples/bpf/xdp1_user.c2
-rw-r--r--samples/bpf/xdp_tx_iptunnel_user.c6
30 files changed, 133 insertions, 109 deletions
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c
index e30b6de94f2e..f5b186c46b7c 100644
--- a/samples/bpf/bpf_load.c
+++ b/samples/bpf/bpf_load.c
@@ -22,7 +22,6 @@
22#include <poll.h> 22#include <poll.h>
23#include <ctype.h> 23#include <ctype.h>
24#include "libbpf.h" 24#include "libbpf.h"
25#include "bpf_helpers.h"
26#include "bpf_load.h" 25#include "bpf_load.h"
27 26
28#define DEBUGFS "/sys/kernel/debug/tracing/" 27#define DEBUGFS "/sys/kernel/debug/tracing/"
@@ -30,17 +29,26 @@
30static char license[128]; 29static char license[128];
31static int kern_version; 30static int kern_version;
32static bool processed_sec[128]; 31static bool processed_sec[128];
32char bpf_log_buf[BPF_LOG_BUF_SIZE];
33int map_fd[MAX_MAPS]; 33int map_fd[MAX_MAPS];
34int prog_fd[MAX_PROGS]; 34int prog_fd[MAX_PROGS];
35int event_fd[MAX_PROGS]; 35int event_fd[MAX_PROGS];
36int prog_cnt; 36int prog_cnt;
37int prog_array_fd = -1; 37int prog_array_fd = -1;
38 38
39struct bpf_map_def {
40 unsigned int type;
41 unsigned int key_size;
42 unsigned int value_size;
43 unsigned int max_entries;
44 unsigned int map_flags;
45};
46
39static int populate_prog_array(const char *event, int prog_fd) 47static int populate_prog_array(const char *event, int prog_fd)
40{ 48{
41 int ind = atoi(event), err; 49 int ind = atoi(event), err;
42 50
43 err = bpf_update_elem(prog_array_fd, &ind, &prog_fd, BPF_ANY); 51 err = bpf_map_update_elem(prog_array_fd, &ind, &prog_fd, BPF_ANY);
44 if (err < 0) { 52 if (err < 0) {
45 printf("failed to store prog_fd in prog_array\n"); 53 printf("failed to store prog_fd in prog_array\n");
46 return -1; 54 return -1;
@@ -87,9 +95,10 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
87 return -1; 95 return -1;
88 } 96 }
89 97
90 fd = bpf_prog_load(prog_type, prog, size, license, kern_version); 98 fd = bpf_load_program(prog_type, prog, size, license, kern_version,
99 bpf_log_buf, BPF_LOG_BUF_SIZE);
91 if (fd < 0) { 100 if (fd < 0) {
92 printf("bpf_prog_load() err=%d\n%s", errno, bpf_log_buf); 101 printf("bpf_load_program() err=%d\n%s", errno, bpf_log_buf);
93 return -1; 102 return -1;
94 } 103 }
95 104
diff --git a/samples/bpf/bpf_load.h b/samples/bpf/bpf_load.h
index fb46a421ab41..c827827299b3 100644
--- a/samples/bpf/bpf_load.h
+++ b/samples/bpf/bpf_load.h
@@ -1,12 +1,15 @@
1#ifndef __BPF_LOAD_H 1#ifndef __BPF_LOAD_H
2#define __BPF_LOAD_H 2#define __BPF_LOAD_H
3 3
4#include "libbpf.h"
5
4#define MAX_MAPS 32 6#define MAX_MAPS 32
5#define MAX_PROGS 32 7#define MAX_PROGS 32
6 8
7extern int map_fd[MAX_MAPS]; 9extern int map_fd[MAX_MAPS];
8extern int prog_fd[MAX_PROGS]; 10extern int prog_fd[MAX_PROGS];
9extern int event_fd[MAX_PROGS]; 11extern int event_fd[MAX_PROGS];
12extern char bpf_log_buf[BPF_LOG_BUF_SIZE];
10extern int prog_cnt; 13extern int prog_cnt;
11 14
12/* parses elf file compiled by llvm .c->.o 15/* parses elf file compiled by llvm .c->.o
diff --git a/samples/bpf/fds_example.c b/samples/bpf/fds_example.c
index 625e797be6ef..8a4fc4ef3993 100644
--- a/samples/bpf/fds_example.c
+++ b/samples/bpf/fds_example.c
@@ -58,8 +58,9 @@ static int bpf_prog_create(const char *object)
58 assert(!load_bpf_file((char *)object)); 58 assert(!load_bpf_file((char *)object));
59 return prog_fd[0]; 59 return prog_fd[0];
60 } else { 60 } else {
61 return bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, 61 return bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER,
62 insns, sizeof(insns), "GPL", 0); 62 insns, sizeof(insns), "GPL", 0,
63 bpf_log_buf, BPF_LOG_BUF_SIZE);
63 } 64 }
64} 65}
65 66
@@ -83,12 +84,12 @@ static int bpf_do_map(const char *file, uint32_t flags, uint32_t key,
83 } 84 }
84 85
85 if ((flags & BPF_F_KEY_VAL) == BPF_F_KEY_VAL) { 86 if ((flags & BPF_F_KEY_VAL) == BPF_F_KEY_VAL) {
86 ret = bpf_update_elem(fd, &key, &value, 0); 87 ret = bpf_map_update_elem(fd, &key, &value, 0);
87 printf("bpf: fd:%d u->(%u:%u) ret:(%d,%s)\n", fd, key, value, 88 printf("bpf: fd:%d u->(%u:%u) ret:(%d,%s)\n", fd, key, value,
88 ret, strerror(errno)); 89 ret, strerror(errno));
89 assert(ret == 0); 90 assert(ret == 0);
90 } else if (flags & BPF_F_KEY) { 91 } else if (flags & BPF_F_KEY) {
91 ret = bpf_lookup_elem(fd, &key, &value); 92 ret = bpf_map_lookup_elem(fd, &key, &value);
92 printf("bpf: fd:%d l->(%u):%u ret:(%d,%s)\n", fd, key, value, 93 printf("bpf: fd:%d l->(%u):%u ret:(%d,%s)\n", fd, key, value,
93 ret, strerror(errno)); 94 ret, strerror(errno));
94 assert(ret == 0); 95 assert(ret == 0);
diff --git a/samples/bpf/lathist_user.c b/samples/bpf/lathist_user.c
index 65da8c1576de..6477bad5b4e2 100644
--- a/samples/bpf/lathist_user.c
+++ b/samples/bpf/lathist_user.c
@@ -73,7 +73,7 @@ static void get_data(int fd)
73 for (c = 0; c < MAX_CPU; c++) { 73 for (c = 0; c < MAX_CPU; c++) {
74 for (i = 0; i < MAX_ENTRIES; i++) { 74 for (i = 0; i < MAX_ENTRIES; i++) {
75 key = c * MAX_ENTRIES + i; 75 key = c * MAX_ENTRIES + i;
76 bpf_lookup_elem(fd, &key, &value); 76 bpf_map_lookup_elem(fd, &key, &value);
77 77
78 cpu_hist[c].data[i] = value; 78 cpu_hist[c].data[i] = value;
79 if (value > cpu_hist[c].max) 79 if (value > cpu_hist[c].max)
diff --git a/samples/bpf/libbpf.c b/samples/bpf/libbpf.c
index 9ce707bf02a7..6f076abdca35 100644
--- a/samples/bpf/libbpf.c
+++ b/samples/bpf/libbpf.c
@@ -32,7 +32,7 @@ int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
32 return syscall(__NR_bpf, BPF_MAP_CREATE, &attr, sizeof(attr)); 32 return syscall(__NR_bpf, BPF_MAP_CREATE, &attr, sizeof(attr));
33} 33}
34 34
35int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags) 35int bpf_map_update_elem(int fd, void *key, void *value, unsigned long long flags)
36{ 36{
37 union bpf_attr attr = { 37 union bpf_attr attr = {
38 .map_fd = fd, 38 .map_fd = fd,
@@ -44,7 +44,7 @@ int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags)
44 return syscall(__NR_bpf, BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); 44 return syscall(__NR_bpf, BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
45} 45}
46 46
47int bpf_lookup_elem(int fd, void *key, void *value) 47int bpf_map_lookup_elem(int fd, void *key, void *value)
48{ 48{
49 union bpf_attr attr = { 49 union bpf_attr attr = {
50 .map_fd = fd, 50 .map_fd = fd,
@@ -55,7 +55,7 @@ int bpf_lookup_elem(int fd, void *key, void *value)
55 return syscall(__NR_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)); 55 return syscall(__NR_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
56} 56}
57 57
58int bpf_delete_elem(int fd, void *key) 58int bpf_map_delete_elem(int fd, void *key)
59{ 59{
60 union bpf_attr attr = { 60 union bpf_attr attr = {
61 .map_fd = fd, 61 .map_fd = fd,
@@ -65,7 +65,7 @@ int bpf_delete_elem(int fd, void *key)
65 return syscall(__NR_bpf, BPF_MAP_DELETE_ELEM, &attr, sizeof(attr)); 65 return syscall(__NR_bpf, BPF_MAP_DELETE_ELEM, &attr, sizeof(attr));
66} 66}
67 67
68int bpf_get_next_key(int fd, void *key, void *next_key) 68int bpf_map_get_next_key(int fd, void *key, void *next_key)
69{ 69{
70 union bpf_attr attr = { 70 union bpf_attr attr = {
71 .map_fd = fd, 71 .map_fd = fd,
@@ -78,19 +78,18 @@ int bpf_get_next_key(int fd, void *key, void *next_key)
78 78
79#define ROUND_UP(x, n) (((x) + (n) - 1u) & ~((n) - 1u)) 79#define ROUND_UP(x, n) (((x) + (n) - 1u) & ~((n) - 1u))
80 80
81char bpf_log_buf[LOG_BUF_SIZE]; 81int bpf_load_program(enum bpf_prog_type prog_type,
82 82 const struct bpf_insn *insns, int prog_len,
83int bpf_prog_load(enum bpf_prog_type prog_type, 83 const char *license, int kern_version,
84 const struct bpf_insn *insns, int prog_len, 84 char *log_buf, size_t log_buf_sz)
85 const char *license, int kern_version)
86{ 85{
87 union bpf_attr attr = { 86 union bpf_attr attr = {
88 .prog_type = prog_type, 87 .prog_type = prog_type,
89 .insns = ptr_to_u64((void *) insns), 88 .insns = ptr_to_u64((void *) insns),
90 .insn_cnt = prog_len / sizeof(struct bpf_insn), 89 .insn_cnt = prog_len / sizeof(struct bpf_insn),
91 .license = ptr_to_u64((void *) license), 90 .license = ptr_to_u64((void *) license),
92 .log_buf = ptr_to_u64(bpf_log_buf), 91 .log_buf = ptr_to_u64(log_buf),
93 .log_size = LOG_BUF_SIZE, 92 .log_size = log_buf_sz,
94 .log_level = 1, 93 .log_level = 1,
95 }; 94 };
96 95
@@ -99,7 +98,7 @@ int bpf_prog_load(enum bpf_prog_type prog_type,
99 */ 98 */
100 attr.kern_version = kern_version; 99 attr.kern_version = kern_version;
101 100
102 bpf_log_buf[0] = 0; 101 log_buf[0] = 0;
103 102
104 return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr)); 103 return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
105} 104}
diff --git a/samples/bpf/libbpf.h b/samples/bpf/libbpf.h
index 94a901d86fc2..20e3457857ca 100644
--- a/samples/bpf/libbpf.h
+++ b/samples/bpf/libbpf.h
@@ -6,14 +6,15 @@ struct bpf_insn;
6 6
7int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, 7int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
8 int max_entries, int map_flags); 8 int max_entries, int map_flags);
9int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags); 9int bpf_map_update_elem(int fd, void *key, void *value, unsigned long long flags);
10int bpf_lookup_elem(int fd, void *key, void *value); 10int bpf_map_lookup_elem(int fd, void *key, void *value);
11int bpf_delete_elem(int fd, void *key); 11int bpf_map_delete_elem(int fd, void *key);
12int bpf_get_next_key(int fd, void *key, void *next_key); 12int bpf_map_get_next_key(int fd, void *key, void *next_key);
13 13
14int bpf_prog_load(enum bpf_prog_type prog_type, 14int bpf_load_program(enum bpf_prog_type prog_type,
15 const struct bpf_insn *insns, int insn_len, 15 const struct bpf_insn *insns, int insn_len,
16 const char *license, int kern_version); 16 const char *license, int kern_version,
17 char *log_buf, size_t log_buf_sz);
17 18
18int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type); 19int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type);
19int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type); 20int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
@@ -21,8 +22,7 @@ int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
21int bpf_obj_pin(int fd, const char *pathname); 22int bpf_obj_pin(int fd, const char *pathname);
22int bpf_obj_get(const char *pathname); 23int bpf_obj_get(const char *pathname);
23 24
24#define LOG_BUF_SIZE (256 * 1024) 25#define BPF_LOG_BUF_SIZE (256 * 1024)
25extern char bpf_log_buf[LOG_BUF_SIZE];
26 26
27/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */ 27/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
28 28
diff --git a/samples/bpf/lwt_len_hist_user.c b/samples/bpf/lwt_len_hist_user.c
index 05d783fc5daf..ec8f3bbcbef3 100644
--- a/samples/bpf/lwt_len_hist_user.c
+++ b/samples/bpf/lwt_len_hist_user.c
@@ -14,6 +14,8 @@
14#define MAX_INDEX 64 14#define MAX_INDEX 64
15#define MAX_STARS 38 15#define MAX_STARS 38
16 16
17char bpf_log_buf[BPF_LOG_BUF_SIZE];
18
17static void stars(char *str, long val, long max, int width) 19static void stars(char *str, long val, long max, int width)
18{ 20{
19 int i; 21 int i;
@@ -41,13 +43,13 @@ int main(int argc, char **argv)
41 return -1; 43 return -1;
42 } 44 }
43 45
44 while (bpf_get_next_key(map_fd, &key, &next_key) == 0) { 46 while (bpf_map_get_next_key(map_fd, &key, &next_key) == 0) {
45 if (next_key >= MAX_INDEX) { 47 if (next_key >= MAX_INDEX) {
46 fprintf(stderr, "Key %lu out of bounds\n", next_key); 48 fprintf(stderr, "Key %lu out of bounds\n", next_key);
47 continue; 49 continue;
48 } 50 }
49 51
50 bpf_lookup_elem(map_fd, &next_key, values); 52 bpf_map_lookup_elem(map_fd, &next_key, values);
51 53
52 sum = 0; 54 sum = 0;
53 for (i = 0; i < nr_cpus; i++) 55 for (i = 0; i < nr_cpus; i++)
diff --git a/samples/bpf/offwaketime_user.c b/samples/bpf/offwaketime_user.c
index 6f002a9c24fa..9cce2a66bd66 100644
--- a/samples/bpf/offwaketime_user.c
+++ b/samples/bpf/offwaketime_user.c
@@ -49,14 +49,14 @@ static void print_stack(struct key_t *key, __u64 count)
49 int i; 49 int i;
50 50
51 printf("%s;", key->target); 51 printf("%s;", key->target);
52 if (bpf_lookup_elem(map_fd[3], &key->tret, ip) != 0) { 52 if (bpf_map_lookup_elem(map_fd[3], &key->tret, ip) != 0) {
53 printf("---;"); 53 printf("---;");
54 } else { 54 } else {
55 for (i = PERF_MAX_STACK_DEPTH - 1; i >= 0; i--) 55 for (i = PERF_MAX_STACK_DEPTH - 1; i >= 0; i--)
56 print_ksym(ip[i]); 56 print_ksym(ip[i]);
57 } 57 }
58 printf("-;"); 58 printf("-;");
59 if (bpf_lookup_elem(map_fd[3], &key->wret, ip) != 0) { 59 if (bpf_map_lookup_elem(map_fd[3], &key->wret, ip) != 0) {
60 printf("---;"); 60 printf("---;");
61 } else { 61 } else {
62 for (i = 0; i < PERF_MAX_STACK_DEPTH; i++) 62 for (i = 0; i < PERF_MAX_STACK_DEPTH; i++)
@@ -77,8 +77,8 @@ static void print_stacks(int fd)
77 struct key_t key = {}, next_key; 77 struct key_t key = {}, next_key;
78 __u64 value; 78 __u64 value;
79 79
80 while (bpf_get_next_key(fd, &key, &next_key) == 0) { 80 while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
81 bpf_lookup_elem(fd, &next_key, &value); 81 bpf_map_lookup_elem(fd, &next_key, &value);
82 print_stack(&next_key, value); 82 print_stack(&next_key, value);
83 key = next_key; 83 key = next_key;
84 } 84 }
diff --git a/samples/bpf/sampleip_user.c b/samples/bpf/sampleip_user.c
index 260a6bdd6413..5ac5adf75931 100644
--- a/samples/bpf/sampleip_user.c
+++ b/samples/bpf/sampleip_user.c
@@ -95,8 +95,8 @@ static void print_ip_map(int fd)
95 95
96 /* fetch IPs and counts */ 96 /* fetch IPs and counts */
97 key = 0, i = 0; 97 key = 0, i = 0;
98 while (bpf_get_next_key(fd, &key, &next_key) == 0) { 98 while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
99 bpf_lookup_elem(fd, &next_key, &value); 99 bpf_map_lookup_elem(fd, &next_key, &value);
100 counts[i].ip = next_key; 100 counts[i].ip = next_key;
101 counts[i++].count = value; 101 counts[i++].count = value;
102 key = next_key; 102 key = next_key;
diff --git a/samples/bpf/sock_example.c b/samples/bpf/sock_example.c
index 28b60baa9fa8..d6b91e9a38ad 100644
--- a/samples/bpf/sock_example.c
+++ b/samples/bpf/sock_example.c
@@ -28,6 +28,8 @@
28#include <stddef.h> 28#include <stddef.h>
29#include "libbpf.h" 29#include "libbpf.h"
30 30
31char bpf_log_buf[BPF_LOG_BUF_SIZE];
32
31static int test_sock(void) 33static int test_sock(void)
32{ 34{
33 int sock = -1, map_fd, prog_fd, i, key; 35 int sock = -1, map_fd, prog_fd, i, key;
@@ -55,8 +57,8 @@ static int test_sock(void)
55 BPF_EXIT_INSN(), 57 BPF_EXIT_INSN(),
56 }; 58 };
57 59
58 prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, prog, sizeof(prog), 60 prog_fd = bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER, prog, sizeof(prog),
59 "GPL", 0); 61 "GPL", 0, bpf_log_buf, BPF_LOG_BUF_SIZE);
60 if (prog_fd < 0) { 62 if (prog_fd < 0) {
61 printf("failed to load prog '%s'\n", strerror(errno)); 63 printf("failed to load prog '%s'\n", strerror(errno));
62 goto cleanup; 64 goto cleanup;
@@ -72,13 +74,13 @@ static int test_sock(void)
72 74
73 for (i = 0; i < 10; i++) { 75 for (i = 0; i < 10; i++) {
74 key = IPPROTO_TCP; 76 key = IPPROTO_TCP;
75 assert(bpf_lookup_elem(map_fd, &key, &tcp_cnt) == 0); 77 assert(bpf_map_lookup_elem(map_fd, &key, &tcp_cnt) == 0);
76 78
77 key = IPPROTO_UDP; 79 key = IPPROTO_UDP;
78 assert(bpf_lookup_elem(map_fd, &key, &udp_cnt) == 0); 80 assert(bpf_map_lookup_elem(map_fd, &key, &udp_cnt) == 0);
79 81
80 key = IPPROTO_ICMP; 82 key = IPPROTO_ICMP;
81 assert(bpf_lookup_elem(map_fd, &key, &icmp_cnt) == 0); 83 assert(bpf_map_lookup_elem(map_fd, &key, &icmp_cnt) == 0);
82 84
83 printf("TCP %lld UDP %lld ICMP %lld packets\n", 85 printf("TCP %lld UDP %lld ICMP %lld packets\n",
84 tcp_cnt, udp_cnt, icmp_cnt); 86 tcp_cnt, udp_cnt, icmp_cnt);
diff --git a/samples/bpf/sockex1_user.c b/samples/bpf/sockex1_user.c
index 678ce4693551..9454448bf198 100644
--- a/samples/bpf/sockex1_user.c
+++ b/samples/bpf/sockex1_user.c
@@ -32,13 +32,13 @@ int main(int ac, char **argv)
32 int key; 32 int key;
33 33
34 key = IPPROTO_TCP; 34 key = IPPROTO_TCP;
35 assert(bpf_lookup_elem(map_fd[0], &key, &tcp_cnt) == 0); 35 assert(bpf_map_lookup_elem(map_fd[0], &key, &tcp_cnt) == 0);
36 36
37 key = IPPROTO_UDP; 37 key = IPPROTO_UDP;
38 assert(bpf_lookup_elem(map_fd[0], &key, &udp_cnt) == 0); 38 assert(bpf_map_lookup_elem(map_fd[0], &key, &udp_cnt) == 0);
39 39
40 key = IPPROTO_ICMP; 40 key = IPPROTO_ICMP;
41 assert(bpf_lookup_elem(map_fd[0], &key, &icmp_cnt) == 0); 41 assert(bpf_map_lookup_elem(map_fd[0], &key, &icmp_cnt) == 0);
42 42
43 printf("TCP %lld UDP %lld ICMP %lld bytes\n", 43 printf("TCP %lld UDP %lld ICMP %lld bytes\n",
44 tcp_cnt, udp_cnt, icmp_cnt); 44 tcp_cnt, udp_cnt, icmp_cnt);
diff --git a/samples/bpf/sockex2_user.c b/samples/bpf/sockex2_user.c
index 8a4085c2d117..6a40600d5a83 100644
--- a/samples/bpf/sockex2_user.c
+++ b/samples/bpf/sockex2_user.c
@@ -39,8 +39,8 @@ int main(int ac, char **argv)
39 int key = 0, next_key; 39 int key = 0, next_key;
40 struct pair value; 40 struct pair value;
41 41
42 while (bpf_get_next_key(map_fd[0], &key, &next_key) == 0) { 42 while (bpf_map_get_next_key(map_fd[0], &key, &next_key) == 0) {
43 bpf_lookup_elem(map_fd[0], &next_key, &value); 43 bpf_map_lookup_elem(map_fd[0], &next_key, &value);
44 printf("ip %s bytes %lld packets %lld\n", 44 printf("ip %s bytes %lld packets %lld\n",
45 inet_ntoa((struct in_addr){htonl(next_key)}), 45 inet_ntoa((struct in_addr){htonl(next_key)}),
46 value.bytes, value.packets); 46 value.bytes, value.packets);
diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c
index 3fcfd8c4b2a3..9099c4255f23 100644
--- a/samples/bpf/sockex3_user.c
+++ b/samples/bpf/sockex3_user.c
@@ -54,8 +54,8 @@ int main(int argc, char **argv)
54 54
55 sleep(1); 55 sleep(1);
56 printf("IP src.port -> dst.port bytes packets\n"); 56 printf("IP src.port -> dst.port bytes packets\n");
57 while (bpf_get_next_key(map_fd[2], &key, &next_key) == 0) { 57 while (bpf_map_get_next_key(map_fd[2], &key, &next_key) == 0) {
58 bpf_lookup_elem(map_fd[2], &next_key, &value); 58 bpf_map_lookup_elem(map_fd[2], &next_key, &value);
59 printf("%s.%05d -> %s.%05d %12lld %12lld\n", 59 printf("%s.%05d -> %s.%05d %12lld %12lld\n",
60 inet_ntoa((struct in_addr){htonl(next_key.src)}), 60 inet_ntoa((struct in_addr){htonl(next_key.src)}),
61 next_key.port16[0], 61 next_key.port16[0],
diff --git a/samples/bpf/spintest_user.c b/samples/bpf/spintest_user.c
index 311ede532230..80676c25fa50 100644
--- a/samples/bpf/spintest_user.c
+++ b/samples/bpf/spintest_user.c
@@ -31,8 +31,8 @@ int main(int ac, char **argv)
31 for (i = 0; i < 5; i++) { 31 for (i = 0; i < 5; i++) {
32 key = 0; 32 key = 0;
33 printf("kprobing funcs:"); 33 printf("kprobing funcs:");
34 while (bpf_get_next_key(map_fd[0], &key, &next_key) == 0) { 34 while (bpf_map_get_next_key(map_fd[0], &key, &next_key) == 0) {
35 bpf_lookup_elem(map_fd[0], &next_key, &value); 35 bpf_map_lookup_elem(map_fd[0], &next_key, &value);
36 assert(next_key == value); 36 assert(next_key == value);
37 sym = ksym_search(value); 37 sym = ksym_search(value);
38 printf(" %s", sym->name); 38 printf(" %s", sym->name);
@@ -41,8 +41,8 @@ int main(int ac, char **argv)
41 if (key) 41 if (key)
42 printf("\n"); 42 printf("\n");
43 key = 0; 43 key = 0;
44 while (bpf_get_next_key(map_fd[0], &key, &next_key) == 0) 44 while (bpf_map_get_next_key(map_fd[0], &key, &next_key) == 0)
45 bpf_delete_elem(map_fd[0], &next_key); 45 bpf_map_delete_elem(map_fd[0], &next_key);
46 sleep(1); 46 sleep(1);
47 } 47 }
48 48
diff --git a/samples/bpf/tc_l2_redirect_user.c b/samples/bpf/tc_l2_redirect_user.c
index 4013c5337b91..28995a776560 100644
--- a/samples/bpf/tc_l2_redirect_user.c
+++ b/samples/bpf/tc_l2_redirect_user.c
@@ -60,9 +60,9 @@ int main(int argc, char **argv)
60 } 60 }
61 61
62 /* bpf_tunnel_key.remote_ipv4 expects host byte orders */ 62 /* bpf_tunnel_key.remote_ipv4 expects host byte orders */
63 ret = bpf_update_elem(array_fd, &array_key, &ifindex, 0); 63 ret = bpf_map_update_elem(array_fd, &array_key, &ifindex, 0);
64 if (ret) { 64 if (ret) {
65 perror("bpf_update_elem"); 65 perror("bpf_map_update_elem");
66 goto out; 66 goto out;
67 } 67 }
68 68
diff --git a/samples/bpf/test_cgrp2_array_pin.c b/samples/bpf/test_cgrp2_array_pin.c
index 70e86f7be69d..8a1b8b5d8def 100644
--- a/samples/bpf/test_cgrp2_array_pin.c
+++ b/samples/bpf/test_cgrp2_array_pin.c
@@ -85,9 +85,9 @@ int main(int argc, char **argv)
85 } 85 }
86 } 86 }
87 87
88 ret = bpf_update_elem(array_fd, &array_key, &cg2_fd, 0); 88 ret = bpf_map_update_elem(array_fd, &array_key, &cg2_fd, 0);
89 if (ret) { 89 if (ret) {
90 perror("bpf_update_elem"); 90 perror("bpf_map_update_elem");
91 goto out; 91 goto out;
92 } 92 }
93 93
diff --git a/samples/bpf/test_cgrp2_attach.c b/samples/bpf/test_cgrp2_attach.c
index a19484c45b79..8283ef86d392 100644
--- a/samples/bpf/test_cgrp2_attach.c
+++ b/samples/bpf/test_cgrp2_attach.c
@@ -36,6 +36,8 @@ enum {
36 MAP_KEY_BYTES, 36 MAP_KEY_BYTES,
37}; 37};
38 38
39char bpf_log_buf[BPF_LOG_BUF_SIZE];
40
39static int prog_load(int map_fd, int verdict) 41static int prog_load(int map_fd, int verdict)
40{ 42{
41 struct bpf_insn prog[] = { 43 struct bpf_insn prog[] = {
@@ -67,8 +69,9 @@ static int prog_load(int map_fd, int verdict)
67 BPF_EXIT_INSN(), 69 BPF_EXIT_INSN(),
68 }; 70 };
69 71
70 return bpf_prog_load(BPF_PROG_TYPE_CGROUP_SKB, 72 return bpf_load_program(BPF_PROG_TYPE_CGROUP_SKB,
71 prog, sizeof(prog), "GPL", 0); 73 prog, sizeof(prog), "GPL", 0,
74 bpf_log_buf, BPF_LOG_BUF_SIZE);
72} 75}
73 76
74static int usage(const char *argv0) 77static int usage(const char *argv0)
@@ -108,10 +111,10 @@ static int attach_filter(int cg_fd, int type, int verdict)
108 } 111 }
109 while (1) { 112 while (1) {
110 key = MAP_KEY_PACKETS; 113 key = MAP_KEY_PACKETS;
111 assert(bpf_lookup_elem(map_fd, &key, &pkt_cnt) == 0); 114 assert(bpf_map_lookup_elem(map_fd, &key, &pkt_cnt) == 0);
112 115
113 key = MAP_KEY_BYTES; 116 key = MAP_KEY_BYTES;
114 assert(bpf_lookup_elem(map_fd, &key, &byte_cnt) == 0); 117 assert(bpf_map_lookup_elem(map_fd, &key, &byte_cnt) == 0);
115 118
116 printf("cgroup received %lld packets, %lld bytes\n", 119 printf("cgroup received %lld packets, %lld bytes\n",
117 pkt_cnt, byte_cnt); 120 pkt_cnt, byte_cnt);
diff --git a/samples/bpf/test_cgrp2_attach2.c b/samples/bpf/test_cgrp2_attach2.c
index ddfac42ed4df..fc6092fdc3b0 100644
--- a/samples/bpf/test_cgrp2_attach2.c
+++ b/samples/bpf/test_cgrp2_attach2.c
@@ -32,6 +32,8 @@
32#define BAR "/foo/bar/" 32#define BAR "/foo/bar/"
33#define PING_CMD "ping -c1 -w1 127.0.0.1" 33#define PING_CMD "ping -c1 -w1 127.0.0.1"
34 34
35char bpf_log_buf[BPF_LOG_BUF_SIZE];
36
35static int prog_load(int verdict) 37static int prog_load(int verdict)
36{ 38{
37 int ret; 39 int ret;
@@ -40,8 +42,9 @@ static int prog_load(int verdict)
40 BPF_EXIT_INSN(), 42 BPF_EXIT_INSN(),
41 }; 43 };
42 44
43 ret = bpf_prog_load(BPF_PROG_TYPE_CGROUP_SKB, 45 ret = bpf_load_program(BPF_PROG_TYPE_CGROUP_SKB,
44 prog, sizeof(prog), "GPL", 0); 46 prog, sizeof(prog), "GPL", 0,
47 bpf_log_buf, BPF_LOG_BUF_SIZE);
45 48
46 if (ret < 0) { 49 if (ret < 0) {
47 log_err("Loading program"); 50 log_err("Loading program");
diff --git a/samples/bpf/test_cgrp2_sock.c b/samples/bpf/test_cgrp2_sock.c
index d467b3c1c55c..43b4bde5d05c 100644
--- a/samples/bpf/test_cgrp2_sock.c
+++ b/samples/bpf/test_cgrp2_sock.c
@@ -23,6 +23,8 @@
23 23
24#include "libbpf.h" 24#include "libbpf.h"
25 25
26char bpf_log_buf[BPF_LOG_BUF_SIZE];
27
26static int prog_load(int idx) 28static int prog_load(int idx)
27{ 29{
28 struct bpf_insn prog[] = { 30 struct bpf_insn prog[] = {
@@ -34,8 +36,8 @@ static int prog_load(int idx)
34 BPF_EXIT_INSN(), 36 BPF_EXIT_INSN(),
35 }; 37 };
36 38
37 return bpf_prog_load(BPF_PROG_TYPE_CGROUP_SOCK, prog, sizeof(prog), 39 return bpf_load_program(BPF_PROG_TYPE_CGROUP_SOCK, prog, sizeof(prog),
38 "GPL", 0); 40 "GPL", 0, bpf_log_buf, BPF_LOG_BUF_SIZE);
39} 41}
40 42
41static int usage(const char *argv0) 43static int usage(const char *argv0)
diff --git a/samples/bpf/test_current_task_under_cgroup_user.c b/samples/bpf/test_current_task_under_cgroup_user.c
index 95aaaa846130..65b5fb51c1db 100644
--- a/samples/bpf/test_current_task_under_cgroup_user.c
+++ b/samples/bpf/test_current_task_under_cgroup_user.c
@@ -36,7 +36,7 @@ int main(int argc, char **argv)
36 if (!cg2) 36 if (!cg2)
37 goto err; 37 goto err;
38 38
39 if (bpf_update_elem(map_fd[0], &idx, &cg2, BPF_ANY)) { 39 if (bpf_map_update_elem(map_fd[0], &idx, &cg2, BPF_ANY)) {
40 log_err("Adding target cgroup to map"); 40 log_err("Adding target cgroup to map");
41 goto err; 41 goto err;
42 } 42 }
@@ -50,7 +50,7 @@ int main(int argc, char **argv)
50 */ 50 */
51 51
52 sync(); 52 sync();
53 bpf_lookup_elem(map_fd[1], &idx, &remote_pid); 53 bpf_map_lookup_elem(map_fd[1], &idx, &remote_pid);
54 54
55 if (local_pid != remote_pid) { 55 if (local_pid != remote_pid) {
56 fprintf(stderr, 56 fprintf(stderr,
@@ -64,10 +64,10 @@ int main(int argc, char **argv)
64 goto err; 64 goto err;
65 65
66 remote_pid = 0; 66 remote_pid = 0;
67 bpf_update_elem(map_fd[1], &idx, &remote_pid, BPF_ANY); 67 bpf_map_update_elem(map_fd[1], &idx, &remote_pid, BPF_ANY);
68 68
69 sync(); 69 sync();
70 bpf_lookup_elem(map_fd[1], &idx, &remote_pid); 70 bpf_map_lookup_elem(map_fd[1], &idx, &remote_pid);
71 71
72 if (local_pid == remote_pid) { 72 if (local_pid == remote_pid) {
73 fprintf(stderr, "BPF cgroup negative test did not work\n"); 73 fprintf(stderr, "BPF cgroup negative test did not work\n");
diff --git a/samples/bpf/test_lru_dist.c b/samples/bpf/test_lru_dist.c
index 316230a0ed23..d96dc88d3b04 100644
--- a/samples/bpf/test_lru_dist.c
+++ b/samples/bpf/test_lru_dist.c
@@ -134,7 +134,7 @@ static int pfect_lru_lookup_or_insert(struct pfect_lru *lru,
134 int seen = 0; 134 int seen = 0;
135 135
136 lru->total++; 136 lru->total++;
137 if (!bpf_lookup_elem(lru->map_fd, &key, &node)) { 137 if (!bpf_map_lookup_elem(lru->map_fd, &key, &node)) {
138 if (node) { 138 if (node) {
139 list_move(&node->list, &lru->list); 139 list_move(&node->list, &lru->list);
140 return 1; 140 return 1;
@@ -151,7 +151,7 @@ static int pfect_lru_lookup_or_insert(struct pfect_lru *lru,
151 node = list_last_entry(&lru->list, 151 node = list_last_entry(&lru->list,
152 struct pfect_lru_node, 152 struct pfect_lru_node,
153 list); 153 list);
154 bpf_update_elem(lru->map_fd, &node->key, &null_node, BPF_EXIST); 154 bpf_map_update_elem(lru->map_fd, &node->key, &null_node, BPF_EXIST);
155 } 155 }
156 156
157 node->key = key; 157 node->key = key;
@@ -159,10 +159,10 @@ static int pfect_lru_lookup_or_insert(struct pfect_lru *lru,
159 159
160 lru->nr_misses++; 160 lru->nr_misses++;
161 if (seen) { 161 if (seen) {
162 assert(!bpf_update_elem(lru->map_fd, &key, &node, BPF_EXIST)); 162 assert(!bpf_map_update_elem(lru->map_fd, &key, &node, BPF_EXIST));
163 } else { 163 } else {
164 lru->nr_unique++; 164 lru->nr_unique++;
165 assert(!bpf_update_elem(lru->map_fd, &key, &node, BPF_NOEXIST)); 165 assert(!bpf_map_update_elem(lru->map_fd, &key, &node, BPF_NOEXIST));
166 } 166 }
167 167
168 return seen; 168 return seen;
@@ -285,11 +285,11 @@ static void do_test_lru_dist(int task, void *data)
285 285
286 pfect_lru_lookup_or_insert(&pfect_lru, key); 286 pfect_lru_lookup_or_insert(&pfect_lru, key);
287 287
288 if (!bpf_lookup_elem(lru_map_fd, &key, &value)) 288 if (!bpf_map_lookup_elem(lru_map_fd, &key, &value))
289 continue; 289 continue;
290 290
291 if (bpf_update_elem(lru_map_fd, &key, &value, BPF_NOEXIST)) { 291 if (bpf_map_update_elem(lru_map_fd, &key, &value, BPF_NOEXIST)) {
292 printf("bpf_update_elem(lru_map_fd, %llu): errno:%d\n", 292 printf("bpf_map_update_elem(lru_map_fd, %llu): errno:%d\n",
293 key, errno); 293 key, errno);
294 assert(0); 294 assert(0);
295 } 295 }
@@ -358,19 +358,19 @@ static void test_lru_loss0(int map_type, int map_flags)
358 for (key = 1; key <= 1000; key++) { 358 for (key = 1; key <= 1000; key++) {
359 int start_key, end_key; 359 int start_key, end_key;
360 360
361 assert(bpf_update_elem(map_fd, &key, value, BPF_NOEXIST) == 0); 361 assert(bpf_map_update_elem(map_fd, &key, value, BPF_NOEXIST) == 0);
362 362
363 start_key = 101; 363 start_key = 101;
364 end_key = min(key, 900); 364 end_key = min(key, 900);
365 365
366 while (start_key <= end_key) { 366 while (start_key <= end_key) {
367 bpf_lookup_elem(map_fd, &start_key, value); 367 bpf_map_lookup_elem(map_fd, &start_key, value);
368 start_key++; 368 start_key++;
369 } 369 }
370 } 370 }
371 371
372 for (key = 1; key <= 1000; key++) { 372 for (key = 1; key <= 1000; key++) {
373 if (bpf_lookup_elem(map_fd, &key, value)) { 373 if (bpf_map_lookup_elem(map_fd, &key, value)) {
374 if (key <= 100) 374 if (key <= 100)
375 old_unused_losses++; 375 old_unused_losses++;
376 else if (key <= 900) 376 else if (key <= 900)
@@ -408,10 +408,10 @@ static void test_lru_loss1(int map_type, int map_flags)
408 value[0] = 1234; 408 value[0] = 1234;
409 409
410 for (key = 1; key <= 1000; key++) 410 for (key = 1; key <= 1000; key++)
411 assert(!bpf_update_elem(map_fd, &key, value, BPF_NOEXIST)); 411 assert(!bpf_map_update_elem(map_fd, &key, value, BPF_NOEXIST));
412 412
413 for (key = 1; key <= 1000; key++) { 413 for (key = 1; key <= 1000; key++) {
414 if (bpf_lookup_elem(map_fd, &key, value)) 414 if (bpf_map_lookup_elem(map_fd, &key, value))
415 nr_losses++; 415 nr_losses++;
416 } 416 }
417 417
@@ -436,7 +436,7 @@ static void do_test_parallel_lru_loss(int task, void *data)
436 next_ins_key = stable_base; 436 next_ins_key = stable_base;
437 value[0] = 1234; 437 value[0] = 1234;
438 for (i = 0; i < nr_stable_elems; i++) { 438 for (i = 0; i < nr_stable_elems; i++) {
439 assert(bpf_update_elem(map_fd, &next_ins_key, value, 439 assert(bpf_map_update_elem(map_fd, &next_ins_key, value,
440 BPF_NOEXIST) == 0); 440 BPF_NOEXIST) == 0);
441 next_ins_key++; 441 next_ins_key++;
442 } 442 }
@@ -448,9 +448,9 @@ static void do_test_parallel_lru_loss(int task, void *data)
448 448
449 if (rn % 10) { 449 if (rn % 10) {
450 key = rn % nr_stable_elems + stable_base; 450 key = rn % nr_stable_elems + stable_base;
451 bpf_lookup_elem(map_fd, &key, value); 451 bpf_map_lookup_elem(map_fd, &key, value);
452 } else { 452 } else {
453 bpf_update_elem(map_fd, &next_ins_key, value, 453 bpf_map_update_elem(map_fd, &next_ins_key, value,
454 BPF_NOEXIST); 454 BPF_NOEXIST);
455 next_ins_key++; 455 next_ins_key++;
456 } 456 }
@@ -458,7 +458,7 @@ static void do_test_parallel_lru_loss(int task, void *data)
458 458
459 key = stable_base; 459 key = stable_base;
460 for (i = 0; i < nr_stable_elems; i++) { 460 for (i = 0; i < nr_stable_elems; i++) {
461 if (bpf_lookup_elem(map_fd, &key, value)) 461 if (bpf_map_lookup_elem(map_fd, &key, value))
462 nr_losses++; 462 nr_losses++;
463 key++; 463 key++;
464 } 464 }
diff --git a/samples/bpf/test_probe_write_user_user.c b/samples/bpf/test_probe_write_user_user.c
index a44bf347bedd..b5bf178a6ecc 100644
--- a/samples/bpf/test_probe_write_user_user.c
+++ b/samples/bpf/test_probe_write_user_user.c
@@ -50,7 +50,7 @@ int main(int ac, char **argv)
50 mapped_addr_in->sin_port = htons(5555); 50 mapped_addr_in->sin_port = htons(5555);
51 mapped_addr_in->sin_addr.s_addr = inet_addr("255.255.255.255"); 51 mapped_addr_in->sin_addr.s_addr = inet_addr("255.255.255.255");
52 52
53 assert(!bpf_update_elem(map_fd[0], &mapped_addr, &serv_addr, BPF_ANY)); 53 assert(!bpf_map_update_elem(map_fd[0], &mapped_addr, &serv_addr, BPF_ANY));
54 54
55 assert(listen(serverfd, 5) == 0); 55 assert(listen(serverfd, 5) == 0);
56 56
diff --git a/samples/bpf/trace_event_user.c b/samples/bpf/trace_event_user.c
index 9a130d31ecf2..704fe9fa77b2 100644
--- a/samples/bpf/trace_event_user.c
+++ b/samples/bpf/trace_event_user.c
@@ -61,14 +61,14 @@ static void print_stack(struct key_t *key, __u64 count)
61 int i; 61 int i;
62 62
63 printf("%3lld %s;", count, key->comm); 63 printf("%3lld %s;", count, key->comm);
64 if (bpf_lookup_elem(map_fd[1], &key->kernstack, ip) != 0) { 64 if (bpf_map_lookup_elem(map_fd[1], &key->kernstack, ip) != 0) {
65 printf("---;"); 65 printf("---;");
66 } else { 66 } else {
67 for (i = PERF_MAX_STACK_DEPTH - 1; i >= 0; i--) 67 for (i = PERF_MAX_STACK_DEPTH - 1; i >= 0; i--)
68 print_ksym(ip[i]); 68 print_ksym(ip[i]);
69 } 69 }
70 printf("-;"); 70 printf("-;");
71 if (bpf_lookup_elem(map_fd[1], &key->userstack, ip) != 0) { 71 if (bpf_map_lookup_elem(map_fd[1], &key->userstack, ip) != 0) {
72 printf("---;"); 72 printf("---;");
73 } else { 73 } else {
74 for (i = PERF_MAX_STACK_DEPTH - 1; i >= 0; i--) 74 for (i = PERF_MAX_STACK_DEPTH - 1; i >= 0; i--)
@@ -98,10 +98,10 @@ static void print_stacks(void)
98 int fd = map_fd[0], stack_map = map_fd[1]; 98 int fd = map_fd[0], stack_map = map_fd[1];
99 99
100 sys_read_seen = sys_write_seen = false; 100 sys_read_seen = sys_write_seen = false;
101 while (bpf_get_next_key(fd, &key, &next_key) == 0) { 101 while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
102 bpf_lookup_elem(fd, &next_key, &value); 102 bpf_map_lookup_elem(fd, &next_key, &value);
103 print_stack(&next_key, value); 103 print_stack(&next_key, value);
104 bpf_delete_elem(fd, &next_key); 104 bpf_map_delete_elem(fd, &next_key);
105 key = next_key; 105 key = next_key;
106 } 106 }
107 107
@@ -111,8 +111,8 @@ static void print_stacks(void)
111 } 111 }
112 112
113 /* clear stack map */ 113 /* clear stack map */
114 while (bpf_get_next_key(stack_map, &stackid, &next_id) == 0) { 114 while (bpf_map_get_next_key(stack_map, &stackid, &next_id) == 0) {
115 bpf_delete_elem(stack_map, &next_id); 115 bpf_map_delete_elem(stack_map, &next_id);
116 stackid = next_id; 116 stackid = next_id;
117 } 117 }
118} 118}
diff --git a/samples/bpf/trace_output_user.c b/samples/bpf/trace_output_user.c
index 661a7d052f2c..3bedd945def1 100644
--- a/samples/bpf/trace_output_user.c
+++ b/samples/bpf/trace_output_user.c
@@ -162,7 +162,7 @@ static void test_bpf_perf_event(void)
162 pmu_fd = perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0); 162 pmu_fd = perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
163 163
164 assert(pmu_fd >= 0); 164 assert(pmu_fd >= 0);
165 assert(bpf_update_elem(map_fd[0], &key, &pmu_fd, BPF_ANY) == 0); 165 assert(bpf_map_update_elem(map_fd[0], &key, &pmu_fd, BPF_ANY) == 0);
166 ioctl(pmu_fd, PERF_EVENT_IOC_ENABLE, 0); 166 ioctl(pmu_fd, PERF_EVENT_IOC_ENABLE, 0);
167} 167}
168 168
diff --git a/samples/bpf/tracex2_user.c b/samples/bpf/tracex2_user.c
index 3e225e331f66..ded9804c5034 100644
--- a/samples/bpf/tracex2_user.c
+++ b/samples/bpf/tracex2_user.c
@@ -48,12 +48,12 @@ static void print_hist_for_pid(int fd, void *task)
48 long max_value = 0; 48 long max_value = 0;
49 int i, ind; 49 int i, ind;
50 50
51 while (bpf_get_next_key(fd, &key, &next_key) == 0) { 51 while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
52 if (memcmp(&next_key, task, SIZE)) { 52 if (memcmp(&next_key, task, SIZE)) {
53 key = next_key; 53 key = next_key;
54 continue; 54 continue;
55 } 55 }
56 bpf_lookup_elem(fd, &next_key, values); 56 bpf_map_lookup_elem(fd, &next_key, values);
57 value = 0; 57 value = 0;
58 for (i = 0; i < nr_cpus; i++) 58 for (i = 0; i < nr_cpus; i++)
59 value += values[i]; 59 value += values[i];
@@ -83,7 +83,7 @@ static void print_hist(int fd)
83 int task_cnt = 0; 83 int task_cnt = 0;
84 int i; 84 int i;
85 85
86 while (bpf_get_next_key(fd, &key, &next_key) == 0) { 86 while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
87 int found = 0; 87 int found = 0;
88 88
89 for (i = 0; i < task_cnt; i++) 89 for (i = 0; i < task_cnt; i++)
@@ -136,8 +136,8 @@ int main(int ac, char **argv)
136 136
137 for (i = 0; i < 5; i++) { 137 for (i = 0; i < 5; i++) {
138 key = 0; 138 key = 0;
139 while (bpf_get_next_key(map_fd[0], &key, &next_key) == 0) { 139 while (bpf_map_get_next_key(map_fd[0], &key, &next_key) == 0) {
140 bpf_lookup_elem(map_fd[0], &next_key, &value); 140 bpf_map_lookup_elem(map_fd[0], &next_key, &value);
141 printf("location 0x%lx count %ld\n", next_key, value); 141 printf("location 0x%lx count %ld\n", next_key, value);
142 key = next_key; 142 key = next_key;
143 } 143 }
diff --git a/samples/bpf/tracex3_user.c b/samples/bpf/tracex3_user.c
index d0851cb4fa8d..8f7d199d5945 100644
--- a/samples/bpf/tracex3_user.c
+++ b/samples/bpf/tracex3_user.c
@@ -28,7 +28,7 @@ static void clear_stats(int fd)
28 28
29 memset(values, 0, sizeof(values)); 29 memset(values, 0, sizeof(values));
30 for (key = 0; key < SLOTS; key++) 30 for (key = 0; key < SLOTS; key++)
31 bpf_update_elem(fd, &key, values, BPF_ANY); 31 bpf_map_update_elem(fd, &key, values, BPF_ANY);
32} 32}
33 33
34const char *color[] = { 34const char *color[] = {
@@ -89,7 +89,7 @@ static void print_hist(int fd)
89 int i; 89 int i;
90 90
91 for (key = 0; key < SLOTS; key++) { 91 for (key = 0; key < SLOTS; key++) {
92 bpf_lookup_elem(fd, &key, values); 92 bpf_map_lookup_elem(fd, &key, values);
93 value = 0; 93 value = 0;
94 for (i = 0; i < nr_cpus; i++) 94 for (i = 0; i < nr_cpus; i++)
95 value += values[i]; 95 value += values[i];
diff --git a/samples/bpf/tracex4_user.c b/samples/bpf/tracex4_user.c
index bc4a3bdea6ed..03449f773cb1 100644
--- a/samples/bpf/tracex4_user.c
+++ b/samples/bpf/tracex4_user.c
@@ -37,8 +37,8 @@ static void print_old_objects(int fd)
37 key = write(1, "\e[1;1H\e[2J", 12); /* clear screen */ 37 key = write(1, "\e[1;1H\e[2J", 12); /* clear screen */
38 38
39 key = -1; 39 key = -1;
40 while (bpf_get_next_key(map_fd[0], &key, &next_key) == 0) { 40 while (bpf_map_get_next_key(map_fd[0], &key, &next_key) == 0) {
41 bpf_lookup_elem(map_fd[0], &next_key, &v); 41 bpf_map_lookup_elem(map_fd[0], &next_key, &v);
42 key = next_key; 42 key = next_key;
43 if (val - v.val < 1000000000ll) 43 if (val - v.val < 1000000000ll)
44 /* object was allocated more then 1 sec ago */ 44 /* object was allocated more then 1 sec ago */
diff --git a/samples/bpf/tracex6_user.c b/samples/bpf/tracex6_user.c
index 8ea4976cfcf1..179297cb4d35 100644
--- a/samples/bpf/tracex6_user.c
+++ b/samples/bpf/tracex6_user.c
@@ -36,7 +36,7 @@ static void test_bpf_perf_event(void)
36 goto exit; 36 goto exit;
37 } 37 }
38 38
39 bpf_update_elem(map_fd[0], &i, &pmu_fd[i], BPF_ANY); 39 bpf_map_update_elem(map_fd[0], &i, &pmu_fd[i], BPF_ANY);
40 ioctl(pmu_fd[i], PERF_EVENT_IOC_ENABLE, 0); 40 ioctl(pmu_fd[i], PERF_EVENT_IOC_ENABLE, 0);
41 } 41 }
42 42
diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c
index 5f040a0d7712..d2be65d1fd86 100644
--- a/samples/bpf/xdp1_user.c
+++ b/samples/bpf/xdp1_user.c
@@ -43,7 +43,7 @@ static void poll_stats(int interval)
43 for (key = 0; key < nr_keys; key++) { 43 for (key = 0; key < nr_keys; key++) {
44 __u64 sum = 0; 44 __u64 sum = 0;
45 45
46 assert(bpf_lookup_elem(map_fd[0], &key, values) == 0); 46 assert(bpf_map_lookup_elem(map_fd[0], &key, values) == 0);
47 for (i = 0; i < nr_cpus; i++) 47 for (i = 0; i < nr_cpus; i++)
48 sum += (values[i] - prev[key][i]); 48 sum += (values[i] - prev[key][i]);
49 if (sum) 49 if (sum)
diff --git a/samples/bpf/xdp_tx_iptunnel_user.c b/samples/bpf/xdp_tx_iptunnel_user.c
index 7a71f5c74684..70e192fc61aa 100644
--- a/samples/bpf/xdp_tx_iptunnel_user.c
+++ b/samples/bpf/xdp_tx_iptunnel_user.c
@@ -51,7 +51,7 @@ static void poll_stats(unsigned int kill_after_s)
51 for (proto = 0; proto < nr_protos; proto++) { 51 for (proto = 0; proto < nr_protos; proto++) {
52 __u64 sum = 0; 52 __u64 sum = 0;
53 53
54 assert(bpf_lookup_elem(map_fd[0], &proto, values) == 0); 54 assert(bpf_map_lookup_elem(map_fd[0], &proto, values) == 0);
55 for (i = 0; i < nr_cpus; i++) 55 for (i = 0; i < nr_cpus; i++)
56 sum += (values[i] - prev[proto][i]); 56 sum += (values[i] - prev[proto][i]);
57 57
@@ -237,8 +237,8 @@ int main(int argc, char **argv)
237 237
238 while (min_port <= max_port) { 238 while (min_port <= max_port) {
239 vip.dport = htons(min_port++); 239 vip.dport = htons(min_port++);
240 if (bpf_update_elem(map_fd[1], &vip, &tnl, BPF_NOEXIST)) { 240 if (bpf_map_update_elem(map_fd[1], &vip, &tnl, BPF_NOEXIST)) {
241 perror("bpf_update_elem(&vip2tnl)"); 241 perror("bpf_map_update_elem(&vip2tnl)");
242 return 1; 242 return 1;
243 } 243 }
244 } 244 }