Skip to content

Commit e4d9c23

Browse files
iii-iAlexei Starovoitov
authored andcommitted
samples/bpf, selftests/bpf: Use bpf_probe_read_kernel
A handful of samples and selftests fail to build on s390, because after commit 0ebeea8 ("bpf: Restrict bpf_probe_read{, str}() only to archs where they work") bpf_probe_read is not available anymore. Fix by using bpf_probe_read_kernel. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200720114806.88823-1-iii@linux.ibm.com
1 parent 6bd5572 commit e4d9c23

10 files changed

Lines changed: 33 additions & 16 deletions

File tree

‎samples/bpf/offwaketime_kern.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
#include <bpf/bpf_helpers.h>
1313
#include <bpf/bpf_tracing.h>
1414

15-
#define _(P) ({typeof(P) val; bpf_probe_read(&val, sizeof(val), &P); val;})
15+
#define _(P) \
16+
({ \
17+
typeof(P) val; \
18+
bpf_probe_read_kernel(&val, sizeof(val), &(P)); \
19+
val; \
20+
})
1621

1722
#define MINBLOCK_US 1
1823

‎samples/bpf/test_overhead_kprobe_kern.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
#include <bpf/bpf_helpers.h>
1111
#include <bpf/bpf_tracing.h>
1212

13-
#define _(P) ({typeof(P) val = 0; bpf_probe_read(&val, sizeof(val), &P); val;})
13+
#define _(P) \
14+
({ \
15+
typeof(P) val = 0; \
16+
bpf_probe_read_kernel(&val, sizeof(val), &(P)); \
17+
val; \
18+
})
1419

1520
SEC("kprobe/__set_task_comm")
1621
int prog(struct pt_regs *ctx)
@@ -25,8 +30,9 @@ int prog(struct pt_regs *ctx)
2530
tsk = (void *)PT_REGS_PARM1(ctx);
2631

2732
pid = _(tsk->pid);
28-
bpf_probe_read(oldcomm, sizeof(oldcomm), &tsk->comm);
29-
bpf_probe_read(newcomm, sizeof(newcomm), (void *)PT_REGS_PARM2(ctx));
33+
bpf_probe_read_kernel(oldcomm, sizeof(oldcomm), &tsk->comm);
34+
bpf_probe_read_kernel(newcomm, sizeof(newcomm),
35+
(void *)PT_REGS_PARM2(ctx));
3036
signal = _(tsk->signal);
3137
oom_score_adj = _(signal->oom_score_adj);
3238
return 0;

‎samples/bpf/tracex1_kern.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
#include <bpf/bpf_helpers.h>
1212
#include <bpf/bpf_tracing.h>
1313

14-
#define _(P) ({typeof(P) val = 0; bpf_probe_read(&val, sizeof(val), &P); val;})
14+
#define _(P) \
15+
({ \
16+
typeof(P) val = 0; \
17+
bpf_probe_read_kernel(&val, sizeof(val), &(P)); \
18+
val; \
19+
})
1520

