Skip to content

Commit

Permalink
bpf: samples: Do not touch RLIMIT_MEMLOCK
Browse files Browse the repository at this point in the history
Since bpf is not using rlimit memlock for the memory accounting
and control, do not change the limit in sample applications.

Signed-off-by: Roman Gushchin <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Acked-by: Song Liu <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
rgushchin authored and Alexei Starovoitov committed Dec 3, 2020
1 parent 3ac1f01 commit 5b0764b
Show file tree
Hide file tree
Showing 27 changed files with 0 additions and 133 deletions.
6 changes: 0 additions & 6 deletions samples/bpf/map_perf_test_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ static void fixup_map(struct bpf_object *obj)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
int nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
struct bpf_link *links[8];
struct bpf_program *prog;
Expand All @@ -430,11 +429,6 @@ int main(int argc, char **argv)
char filename[256];
int i = 0;

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return 1;
}

if (argc > 1)
test_flags = atoi(argv[1]) ? : test_flags;

Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/offwaketime_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,12 @@ static void int_exit(int sig)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_object *obj = NULL;
struct bpf_link *links[2];
struct bpf_program *prog;
int delay = 1, i = 0;
char filename[256];

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return 1;
}

if (load_kallsyms()) {
printf("failed to process /proc/kallsyms\n");
return 2;
Expand Down
2 changes: 0 additions & 2 deletions samples/bpf/sockex2_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ struct pair {

int main(int ac, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_object *obj;
int map_fd, prog_fd;
char filename[256];
int i, sock;
FILE *f;

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
setrlimit(RLIMIT_MEMLOCK, &r);

if (bpf_prog_load(filename, BPF_PROG_TYPE_SOCKET_FILTER,
&obj, &prog_fd))
Expand Down
2 changes: 0 additions & 2 deletions samples/bpf/sockex3_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ struct pair {
int main(int argc, char **argv)
{
int i, sock, key, fd, main_prog_fd, jmp_table_fd, hash_map_fd;
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_program *prog;
struct bpf_object *obj;
const char *section;
char filename[256];
FILE *f;

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
setrlimit(RLIMIT_MEMLOCK, &r);

obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/spintest_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

int main(int ac, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
char filename[256], symbol[256];
struct bpf_object *obj = NULL;
struct bpf_link *links[20];
Expand All @@ -20,11 +19,6 @@ int main(int ac, char **argv)
const char *section;
struct ksym *sym;

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return 1;
}

if (load_kallsyms()) {
printf("failed to process /proc/kallsyms\n");
return 2;
Expand Down
2 changes: 0 additions & 2 deletions samples/bpf/syscall_tp_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ static int test(char *filename, int num_progs)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
int opt, num_progs = 1;
char filename[256];

Expand All @@ -131,7 +130,6 @@ int main(int argc, char **argv)
}
}

setrlimit(RLIMIT_MEMLOCK, &r);
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);

return test(filename, num_progs);
Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/task_fd_query_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,13 @@ static int test_debug_fs_uprobe(char *binary_path, long offset, bool is_return)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
extern char __executable_start;
char filename[256], buf[256];
__u64 uprobe_file_offset;
struct bpf_program *prog;
struct bpf_object *obj;
int i = 0, err = -1;

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return err;
}

if (load_kallsyms()) {
printf("failed to process /proc/kallsyms\n");
return err;
Expand Down
3 changes: 0 additions & 3 deletions samples/bpf/test_lru_dist.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ static void test_parallel_lru_loss(int map_type, int map_flags, int nr_tasks)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
int map_flags[] = {0, BPF_F_NO_COMMON_LRU};
const char *dist_file;
int nr_tasks = 1;
Expand All @@ -508,8 +507,6 @@ int main(int argc, char **argv)

setbuf(stdout, NULL);

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

srand(time(NULL));

nr_cpus = bpf_num_possible_cpus();
Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/test_map_in_map_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,11 @@ static void test_map_in_map(void)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_link *link = NULL;
struct bpf_program *prog;
struct bpf_object *obj;
char filename[256];

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return 1;
}

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
Expand Down
2 changes: 0 additions & 2 deletions samples/bpf/test_overhead_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,11 @@ static void unload_progs(void)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
int num_cpu = sysconf(_SC_NPROCESSORS_ONLN);
int test_flags = ~0;
char filename[256];
int err = 0;

setrlimit(RLIMIT_MEMLOCK, &r);

if (argc > 1)
test_flags = atoi(argv[1]) ? : test_flags;
Expand Down
2 changes: 0 additions & 2 deletions samples/bpf/trace_event_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,11 @@ static void test_bpf_perf_event(void)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_object *obj = NULL;
char filename[256];
int error = 1;

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
setrlimit(RLIMIT_MEMLOCK, &r);

signal(SIGINT, err_exit);
signal(SIGTERM, err_exit);
Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/tracex2_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ static void int_exit(int sig)

int main(int ac, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
long key, next_key, value;
struct bpf_link *links[2];
struct bpf_program *prog;
Expand All @@ -125,11 +124,6 @@ int main(int ac, char **argv)
int i, j = 0;
FILE *f;

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return 1;
}

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/tracex3_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ static void print_hist(int fd)

int main(int ac, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_link *links[2];
struct bpf_program *prog;
struct bpf_object *obj;
Expand All @@ -127,11 +126,6 @@ int main(int ac, char **argv)
}
}

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return 1;
}

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/tracex4_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,12 @@ static void print_old_objects(int fd)

