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
22 /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
33 */
44 #include <linux/bpf.h>
5+#include <linux/btf.h>
56 #include <linux/bpf-cgroup.h>
67 #include <linux/rcupdate.h>
78 #include <linux/random.h>
@@ -1075,6 +1076,7 @@ static enum hrtimer_restart bpf_timer_cb(struct hrtimer *hrtimer) · 1067 unmodified lines
10751076 void *key;
10761077 u32 idx;
10771078
1079+ BTF_TYPE_EMIT(struct bpf_timer);
10781080 callback_fn = rcu_dereference_check(t->callback_fn, rcu_read_lock_bh_held());
10791081 if (!callback_fn)
10801082 goto out;