Skip to content

Commit d060b6a

Browse files
mykyta5Alexei Starovoitov
authored andcommitted
helpers: make few bpf helpers public
Make bpf_dynptr_slice_rdwr, bpf_dynptr_check_off_len and __bpf_dynptr_write available outside of the helpers.c by adding their prototypes into linux/include/bpf.h. bpf_dynptr_check_off_len() implementation is moved to header and made inline explicitly, as small function should typically be inlined. These functions are going to be used from bpf_trace.c in the next patch of this series. Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Mykyta Yatsenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent fd5fd53 commit d060b6a

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

include/linux/bpf.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,20 @@ u32 __bpf_dynptr_size(const struct bpf_dynptr_kern *ptr);
13491349
const void *__bpf_dynptr_data(const struct bpf_dynptr_kern *ptr, u32 len);
13501350
void *__bpf_dynptr_data_rw(const struct bpf_dynptr_kern *ptr, u32 len);
13511351
bool __bpf_dynptr_is_rdonly(const struct bpf_dynptr_kern *ptr);
1352+
int __bpf_dynptr_write(const struct bpf_dynptr_kern *dst, u32 offset,
1353+
void *src, u32 len, u64 flags);
1354+
void *bpf_dynptr_slice_rdwr(const struct bpf_dynptr *p, u32 offset,
1355+
void *buffer__opt, u32 buffer__szk);
1356+
1357+
static inline int bpf_dynptr_check_off_len(const struct bpf_dynptr_kern *ptr, u32 offset, u32 len)
1358+
{
1359+
u32 size = __bpf_dynptr_size(ptr);
1360+
1361+
if (len > size || offset > size - len)
1362+
return -E2BIG;
1363+
1364+
return 0;
1365+
}
13521366

13531367
#ifdef CONFIG_BPF_JIT
13541368
int bpf_trampoline_link_prog(struct bpf_tramp_link *link,

kernel/bpf/helpers.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,16 +1714,6 @@ void bpf_dynptr_set_null(struct bpf_dynptr_kern *ptr)
17141714
memset(ptr, 0, sizeof(*ptr));
17151715
}
17161716

1717-
static int bpf_dynptr_check_off_len(const struct bpf_dynptr_kern *ptr, u32 offset, u32 len)
1718-
{
1719-
u32 size = __bpf_dynptr_size(ptr);
1720-
1721-
if (len > size || offset > size - len)
1722-
return -E2BIG;
1723-
1724-
return 0;
1725-
}
1726-
17271717
BPF_CALL_4(bpf_dynptr_from_mem, void *, data, u32, size, u64, flags, struct bpf_dynptr_kern *, ptr)
17281718
{
17291719
int err;
@@ -1810,8 +1800,8 @@ static const struct bpf_func_proto bpf_dynptr_read_proto = {
18101800
.arg5_type = ARG_ANYTHING,
18111801
};
18121802

1813-
static int __bpf_dynptr_write(const struct bpf_dynptr_kern *dst, u32 offset, void *src,
1814-
u32 len, u64 flags)
1803+
int __bpf_dynptr_write(const struct bpf_dynptr_kern *dst, u32 offset, void *src,
1804+
u32 len, u64 flags)
18151805
{
18161806
enum bpf_dynptr_type type;
18171807
int err;

0 commit comments

Comments
 (0)