mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
Similarly to subprog/callback logic, enforce return value of BPF program using more precise smin/smax range. We need to adjust a bunch of tests due to a changed format of an error message. Acked-by: Eduard Zingerman <eddyz87@gmail.com> Acked-by: Shung-Hsi Yu <shung-hsi.yu@suse.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20231202175705.885270-7-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
48 lines
976 B
C
48 lines
976 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
|
|
|
|
#include <linux/bpf.h>
|
|
#include <time.h>
|
|
#include <errno.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
#include "bpf_misc.h"
|
|
#include "bpf_tcp_helpers.h"
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
struct elem {
|
|
struct bpf_timer t;
|
|
};
|
|
|
|
struct {
|
|
__uint(type, BPF_MAP_TYPE_ARRAY);
|
|
__uint(max_entries, 1);
|
|
__type(key, int);
|
|
__type(value, struct elem);
|
|
} timer_map SEC(".maps");
|
|
|
|
static int timer_cb_ret1(void *map, int *key, struct bpf_timer *timer)
|
|
{
|
|
if (bpf_get_smp_processor_id() % 2)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
SEC("fentry/bpf_fentry_test1")
|
|
__failure __msg("should have been in [0, 0]")
|
|
int BPF_PROG2(test_ret_1, int, a)
|
|
{
|
|
int key = 0;
|
|
struct bpf_timer *timer;
|
|
|
|
timer = bpf_map_lookup_elem(&timer_map, &key);
|
|
if (timer) {
|
|
bpf_timer_init(timer, &timer_map, CLOCK_BOOTTIME);
|
|
bpf_timer_set_callback(timer, timer_cb_ret1);
|
|
bpf_timer_start(timer, 1000, 0);
|
|
}
|
|
|
|
return 0;
|
|
}
|