samples/bpf: Set rlimit for memlock to infinity in all samples
authorToke Høiland-Jørgensen <toke@redhat.com>
Mon, 26 Oct 2020 23:36:23 +0000 (00:36 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 27 Oct 2020 21:46:17 +0000 (22:46 +0100)
The memlock rlimit is a notorious source of failure for BPF programs. Most
of the samples just set it to infinity, but a few used a lower limit. The
problem with unconditionally setting a lower limit is that this will also
override the limit if the system-wide setting is *higher* than the limit
being set, which can lead to failures on systems that lock a lot of memory,
but set 'ulimit -l' to unlimited before running a sample.

One fix for this is to only conditionally set the limit if the current
limit is lower, but it is simpler to just unify all the samples and have
them all set the limit to infinity.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Link: https://lore.kernel.org/bpf/20201026233623.91728-1-toke@redhat.com
samples/bpf/task_fd_query_user.c
samples/bpf/tracex2_user.c
samples/bpf/tracex3_user.c
samples/bpf/xdp_redirect_cpu_user.c
samples/bpf/xdp_rxq_info_user.c

index 4a74531dc403105d0dac2204367af32652d48fd2..b68bd2f8fdc924a5df2f32a12b4974d60c0b99ec 100644 (file)
@@ -290,7 +290,7 @@ static int test_debug_fs_uprobe(char *binary_path, long offset, bool is_return)
 
 int main(int argc, char **argv)
 {
-       struct rlimit r = {1024*1024, RLIM_INFINITY};
+       struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
        extern char __executable_start;
        char filename[256], buf[256];
        __u64 uprobe_file_offset;
index 3e36b3e4e3efdb282abb08262ce1a86a880fce19..3d6eab711d23e11158855ea9c6074ad184a916ef 100644 (file)
@@ -116,7 +116,7 @@ static void int_exit(int sig)
 
 int main(int ac, char **argv)
 {
-       struct rlimit r = {1024*1024, RLIM_INFINITY};
+       struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
        long key, next_key, value;
        struct bpf_link *links[2];
        struct bpf_program *prog;
index 70e987775c156f90e9c9a383fe1252a6c37b249f..83e0fecbb01ace489ba038522fd1b8c3d695301d 100644 (file)
@@ -107,7 +107,7 @@ static void print_hist(int fd)
 
 int main(int ac, char **argv)
 {
-       struct rlimit r = {1024*1024, RLIM_INFINITY};
+       struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
        struct bpf_link *links[2];
        struct bpf_program *prog;
        struct bpf_object *obj;
index 6fb8dbde62c5e0e5f0f760fb221dd6640c7eaa9e..f78cb18319aaf9d17346c0d8906de761ea27787a 100644 (file)
@@ -765,7 +765,7 @@ static int load_cpumap_prog(char *file_name, char *prog_name,
 
 int main(int argc, char **argv)
 {
-       struct rlimit r = {10 * 1024 * 1024, RLIM_INFINITY};
+       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;
index caa4e7ffcfc7b85eeb04b6320c6b665b99d7db37..93fa1bc54f131eb5c441e0899fec3c53ea0f9a1c 100644 (file)
@@ -450,7 +450,7 @@ static void stats_poll(int interval, int action, __u32 cfg_opt)
 int main(int argc, char **argv)
 {
        __u32 cfg_options= NO_TOUCH ; /* Default: Don't touch packet memory */
-       struct rlimit r = {10 * 1024 * 1024, RLIM_INFINITY};
+       struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
        struct bpf_prog_load_attr prog_load_attr = {
                .prog_type      = BPF_PROG_TYPE_XDP,
        };