int main(int ac, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_link *links[2];
struct bpf_program *prog;
struct bpf_object *obj;
char filename[256];
int map_fd, i, j = 0;

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK, RLIM_INFINITY)");
return 1;
}

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
Expand Down
3 changes: 0 additions & 3 deletions samples/bpf/tracex5_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ static void install_accept_all_seccomp(void)

int main(int ac, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_link *link = NULL;
struct bpf_program *prog;
struct bpf_object *obj;
Expand All @@ -43,8 +42,6 @@ int main(int ac, char **argv)
char filename[256];
FILE *f;

setrlimit(RLIMIT_MEMLOCK, &r);

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
Expand Down
3 changes: 0 additions & 3 deletions samples/bpf/tracex6_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,12 @@ static void test_bpf_perf_event(void)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_link *links[2];
struct bpf_program *prog;
struct bpf_object *obj;
char filename[256];
int i = 0;

setrlimit(RLIMIT_MEMLOCK, &r);

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/xdp1_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ static void usage(const char *prog)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
Expand Down Expand Up @@ -117,11 +116,6 @@ int main(int argc, char **argv)
return 1;
}

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return 1;
}

ifindex = if_nametoindex(argv[optind]);
if (!ifindex) {
perror("if_nametoindex");
Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/xdp_adjust_tail_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ static void usage(const char *cmd)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
Expand Down Expand Up @@ -143,11 +142,6 @@ int main(int argc, char **argv)
}
}

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK, RLIM_INFINITY)");
return 1;
}

if (!ifindex) {
fprintf(stderr, "Invalid ifname\n");
return 1;
Expand Down
5 changes: 0 additions & 5 deletions samples/bpf/xdp_monitor_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,6 @@ static void print_bpf_prog_info(void)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_program *prog;
int longindex = 0, opt;
int ret = EXIT_FAILURE;
Expand Down Expand Up @@ -719,10 +718,6 @@ int main(int argc, char **argv)
}

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return ret;
}

/* Remove tracepoint program when program is interrupted or killed */
signal(SIGINT, int_exit);
Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/xdp_redirect_cpu_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,6 @@ static int load_cpumap_prog(char *file_name, char *prog_name,

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
char *prog_name = "xdp_cpu_map5_lb_hash_ip_pairs";
char *mprog_filename = "xdp_redirect_kern.o";
char *redir_interface = NULL, *redir_map = NULL;
Expand Down Expand Up @@ -804,11 +803,6 @@ int main(int argc, char **argv)
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return 1;
}

if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd))
return err;

Expand Down
6 changes: 0 additions & 6 deletions samples/bpf/xdp_redirect_map_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ static void usage(const char *prog)

int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
Expand Down Expand Up @@ -135,11 +134,6 @@ int main(int argc, char **argv)
return 1;
}

if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return 1;
}

ifindex_in = if_nametoindex(argv[optind]);
if (!ifindex_in)
ifindex_in = strtoul(argv[optind], NULL, 0);
Expand Down
Loading

0 comments on commit 5b0764b

Please sign in to comment.