From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH liburing 7/8] tests: test arbitrary offset reg waits
Date: Fri, 15 Nov 2024 21:33:54 +0000 [thread overview]
Message-ID: <576e9ca1ad794c648af9754ef1c7f4ba5cbed1ab.1731705935.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
The exported io_uring API operates with wait index, which is safer, but
the kernel takes byte offsets. Add a local raw syscall helper passing
byte offsets and add edge testing of more edge cases.
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index 13f6d51..aef4546 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -13,6 +13,18 @@
#include "liburing.h"
#include "helpers.h"
#include "test.h"
+#include "../src/syscall.h"
+
+static int test_wait_reg_offset(struct io_uring *ring,
+ unsigned wait_nr, unsigned long offset)
+{
+ return __sys_io_uring_enter2(ring->ring_fd, 0, wait_nr,
+ IORING_ENTER_GETEVENTS |
+ IORING_ENTER_EXT_ARG |
+ IORING_ENTER_EXT_ARG_REG,
+ (void *)offset,
+ sizeof(struct io_uring_reg_wait));
+}
static int page_size;
static struct io_uring_reg_wait *reg;
@@ -55,6 +67,7 @@ static int test_offsets(struct io_uring *ring)
struct io_uring_cqe *cqe;
int max_index = page_size / sizeof(struct io_uring_reg_wait);
struct io_uring_reg_wait *rw;
+ unsigned long offset;
int ret;
rw = reg + max_index;
@@ -80,6 +93,36 @@ static int test_offsets(struct io_uring *ring)
return T_EXIT_FAIL;
}
+ offset = 0UL - sizeof(long);
+ ret = test_wait_reg_offset(ring, 1, offset);
+ if (ret != -EFAULT) {
+ fprintf(stderr, "overflow offset failed: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ offset = 4096 - sizeof(long);
+ rw = (void *)reg + offset;
+ memset(rw, 0, sizeof(*rw));
+ rw->flags = IORING_REG_WAIT_TS;
+ rw->ts.tv_sec = 0;
+ rw->ts.tv_nsec = 1000;
+
+ ret = test_wait_reg_offset(ring, 1, offset);
+ if (ret != -EFAULT) {
+ fprintf(stderr, "OOB offset failed: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ offset = 1;
+ rw = (void *)reg + offset;
+ memset(rw, 0, sizeof(*rw));
+ rw->flags = IORING_REG_WAIT_TS;
+ rw->ts.tv_sec = 0;
+ rw->ts.tv_nsec = 1000;
+
+ /* undefined behaviour, check the kernel doesn't crash */
+ (void)test_wait_reg_offset(ring, 1, offset);
+
return 0;
}
--
2.46.0
next prev parent reply other threads:[~2024-11-15 21:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 21:33 [PATCH liburing 0/8] update reg-wait to use region API Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 1/8] queue: break reg wait setup Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 2/8] Update io_uring.h Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 3/8] queue: add region helpers and fix up wait reg kernel api Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 4/8] examples: convert reg-wait to new api Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 5/8] tests: convert reg-wait to regions Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 6/8] tests: add region testing Pavel Begunkov
2024-11-15 21:33 ` Pavel Begunkov [this message]
2024-11-15 21:33 ` [PATCH liburing 8/8] Remove leftovers of old reg-wait registration api Pavel Begunkov
2024-11-16 17:07 ` [PATCH liburing 0/8] update reg-wait to use region API Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=576e9ca1ad794c648af9754ef1c7f4ba5cbed1ab.1731705935.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox