bpf: Count missed stats in trace_call_bpf
authorJiri Olsa <jolsa@kernel.org>
Wed, 20 Sep 2023 21:31:40 +0000 (23:31 +0200)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 25 Sep 2023 23:37:44 +0000 (16:37 -0700)
Increase misses stats in case bpf array execution is skipped
because of recursion check in trace_call_bpf.

Adding bpf_prog_inc_misses_counters that increase misses
counts for all bpf programs in bpf_prog_array.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Song Liu <song@kernel.org>
Reviewed-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/bpf/20230920213145.1941596-5-jolsa@kernel.org
include/linux/bpf.h
kernel/trace/bpf_trace.c

index 30063a760b5afdc804593c0ea79fbdb8f0e2b475..a82efd34b7414bdc87aa2b4016c0836d55fc893e 100644 (file)
@@ -2922,6 +2922,22 @@ static inline int sock_map_bpf_prog_query(const union bpf_attr *attr,
 #endif /* CONFIG_BPF_SYSCALL */
 #endif /* CONFIG_NET && CONFIG_BPF_SYSCALL */
 
+static __always_inline void
+bpf_prog_inc_misses_counters(const struct bpf_prog_array *array)
+{
+       const struct bpf_prog_array_item *item;
+       struct bpf_prog *prog;
+
+       if (unlikely(!array))
+               return;
+
+       item = &array->items[0];
+       while ((prog = READ_ONCE(item->prog))) {
+               bpf_prog_inc_misses_counter(prog);
+               item++;
+       }
+}
+
 #if defined(CONFIG_INET) && defined(CONFIG_BPF_SYSCALL)
 void bpf_sk_reuseport_detach(struct sock *sk);
 int bpf_fd_reuseport_array_lookup_elem(struct bpf_map *map, void *key,
index f6a7d25249496916d0b5e1e9234340c629d5c156..df697c74d5197a21a49691cced48138397851076 100644 (file)
@@ -117,6 +117,9 @@ unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
                 * and don't send kprobe event into ring-buffer,
                 * so return zero here
                 */
+               rcu_read_lock();
+               bpf_prog_inc_misses_counters(rcu_dereference(call->prog_array));
+               rcu_read_unlock();
                ret = 0;
                goto out;
        }