Skip to contentSkip to conversation

syscalls/bpf: auto bump RLIMIT_MEMLOCK

PATCH New Jan Stancek 2 participants 3 messages Sep 26, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/bpf: auto bump RLIMIT_MEMLOCK

eBPF tests may fail (-EPERM) if max locked memory limit is too low. User-space tools such as perf started increasing MELOCK limit to avoid this problem.

LTP follows same approach and will attempt to raise RLIMIT_MEMLOCK if possible, otherwise prints an info message.

---
 testcases/kernel/syscalls/bpf/bpf_common.h | 31 ++++++++++++++++++++++++++++++
 testcases/kernel/syscalls/bpf/bpf_map01.c  |  3 +++
 testcases/kernel/syscalls/bpf/bpf_prog01.c |  3 +++
 3 files changed, 37 insertions(+)
 create mode 100644 testcases/kernel/syscalls/bpf/bpf_common.h
testcases/kernel/syscalls/bpf/bpf_common.h new file +31 -0
new file mode 100644
index 000000000000..03e46c5d427e
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2019 Linux Test Project
+ */
+
+#ifndef LTP_BPF_COMMON_H
+#define LTP_BPF_COMMON_H
+
+#define BPF_MEMLOCK_ADD (256*1024)
+
+void rlimit_bump_memlock(void)
+{
+	struct rlimit memlock_r;
+
+	SAFE_GETRLIMIT(RLIMIT_MEMLOCK, &memlock_r);
+	memlock_r.rlim_cur += BPF_MEMLOCK_ADD;
+	tst_res(TINFO, "Raising RLIMIT_MEMLOCK to %ld",
+		(long)memlock_r.rlim_cur);
+
+	if (memlock_r.rlim_cur <= memlock_r.rlim_max) {
+		SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &memlock_r);
+	} else if ((geteuid() == 0)) {
+		memlock_r.rlim_max += BPF_MEMLOCK_ADD;
+		SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &memlock_r);
+	} else {
+		tst_res(TINFO, "Can't raise RLIMIT_MEMLOCK, test may fail "
+			"due to lack of max locked memory");
+	}
+}
+
+#endif
testcases/kernel/syscalls/bpf/bpf_map01.c +3 -0
index 13dde0b4e12f..49d32776ef41 100644
@@ -17,6 +17,7 @@
 #include "config.h"
 #include "tst_test.h"
 #include "lapi/bpf.h"
+#include "bpf_common.h"
 
 #define VAL_SZ 1024
 
@@ -140,6 +141,8 @@ static void setup(void)
 {
 	unsigned int i;
 
+	rlimit_bump_memlock();
+
 	memcpy(key8, "12345678", 8);
 	memset(key4, 0, 4);
 
testcases/kernel/syscalls/bpf/bpf_prog01.c +3 -0
index 3252f92774d1..46a909fe2ec4 100644
@@ -27,6 +27,7 @@
 #include "tst_test.h"
 #include "lapi/socket.h"
 #include "lapi/bpf.h"
+#include "bpf_common.h"
 
 const char MSG[] = "Ahoj!";
 static char *msg;
@@ -94,6 +95,8 @@ int load_prog(int fd)
 
 void setup(void)
 {
+	rlimit_bump_memlock();
+
 	memcpy(prog, PROG, sizeof(PROG));
 	memcpy(msg, MSG, sizeof(MSG));
 }
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 syscalls/bpf: auto bump RLIMIT_MEMLOCK

Hi!

Quoted 10 lines

eBPF tests may fail (-EPERM) if max locked memory limit is too low. User-space tools such as perf started increasing MELOCK limit to avoid this problem.

LTP follows same approach and will attempt to raise RLIMIT_MEMLOCK if possible, otherwise prints an info message.

Looks good, acked.

Also have you had a look at the eBPF regression test?

Do you mind if I push that before the release (with added call to adjust the memlock limit)?

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 syscalls/bpf: auto bump RLIMIT_MEMLOCK

----- Original Message -----

Quoted 5 lines

Hi!

Quoted 4 lines

eBPF tests may fail (-EPERM) if max locked memory limit is too low. User-space tools such as perf started increasing MELOCK limit to avoid this problem.

Quoted 8 lines
Quoted 6 lines

LTP follows same approach and will attempt to raise RLIMIT_MEMLOCK if possible, otherwise prints an info message.

Looks good, acked.

Thanks, pushed with typo above fixed: s/MELOCK/MEMLOCK/.

Quoted 5 lines

Also have you had a look at the eBPF regression test?

Do you mind if I push that before the release (with added call to adjust the memlock limit)?

If you mean "Regression test for 64bit arithmetic", I think that's OK for release.

Quoted 5 lines

--
Cyril Hrubis
[email protected]