[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171221094905.4872-1-bhole_prashant_q7@lab.ntt.co.jp>
Date: Thu, 21 Dec 2017 18:49:05 +0900
From: Prashant Bhole <bhole_prashant_q7@....ntt.co.jp>
To: Alexei Starovoitov <ast@...nel.org>
Cc: Prashant Bhole <bhole_prashant_q7@....ntt.co.jp>,
Daniel Borkmann <daniel@...earbox.net>, netdev@...r.kernel.org
Subject: [PATCH bpf-next] samples/bpf: adjust rlimit RLIMIT_MEMLOCK for sampleip
The default memlock rlimit is 64KB, which causes failure in
creating a map
For example:
test@...t# ./sampleip
failed to create a map: 1 Operation not permitted
ERROR: loading BPF program (errno 1):
Try: ulimit -l unlimited
Signed-off-by: Prashant Bhole <bhole_prashant_q7@....ntt.co.jp>
---
samples/bpf/sampleip_user.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/samples/bpf/sampleip_user.c b/samples/bpf/sampleip_user.c
index 4ed690b907ff..f240a7db7c0a 100644
--- a/samples/bpf/sampleip_user.c
+++ b/samples/bpf/sampleip_user.c
@@ -19,6 +19,7 @@
#include <linux/ptrace.h>
#include <linux/bpf.h>
#include <sys/ioctl.h>
+#include <sys/resource.h>
#include "libbpf.h"
#include "bpf_load.h"
#include "perf-sys.h"
@@ -132,8 +133,9 @@ static void int_exit(int sig)
int main(int argc, char **argv)
{
- char filename[256];
int *pmu_fd, opt, freq = DEFAULT_FREQ, secs = DEFAULT_SECS;
+ struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
+ char filename[256];
/* process arguments */
while ((opt = getopt(argc, argv, "F:h")) != -1) {
@@ -154,6 +156,11 @@ int main(int argc, char **argv)
return 1;
}
+ if (setrlimit(RLIMIT_MEMLOCK, &r)) {
+ perror("Failed to set memlock rlimit");
+ return 1;
+ }
+
/* initialize kernel symbol translation */
if (load_kallsyms()) {
fprintf(stderr, "ERROR: loading /proc/kallsyms\n");
@@ -171,12 +178,8 @@ int main(int argc, char **argv)
/* load BPF program */
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
if (load_bpf_file(filename)) {
- fprintf(stderr, "ERROR: loading BPF program (errno %d):\n",
- errno);
- if (strcmp(bpf_log_buf, "") == 0)
- fprintf(stderr, "Try: ulimit -l unlimited\n");
- else
- fprintf(stderr, "%s", bpf_log_buf);
+ fprintf(stderr, "ERROR: loading BPF program (errno %d): %s\n",
+ errno, bpf_log_buf);
return 1;
}
signal(SIGINT, int_exit);
--
2.13.6
Powered by blists - more mailing lists