Skip to contentSkip to conversation

non-root tests

PATCH Applied Pavel Begunkov 2 participants 4 messages Aug 25, 2021 io_uring

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 tests: don't skip sqpoll needlessly

In reply to Pavel Begunkov

Newer kernels support non-privileged SQPOLL, don't skip sqpoll testing in sq-poll-kthread and others when it would work just fine.

---
 test/d4ae271dfaae-test.c |  5 -----
 test/sq-poll-kthread.c   | 14 ++++++--------
 2 files changed, 6 insertions(+), 13 deletions(-)
test/d4ae271dfaae-test.c +0 -5
index 80d3f71..10c7e98 100644
@@ -27,11 +27,6 @@ int main(int argc, char *argv[])
 	char *fname;
 	void *buf;
 
-	if (geteuid()) {
-		fprintf(stdout, "Test requires root, skipping\n");
-		return 0;
-	}
-
 	memset(&p, 0, sizeof(p));
 	p.flags = IORING_SETUP_SQPOLL;
 	ret = t_create_ring_params(4, &ring, &p);
test/sq-poll-kthread.c +6 -8
index ed7d0bf..0a0a75a 100644
@@ -17,6 +17,7 @@
 #include <sys/epoll.h>
 
 #include "liburing.h"
+#include "helpers.h"
 
 #define SQ_THREAD_IDLE  2000
 #define BUF_SIZE        128
@@ -38,23 +39,20 @@ static int do_test_sq_poll_kthread_stopped(bool do_exit)
 	uint8_t buf[BUF_SIZE];
 	struct iovec iov;
 
-	if (geteuid()) {
-		fprintf(stderr, "sqpoll requires root!\n");
-		return TEST_SKIPPED;
-	}
-
 	if (pipe(pipe1) != 0) {
 		perror("pipe");
 		return TEST_FAILED;
 	}
 
 	memset(&param, 0, sizeof(param));
-
 	param.flags |= IORING_SETUP_SQPOLL;
 	param.sq_thread_idle = SQ_THREAD_IDLE;
 
