[PATCH testsuite v2] tests/io_uring/iouring.c: bump RLIMIT_MEMLOCK up to hard limit
Ondrej Mosnacek <[email protected]>
| Newsgroups | org.kernel.vger.selinux |
|---|---|
| Message-ID | <[email protected]> |
Test domains may get their soft resource limits lowered on transition
due to the typically denied rlimitinh permission. However, the resulting
RLIMIT_MEMLOCK limit may not be enough to run the io_uring test program
in some cases (low init task's limit + large page size, for example).
Ensure that io_uring tests can run successfully in such environments as
well by bumping the soft limit to the hard limit (which should be
sufficient everywhere) in iouring.c.
The issue can be observed for example on CentOS Stream 9 on aarch64 or
ppc64le.
Fixes: 3b4e44eb3243 ("Add tests for io_uring")
Signed-off-by: Ondrej Mosnacek <[email protected]>
---
This is an alternative (better) approach to fix the problem described
in the v1 patch:
https://lore.kernel.org/selinux/[email protected]/
tests/io_uring/iouring.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tests/io_uring/iouring.c b/tests/io_uring/iouring.c
index d5f9cbc..36b014f 100644
--- a/tests/io_uring/iouring.c
+++ b/tests/io_uring/iouring.c
@@ -68,6 +68,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
+#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -475,6 +476,7 @@ int main(int argc, char *argv[])
struct urt_config *cfg_p;
char *progname;
char *progdir;
+ struct rlimit rlim;
enum { TST_UNKNOWN,
TST_SQPOLL,
@@ -500,6 +502,19 @@ int main(int argc, char *argv[])
progname = strdup(argv[0]);
progdir = dirname(progname);
+ /*
+ * bump RLIMIT_MEMLOCK up to hard limit (some operations may need it,
+ * especially if PAGE_SIZE is big)
+ */
+ if (getrlimit(RLIMIT_MEMLOCK, &rlim))
+ fatal("getrlimit");
+
+ if (rlim.rlim_cur < rlim.rlim_max) {
+ rlim.rlim_cur = rlim.rlim_max;
+ if (setrlimit(RLIMIT_MEMLOCK, &rlim))
+ fatal("setrlimit");
+ }
+
snprintf(uring_path, sizeof(uring_path), "%s/iouring.out", progdir);
/* simple header */
--
2.55.0