Re: [PATCH bpf-next 2/2] selftests/bpf: mix legacy (maps) and modern (vars) BPF in one test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> On Nov 19, 2021, at 3:14 PM, Andrii Nakryiko <andrii@xxxxxxxxxx> wrote:
> 
> Add selftest that combines two BPF programs within single BPF object
> file such that one of the programs is using global variables, but can be
> skipped at runtime on old kernels that don't support global data.
> Another BPF program is written with the goal to be runnable on very old
> kernels and only relies on explicitly accessed BPF maps.
> 
> Such test, run against old kernels (e.g., libbpf CI will run it against 4.9
> kernel that doesn't support global data), allows to test the approach
> and ensure that libbpf doesn't make unnecessary assumption about
> necessary kernel features.
> 
> Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>

Acked-by: Song Liu <songliubraving@xxxxxx>

With one nit below. 

> ---
> .../selftests/bpf/prog_tests/legacy_printk.c  | 65 +++++++++++++++++++
> .../selftests/bpf/progs/test_legacy_printk.c  | 65 +++++++++++++++++++
> 2 files changed, 130 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/legacy_printk.c
> create mode 100644 tools/testing/selftests/bpf/progs/test_legacy_printk.c
> 
[...]

> +SEC("tp/raw_syscalls/sys_enter")
> +int handle_legacy(void *ctx)
> +{
> +	int zero = 0, *my_pid, cur_pid, *my_res;
> +
> +	my_pid = bpf_map_lookup_elem(&my_pid_map, &zero);
> +	if (!my_pid)
> +		return 1;
> +
> +	cur_pid = bpf_get_current_pid_tgid() >> 32;
> +	if (cur_pid != *my_pid)
> +		return 1;
> +
> +	my_res = bpf_map_lookup_elem(&res_map, &zero);
> +	if (!my_res)
> +		return 1;
> +
> +	if (*my_res == 0)
> +		bpf_printk("Legacy-case bpf_printk test, pid %d\n", cur_pid);

I think we discourage bpf_printk in selftests in general, but we do need the
bpf_printk here. So maybe add a comment here (and below) to explain the case?

Thanks,
Song

> +	*my_res = 1;
> +
> +	return *my_res;
> +}
> +
> +SEC("tp/raw_syscalls/sys_enter")
> +int handle_modern(void *ctx)
> +{
> +	int zero = 0, cur_pid;
> +
> +	cur_pid = bpf_get_current_pid_tgid() >> 32;
> +	if (cur_pid != my_pid_var)
> +		return 1;
> +
> +	if (res_var == 0)
> +		bpf_printk("Modern-case bpf_printk test, pid %d\n", cur_pid);
> +	res_var = 1;
> +
> +	return res_var;
> +}
> -- 
> 2.30.2
> 




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux