|
41 | 41 | #include <sys/types.h>
|
42 | 42 | #include <sys/vfs.h>
|
43 | 43 | #include <sys/utsname.h>
|
| 44 | +#include <sys/resource.h> |
44 | 45 | #include <tools/libc_compat.h>
|
45 | 46 | #include <libelf.h>
|
46 | 47 | #include <gelf.h>
|
@@ -100,6 +101,32 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...)
|
100 | 101 | va_end(args);
|
101 | 102 | }
|
102 | 103 |
|
| 104 | +static void pr_perm_msg(int err) |
| 105 | +{ |
| 106 | + struct rlimit limit; |
| 107 | + char buf[100]; |
| 108 | + |
| 109 | + if (err != -EPERM || geteuid() != 0) |
| 110 | + return; |
| 111 | + |
| 112 | + err = getrlimit(RLIMIT_MEMLOCK, &limit); |
| 113 | + if (err) |
| 114 | + return; |
| 115 | + |
| 116 | + if (limit.rlim_cur == RLIM_INFINITY) |
| 117 | + return; |
| 118 | + |
| 119 | + if (limit.rlim_cur < 1024) |
| 120 | + snprintf(buf, sizeof(buf), "%lu bytes", limit.rlim_cur); |
| 121 | + else if (limit.rlim_cur < 1024*1024) |
| 122 | + snprintf(buf, sizeof(buf), "%.1f KiB", (double)limit.rlim_cur / 1024); |
| 123 | + else |
| 124 | + snprintf(buf, sizeof(buf), "%.1f MiB", (double)limit.rlim_cur / (1024*1024)); |
| 125 | + |
| 126 | + pr_warn("permission error while running as root; try raising 'ulimit -l'? current value: %s\n", |
| 127 | + buf); |
| 128 | +} |
| 129 | + |
103 | 130 | #define STRERR_BUFSIZE 128
|
104 | 131 |
|
105 | 132 | /* Copied from tools/perf/util/util.h */
|
@@ -2983,6 +3010,7 @@ bpf_object__create_maps(struct bpf_object *obj)
|
2983 | 3010 | cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg));
|
2984 | 3011 | pr_warn("failed to create map (name: '%s'): %s(%d)\n",
|
2985 | 3012 | map->name, cp, err);
|
| 3013 | + pr_perm_msg(err); |
2986 | 3014 | for (j = 0; j < i; j++)
|
2987 | 3015 | zclose(obj->maps[j].fd);
|
2988 | 3016 | return err;
|
@@ -4381,6 +4409,7 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt,
|
4381 | 4409 | ret = -errno;
|
4382 | 4410 | cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
|
4383 | 4411 | pr_warn("load bpf program failed: %s\n", cp);
|
| 4412 | + pr_perm_msg(ret); |
4384 | 4413 |
|
4385 | 4414 | if (log_buf && log_buf[0] != '\0') {
|
4386 | 4415 | ret = -LIBBPF_ERRNO__VERIFY;
|
|
0 commit comments