-	ret = io_uring_queue_init_params(16, &ring, &param);
-	if (ret) {
+	ret = t_create_ring_params(16, &ring, &param);
+	if (ret == T_SETUP_SKIP) {
+		ret = TEST_FAILED;
+		goto err_pipe;
+	} else if (ret != T_SETUP_OK) {
 		fprintf(stderr, "ring setup failed\n");
 		ret = TEST_FAILED;
 		goto err_pipe;
Signature · 1 line
2.32.0
#0 lore raw

cover non-root tests

With 2/2 tests pass with non-root users. Tested with 5.15, most probably would need more work for older kernels.

Pavel Begunkov (2):
tests: don't skip sqpoll needlessly
tests: skip when large buf register fails

 test/d4ae271dfaae-test.c |  5 -----
 test/helpers.c           | 19 +++++++++++++++++++
 test/helpers.h           |  4 ++++
 test/iopoll.c            | 24 ++++++++++++------------
 test/read-write.c        | 26 +++++++++++---------------
 test/sq-poll-kthread.c   | 14 ++++++--------
 6 files changed, 52 insertions(+), 40 deletions(-)
Signature · 1 line
2.32.0
#2 lore raw

PATCH 2/2 tests: skip when large buf register fails

Registering lots of memory will fail for non-privileged users, so skip tests if that happens.

---
 test/helpers.c    | 19 +++++++++++++++++++
 test/helpers.h    |  4 ++++
 test/iopoll.c     | 24 ++++++++++++------------
 test/read-write.c | 26 +++++++++++---------------
 4 files changed, 46 insertions(+), 27 deletions(-)
test/helpers.c +19 -0
index 930d82a..975e7cb 100644
@@ -114,3 +114,22 @@ enum t_setup_ret t_create_ring(int depth, struct io_uring *ring,
 	p.flags = flags;
 	return t_create_ring_params(depth, ring, &p);
 }
+
+enum t_setup_ret t_register_buffers(struct io_uring *ring,
+				    const struct iovec *iovecs,
+				    unsigned nr_iovecs)
+{
+	int ret;
+
+	ret = io_uring_register_buffers(ring, iovecs, nr_iovecs);
+	if (!ret)
+		return T_SETUP_OK;
+
+	if ((ret == -EPERM || ret == -ENOMEM) && geteuid()) {
+		fprintf(stdout, "too large non-root buffer registration, skip\n");
+		return T_SETUP_SKIP;
+	}
+
+	fprintf(stderr, "buffer register failed: %s\n", strerror(-ret));
+	return ret;
+}
test/helpers.h +4 -0
index 18de463..7526d46 100644
@@ -54,6 +54,10 @@ enum t_setup_ret t_create_ring_params(int depth, struct io_uring *ring,
 enum t_setup_ret t_create_ring(int depth, struct io_uring *ring,
 			       unsigned int flags);
 
+enum t_setup_ret t_register_buffers(struct io_uring *ring,
+				    const struct iovec *iovecs,
+				    unsigned nr_iovecs);
+
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 #ifdef __cplusplus
test/iopoll.c +12 -12
index 7037c31..de36473 100644
@@ -60,14 +60,13 @@ static int __test_io(const char *file, struct io_uring *ring, int write, int sqt
 	struct io_uring_sqe *sqe;
 	struct io_uring_cqe *cqe;
 	int open_flags;
-	int i, fd, ret;
+	int i, fd = -1, ret;
 	off_t offset;
 
-	if (buf_select && write)
+	if (buf_select) {
 		write = 0;
-	if (buf_select && fixed)
 		fixed = 0;
-
+	}
 	if (buf_select && provide_buffers(ring))
 		return 1;
 
@@ -77,19 +76,20 @@ static int __test_io(const char *file, struct io_uring *ring, int write, int sqt
 		open_flags = O_RDONLY;
 	open_flags |= O_DIRECT;
 
-	fd = open(file, open_flags);
-	if (fd < 0) {
-		perror("file open");
-		goto err;
-	}
-
 	if (fixed) {
-		ret = io_uring_register_buffers(ring, vecs, BUFFERS);
-		if (ret) {
+		ret = t_register_buffers(ring, vecs, BUFFERS);
+		if (ret == T_SETUP_SKIP)
+			return 0;
+		if (ret != T_SETUP_OK) {
 			fprintf(stderr, "buffer reg failed: %d\n", ret);
 			goto err;
 		}
 	}
+	fd = open(file, open_flags);
+	if (fd < 0) {
+		perror("file open");
+		goto err;
+	}
 	if (sqthread) {
 		ret = io_uring_register_files(ring, &fd, 1);
 		if (ret) {
test/read-write.c +11 -15
index 1cfa2d5..0c55159 100644
@@ -49,7 +49,7 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 	struct io_uring_sqe *sqe;
 	struct io_uring_cqe *cqe;
 	int open_flags;
-	int i, fd, ret;
+	int i, fd = -1, ret;
 	off_t offset;
 
 #ifdef VERBOSE
@@ -57,13 +57,6 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 							buffered, sqthread,
 							fixed, nonvec);
 #endif
-	if (sqthread && geteuid()) {
-#ifdef VERBOSE
-		fprintf(stdout, "SKIPPED (not root)\n");
-#endif
-		return 0;
-	}
-
 	if (write)
 		open_flags = O_WRONLY;
 	else
@@ -71,19 +64,22 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 	if (!buffered)
 		open_flags |= O_DIRECT;
 
+	if (fixed) {
+		ret = t_register_buffers(ring, vecs, BUFFERS);
+		if (ret == T_SETUP_SKIP)
+			return 0;
+		if (ret != T_SETUP_OK) {
+			fprintf(stderr, "buffer reg failed: %d\n", ret);
+			goto err;
+		}
+	}
+
 	fd = open(file, open_flags);
 	if (fd < 0) {
 		perror("file open");
 		goto err;
 	}
 
-	if (fixed) {
-		ret = io_uring_register_buffers(ring, vecs, BUFFERS);
-		if (ret) {
-			fprintf(stderr, "buffer reg failed: %d\n", ret);
-			goto err;
-		}
-	}
 	if (sqthread) {
 		ret = io_uring_register_files(ring, &fd, 1);
 		if (ret) {
Signature · 1 line
2.32.0
maintainer Applied
#3 lore raw
In reply to Pavel Begunkov
Quoted 7 lines · Pavel Begunkov

With 2/2 tests pass with non-root users. Tested with 5.15, most probably would need more work for older kernels.

Pavel Begunkov (2):
tests: don't skip sqpoll needlessly
tests: skip when large buf register fails

Quoted 7 lines
 test/d4ae271dfaae-test.c |  5 -----
 test/helpers.c           | 19 +++++++++++++++++++
 test/helpers.h           |  4 ++++
 test/iopoll.c            | 24 ++++++++++++------------
 test/read-write.c        | 26 +++++++++++---------------
 test/sq-poll-kthread.c   | 14 ++++++--------
 6 files changed, 52 insertions(+), 40 deletions(-)

Thanks, applied.

Signature · 1 line
Jens Axboe