1621
/* kprobe is NOT a stable ABI
1722
* kernel functions can be removed, renamed or completely change semantics.
@@ -34,7 +39,7 @@ int bpf_prog1(struct pt_regs *ctx)
3439
dev = _(skb->dev);
3540
len = _(skb->len);
3641

37-
bpf_probe_read(devname, sizeof(devname), dev->name);
42+
bpf_probe_read_kernel(devname, sizeof(devname), dev->name);
3843

3944
if (devname[0] == 'l' && devname[1] == 'o') {
4045
char fmt[] = "skb %p len %d\n";

‎samples/bpf/tracex5_kern.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ PROG(SYS__NR_write)(struct pt_regs *ctx)
4747
{
4848
struct seccomp_data sd;
4949

50-
bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
50+
bpf_probe_read_kernel(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
5151
if (sd.args[2] == 512) {
5252
char fmt[] = "write(fd=%d, buf=%p, size=%d)\n";
5353
bpf_trace_printk(fmt, sizeof(fmt),
@@ -60,7 +60,7 @@ PROG(SYS__NR_read)(struct pt_regs *ctx)
6060
{
6161
struct seccomp_data sd;
6262

63-
bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
63+
bpf_probe_read_kernel(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
6464
if (sd.args[2] > 128 && sd.args[2] <= 1024) {
6565
char fmt[] = "read(fd=%d, buf=%p, size=%d)\n";
6666
bpf_trace_printk(fmt, sizeof(fmt),

‎tools/bpf/bpftool/skeleton/pid_iter.bpf.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ int iter(struct bpf_iter__task_file *ctx)
7171

7272
e.pid = task->tgid;
7373
e.id = get_obj_id(file->private_data, obj_type);
74-
bpf_probe_read(&e.comm, sizeof(e.comm), task->group_leader->comm);
74+
bpf_probe_read_kernel(&e.comm, sizeof(e.comm),
75+
task->group_leader->comm);
7576
bpf_seq_write(ctx->meta->seq, &e, sizeof(e));
7677

7778
return 0;

‎tools/testing/selftests/bpf/progs/bpf_iter_netlink.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ int dump_netlink(struct bpf_iter__netlink *ctx)
3636
if (!nlk->groups) {
3737
group = 0;
3838
} else {
39-
/* FIXME: temporary use bpf_probe_read here, needs
39+
/* FIXME: temporary use bpf_probe_read_kernel here, needs
4040
* verifier support to do direct access.
4141
*/
42-
bpf_probe_read(&group, sizeof(group), &nlk->groups[0]);
42+
bpf_probe_read_kernel(&group, sizeof(group), &nlk->groups[0]);
4343
}
4444
BPF_SEQ_PRINTF(seq, "%-10u %08x %-8d %-8d %-5d %-8d ",
4545
nlk->portid, (u32)group,
@@ -56,7 +56,7 @@ int dump_netlink(struct bpf_iter__netlink *ctx)
5656
* with current verifier.
5757
*/
5858
inode = SOCK_INODE(sk);
59-
bpf_probe_read(&ino, sizeof(ino), &inode->i_ino);
59+
bpf_probe_read_kernel(&ino, sizeof(ino), &inode->i_ino);
6060
}
6161
BPF_SEQ_PRINTF(seq, "%-8u %-8lu\n", s->sk_drops.counter, ino);
6262

‎tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static long sock_i_ino(const struct sock *sk)
5757
return 0;
5858

5959
inode = &container_of(sk_socket, struct socket_alloc, socket)->vfs_inode;
60-
bpf_probe_read(&ino, sizeof(ino), &inode->i_ino);
60+
bpf_probe_read_kernel(&ino, sizeof(ino), &inode->i_ino);
6161
return ino;
6262
}
6363

‎tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static long sock_i_ino(const struct sock *sk)
5757
return 0;
5858

5959
inode = &container_of(sk_socket, struct socket_alloc, socket)->vfs_inode;
60-
bpf_probe_read(&ino, sizeof(ino), &inode->i_ino);
60+
bpf_probe_read_kernel(&ino, sizeof(ino), &inode->i_ino);
6161
return ino;
6262
}
6363

‎tools/testing/selftests/bpf/progs/bpf_iter_udp4.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static long sock_i_ino(const struct sock *sk)
1818
return 0;
1919

2020
inode = &container_of(sk_socket, struct socket_alloc, socket)->vfs_inode;
21-
bpf_probe_read(&ino, sizeof(ino), &inode->i_ino);
21+
bpf_probe_read_kernel(&ino, sizeof(ino), &inode->i_ino);
2222
return ino;
2323
}
2424

‎tools/testing/selftests/bpf/progs/bpf_iter_udp6.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static long sock_i_ino(const struct sock *sk)
2525
return 0;
2626

2727
inode = &container_of(sk_socket, struct socket_alloc, socket)->vfs_inode;
28-
bpf_probe_read(&ino, sizeof(ino), &inode->i_ino);
28+
bpf_probe_read_kernel(&ino, sizeof(ino), &inode->i_ino);
2929
return ino;
3030
}
3131

0 commit comments

Comments
 (0)