History

bpf: Emit bpf_timer in vmlinux BTF

Currently the following code in check_and_init_map_value() *(struct bpf_timer *)(dst + map->timer_off) = (struct bpf_timer){}; can help generate bpf_timer definition in vmlinuxBTF. But the code above may not zero the whole structure due to anonymour members and that code will be replaced by memset in the subsequent patch and bpf_timer definition will disappear from vmlinuxBTF. Let us emit the type explicitly so bpf program can continue to use it from vmlinux.h.

Yonghong Song committed 4 years ago

Commit 3bd916e1 parent acc3c471 file · +2 −0Browse files

Unified · Split

kernel/bpf/helpers.c+2−0
@@ -2,6 +2,7 @@ · 1 unmodified line
2/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com2/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
3 */3 */
4#include <linux/bpf.h>4#include <linux/bpf.h>
5#include <linux/btf.h>
5#include <linux/bpf-cgroup.h>6#include <linux/bpf-cgroup.h>
6#include <linux/rcupdate.h>7#include <linux/rcupdate.h>
7#include <linux/random.h>8#include <linux/random.h>
@@ -1075,6 +1076,7 @@ static enum hrtimer_restart bpf_timer_cb(struct hrtimer *hrtimer) · 1067 unmodified lines
1075 void *key;1076 void *key;
1076 u32 idx;1077 u32 idx;
1077 1078
1079 BTF_TYPE_EMIT(struct bpf_timer);
1078 callback_fn = rcu_dereference_check(t->callback_fn, rcu_read_lock_bh_held());1080 callback_fn = rcu_dereference_check(t->callback_fn, rcu_read_lock_bh_held());
1079 if (!callback_fn)1081 if (!callback_fn)
1080 goto out;1082 goto out;