syscalls/bpf: auto bump RLIMIT_MEMLOCK
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
@@ -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
@@ -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
@@ -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
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_MEMLOCKif 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]
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_MEMLOCKif 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]