Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f1b5a2b authored by Alexei Starovoitov's avatar Alexei Starovoitov
Browse files

Merge branch 'bpf-kselftest-improvements'



Daniel Borkmann says:

====================
First one unifies the often repeated rlimit handling and the
second one enables and adds run-time tests for BPF tail calls
which provides useful coverage in particular for JITs.
====================

Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents 3808b519 b33eb735
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
#include <sys/resource.h>
#include <stdio.h>

static  __attribute__((constructor)) void bpf_rlimit_ctor(void)
{
	struct rlimit rlim_old, rlim_new = {
		.rlim_cur	= RLIM_INFINITY,
		.rlim_max	= RLIM_INFINITY,
	};

	getrlimit(RLIMIT_MEMLOCK, &rlim_old);
	/* For the sake of running the test cases, we temporarily
	 * set rlimit to infinity in order for kernel to focus on
	 * errors from actual test cases and not getting noise
	 * from hitting memlock limits. The limit is on per-process
	 * basis and not a global one, hence destructor not really
	 * needed here.
	 */
	if (setrlimit(RLIMIT_MEMLOCK, &rlim_new) < 0) {
		perror("Unable to lift memlock rlimit");
		/* Trying out lower limit, but expect potential test
		 * case failures from this!
		 */
		rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
		rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
		setrlimit(RLIMIT_MEMLOCK, &rlim_new);
	}
}
+1 −5
Original line number Diff line number Diff line
@@ -9,8 +9,6 @@
#include <stddef.h>
#include <stdbool.h>

#include <sys/resource.h>

#include <linux/unistd.h>
#include <linux/filter.h>
#include <linux/bpf_perf_event.h>
@@ -19,6 +17,7 @@
#include <bpf/bpf.h>

#include "../../../include/linux/filter.h"
#include "bpf_rlimit.h"

#ifndef ARRAY_SIZE
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
@@ -702,9 +701,6 @@ static int do_test(unsigned int from, unsigned int to)
int main(int argc, char **argv)
{
	unsigned int from = 0, to = ARRAY_SIZE(tests);
	struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY };

	setrlimit(RLIMIT_MEMLOCK, &rinf);

	if (argc == 3) {
		unsigned int l = atoi(argv[argc - 2]);
+1 −5
Original line number Diff line number Diff line
@@ -11,13 +11,13 @@
#include <errno.h>
#include <assert.h>
#include <sys/time.h>
#include <sys/resource.h>

#include <linux/bpf.h>
#include <bpf/bpf.h>
#include <bpf/libbpf.h>

#include "cgroup_helpers.h"
#include "bpf_rlimit.h"

#define DEV_CGROUP_PROG "./dev_cgroup.o"

@@ -25,15 +25,11 @@

int main(int argc, char **argv)
{
	struct rlimit limit  = { RLIM_INFINITY, RLIM_INFINITY };
	struct bpf_object *obj;
	int error = EXIT_FAILURE;
	int prog_fd, cgroup_fd;
	__u32 prog_cnt;

	if (setrlimit(RLIMIT_MEMLOCK, &limit) < 0)
		perror("Unable to lift memlock rlimit");

	if (bpf_prog_load(DEV_CGROUP_PROG, BPF_PROG_TYPE_CGROUP_DEVICE,
			  &obj, &prog_fd)) {
		printf("Failed to load DEV_CGROUP program\n");
+3 −11
Original line number Diff line number Diff line
@@ -22,10 +22,11 @@
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/resource.h>

#include <bpf/bpf.h>

#include "bpf_util.h"
#include "bpf_rlimit.h"

struct tlpm_node {
	struct tlpm_node *next;
@@ -736,17 +737,11 @@ static void test_lpm_multi_thread(void)

int main(void)
{
	struct rlimit limit  = { RLIM_INFINITY, RLIM_INFINITY };
	int i, ret;
	int i;

	/* we want predictable, pseudo random tests */
	srand(0xf00ba1);

	/* allow unlimited locked memory */
	ret = setrlimit(RLIMIT_MEMLOCK, &limit);
	if (ret < 0)
		perror("Unable to lift memlock rlimit");

	test_lpm_basic();
	test_lpm_order();

@@ -755,11 +750,8 @@ int main(void)
		test_lpm_map(i);

	test_lpm_ipaddr();

	test_lpm_delete();

	test_lpm_get_next_key();

	test_lpm_multi_thread();

	printf("test_lpm: OK\n");
+2 −4
Original line number Diff line number Diff line
@@ -16,10 +16,11 @@
#include <time.h>

#include <sys/wait.h>
#include <sys/resource.h>

#include <bpf/bpf.h>

#include "bpf_util.h"
#include "bpf_rlimit.h"

#define LOCAL_FREE_TARGET	(128)
#define PERCPU_FREE_TARGET	(4)
@@ -613,7 +614,6 @@ static void test_lru_sanity6(int map_type, int map_flags, int tgt_free)

int main(int argc, char **argv)
{
	struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
	int map_types[] = {BPF_MAP_TYPE_LRU_HASH,
			     BPF_MAP_TYPE_LRU_PERCPU_HASH};
	int map_flags[] = {0, BPF_F_NO_COMMON_LRU};
@@ -621,8 +621,6 @@ int main(int argc, char **argv)

	setbuf(stdout, NULL);

	assert(!setrlimit(RLIMIT_MEMLOCK, &r));

	nr_cpus = bpf_num_possible_cpus();
	assert(nr_cpus != -1);
	printf("nr_cpus:%d\n\n", nr_cpus);
Loading