Skip to content

Commit

Permalink
samples/bpf: Set rlimit for memlock to infinity in all samples
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Acked-by: Andrii Nakryiko <[email protected]>
Acked-by: Jesper Dangaard Brouer <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
tohojo authored and borkmann committed Oct 27, 2020
1 parent 343a3e8 commit c66dca9
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion samples/bpf/task_fd_query_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion samples/bpf/tracex2_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion samples/bpf/tracex3_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion samples/bpf/xdp_redirect_cpu_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion samples/bpf/xdp_rxq_info_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit c66dca9

Please sign in to comment.