* [PATCH V2 0/2] io_uring: support to inject result for NOP
@ 2024-05-10 3:50 Ming Lei
2024-05-10 3:50 ` [PATCH V2 1/2] io_uring: fail NOP if non-zero op flags is passed in Ming Lei
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ming Lei @ 2024-05-10 3:50 UTC (permalink / raw)
To: Jens Axboe, io-uring; +Cc: Ming Lei
Hello,
The two patches add nop_flags for supporting to inject result on NOP.
V2:
- add patch1 for backport, suggested by Jens
Ming Lei (2):
io_uring: fail NOP if non-zero op flags is passed in
io_uring: support to inject result for NOP
include/uapi/linux/io_uring.h | 8 ++++++++
io_uring/nop.c | 26 ++++++++++++++++++++++----
2 files changed, 30 insertions(+), 4 deletions(-)
--
2.42.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH V2 1/2] io_uring: fail NOP if non-zero op flags is passed in
2024-05-10 3:50 [PATCH V2 0/2] io_uring: support to inject result for NOP Ming Lei
@ 2024-05-10 3:50 ` Ming Lei
2024-05-10 3:50 ` [PATCH V2 2/2] io_uring: support to inject result for NOP Ming Lei
2024-05-10 12:50 ` [PATCH V2 0/2] " Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Ming Lei @ 2024-05-10 3:50 UTC (permalink / raw)
To: Jens Axboe, io-uring; +Cc: Ming Lei, stable
The NOP op flags should have been checked from beginning like any other
opcode, otherwise NOP may not be extended with the op flags.
Given both liburing and Rust io-uring crate always zeros SQE op flags, just
ignore users which play raw NOP uring interface without zeroing SQE, because
NOP is just for test purpose. Then we can save one NOP2 opcode.
Suggested-by: Jens Axboe <[email protected]>
Fixes: 2b188cc1bb85 ("Add io_uring IO interface")
Cc: [email protected]
Signed-off-by: Ming Lei <[email protected]>
---
io_uring/nop.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/io_uring/nop.c b/io_uring/nop.c
index d956599a3c1b..1a4e312dfe51 100644
--- a/io_uring/nop.c
+++ b/io_uring/nop.c
@@ -12,6 +12,8 @@
int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
+ if (READ_ONCE(sqe->rw_flags))
+ return -EINVAL;
return 0;
}
--
2.42.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH V2 2/2] io_uring: support to inject result for NOP
2024-05-10 3:50 [PATCH V2 0/2] io_uring: support to inject result for NOP Ming Lei
2024-05-10 3:50 ` [PATCH V2 1/2] io_uring: fail NOP if non-zero op flags is passed in Ming Lei
@ 2024-05-10 3:50 ` Ming Lei
2024-05-10 12:50 ` [PATCH V2 0/2] " Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Ming Lei @ 2024-05-10 3:50 UTC (permalink / raw)
To: Jens Axboe, io-uring; +Cc: Ming Lei
Support to inject result for NOP so that we can inject failure from
userspace. It is very helpful for covering failure handling code in
io_uring core change.
With nop flags, it becomes possible to add more test features on NOP in
future.
Suggested-by: Jens Axboe <[email protected]>
Signed-off-by: Ming Lei <[email protected]>
---
include/uapi/linux/io_uring.h | 8 ++++++++
io_uring/nop.c | 26 +++++++++++++++++++++-----
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 922f29b07ccc..21e9cd604068 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -72,6 +72,7 @@ struct io_uring_sqe {
__u32 waitid_flags;
__u32 futex_flags;
__u32 install_fd_flags;
+ __u32 nop_flags;
};
__u64 user_data; /* data to be passed back at completion time */
/* pack this to avoid bogus arm OABI complaints */
@@ -413,6 +414,13 @@ enum io_uring_msg_ring_flags {
*/
#define IORING_FIXED_FD_NO_CLOEXEC (1U << 0)
+/*
+ * IORING_OP_NOP flags (sqe->nop_flags)
+ *
+ * IORING_NOP_INJECT_RESULT Inject result from sqe->result
+ */
+#define IORING_NOP_INJECT_RESULT (1U << 0)
+
/*
* IO completion data structure (Completion Queue Entry)
*/
diff --git a/io_uring/nop.c b/io_uring/nop.c
index 1a4e312dfe51..a5bcf3d6984f 100644
--- a/io_uring/nop.c
+++ b/io_uring/nop.c
@@ -10,18 +10,34 @@
#include "io_uring.h"
#include "nop.h"
+struct io_nop {
+ /* NOTE: kiocb has the file as the first member, so don't do it here */
+ struct file *file;
+ int result;
+};
+
int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
- if (READ_ONCE(sqe->rw_flags))
+ unsigned int flags;
+ struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
+
+ flags = READ_ONCE(sqe->nop_flags);
+ if (flags & ~IORING_NOP_INJECT_RESULT)
return -EINVAL;
+
+ if (flags & IORING_NOP_INJECT_RESULT)
+ nop->result = READ_ONCE(sqe->len);
+ else
+ nop->result = 0;
return 0;
}
-/*
- * IORING_OP_NOP just posts a completion event, nothing else.
- */
int io_nop(struct io_kiocb *req, unsigned int issue_flags)
{
- io_req_set_res(req, 0, 0);
+ struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
+
+ if (nop->result < 0)
+ req_set_fail(req);
+ io_req_set_res(req, nop->result, 0);
return IOU_OK;
}
--
2.42.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH V2 0/2] io_uring: support to inject result for NOP
2024-05-10 3:50 [PATCH V2 0/2] io_uring: support to inject result for NOP Ming Lei
2024-05-10 3:50 ` [PATCH V2 1/2] io_uring: fail NOP if non-zero op flags is passed in Ming Lei
2024-05-10 3:50 ` [PATCH V2 2/2] io_uring: support to inject result for NOP Ming Lei
@ 2024-05-10 12:50 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2024-05-10 12:50 UTC (permalink / raw)
To: io-uring, Ming Lei
On Fri, 10 May 2024 11:50:26 +0800, Ming Lei wrote:
> The two patches add nop_flags for supporting to inject result on NOP.
>
> V2:
> - add patch1 for backport, suggested by Jens
>
>
> Ming Lei (2):
> io_uring: fail NOP if non-zero op flags is passed in
> io_uring: support to inject result for NOP
>
> [...]
Applied, thanks!
[1/2] io_uring: fail NOP if non-zero op flags is passed in
(no commit info)
[2/2] io_uring: support to inject result for NOP
(no commit info)
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-10 12:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-10 3:50 [PATCH V2 0/2] io_uring: support to inject result for NOP Ming Lei
2024-05-10 3:50 ` [PATCH V2 1/2] io_uring: fail NOP if non-zero op flags is passed in Ming Lei
2024-05-10 3:50 ` [PATCH V2 2/2] io_uring: support to inject result for NOP Ming Lei
2024-05-10 12:50 ` [PATCH V2 0/2] " Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox