* [PATCH 5.13 0/3] drain rsrc fix
@ 2021-04-27 15:13 Pavel Begunkov
2021-04-27 15:13 ` [PATCH 1/3] io_uring: fix drain with rsrc CQEs Pavel Begunkov
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Pavel Begunkov @ 2021-04-27 15:13 UTC (permalink / raw)
To: Jens Axboe, io-uring
1/3 is a rsrc-related follow up/fix after Hao's drain fix.
Other two are simple hardening.
Pavel Begunkov (3):
io_uring: fix drain with rsrc CQEs
io_uring: dont overlap internal and user req flags
io_uring: add more build check for uapi
fs/io_uring.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
--
2.31.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] io_uring: fix drain with rsrc CQEs
2021-04-27 15:13 [PATCH 5.13 0/3] drain rsrc fix Pavel Begunkov
@ 2021-04-27 15:13 ` Pavel Begunkov
2021-04-27 15:13 ` [PATCH 2/3] io_uring: dont overlap internal and user req flags Pavel Begunkov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2021-04-27 15:13 UTC (permalink / raw)
To: Jens Axboe, io-uring
Resource emitted CQEs are not bound to requests, so fix up counters used
for DRAIN/defer logic.
Fixes: b60c8dce33895 ("io_uring: preparation for rsrc tagging")
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 63ff70587d4f..d3b7fe6ccb0e 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7536,6 +7536,7 @@ static void __io_rsrc_put_work(struct io_rsrc_node *ref_node)
io_ring_submit_lock(ctx, lock_ring);
spin_lock_irqsave(&ctx->completion_lock, flags);
io_cqring_fill_event(ctx, prsrc->tag, 0, 0);
+ ctx->cq_extra++;
io_commit_cqring(ctx);
spin_unlock_irqrestore(&ctx->completion_lock, flags);
io_cqring_ev_posted(ctx);
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] io_uring: dont overlap internal and user req flags
2021-04-27 15:13 [PATCH 5.13 0/3] drain rsrc fix Pavel Begunkov
2021-04-27 15:13 ` [PATCH 1/3] io_uring: fix drain with rsrc CQEs Pavel Begunkov
@ 2021-04-27 15:13 ` Pavel Begunkov
2021-04-27 15:13 ` [PATCH 3/3] io_uring: add more build check for uapi Pavel Begunkov
2021-04-28 14:04 ` [PATCH 5.13 0/3] drain rsrc fix Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2021-04-27 15:13 UTC (permalink / raw)
To: Jens Axboe, io-uring
CQE flags take one byte that we store in req->flags together with other
REQ_F_* internal flags. CQE flags are copied directly into req and then
verified that requires some handling on failures, e.g. to make sure that
that copy doesn't set some of the internal flags.
More all internal flags to take bits after the first byte, so we don't
need extra handling and make it safer overall.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index d3b7fe6ccb0e..3419548ccaf5 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -702,7 +702,8 @@ enum {
REQ_F_FORCE_ASYNC_BIT = IOSQE_ASYNC_BIT,
REQ_F_BUFFER_SELECT_BIT = IOSQE_BUFFER_SELECT_BIT,
- REQ_F_FAIL_LINK_BIT,
+ /* first byte is taken by user flags, shift it to not overlap */
+ REQ_F_FAIL_LINK_BIT = 8,
REQ_F_INFLIGHT_BIT,
REQ_F_CUR_POS_BIT,
REQ_F_NOWAIT_BIT,
@@ -6503,14 +6504,10 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
req->work.creds = NULL;
/* enforce forwards compatibility on users */
- if (unlikely(sqe_flags & ~SQE_VALID_FLAGS)) {
- req->flags = 0;
+ if (unlikely(sqe_flags & ~SQE_VALID_FLAGS))
return -EINVAL;
- }
-
if (unlikely(req->opcode >= IORING_OP_LAST))
return -EINVAL;
-
if (unlikely(!io_check_restriction(ctx, req, sqe_flags)))
return -EACCES;
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] io_uring: add more build check for uapi
2021-04-27 15:13 [PATCH 5.13 0/3] drain rsrc fix Pavel Begunkov
2021-04-27 15:13 ` [PATCH 1/3] io_uring: fix drain with rsrc CQEs Pavel Begunkov
2021-04-27 15:13 ` [PATCH 2/3] io_uring: dont overlap internal and user req flags Pavel Begunkov
@ 2021-04-27 15:13 ` Pavel Begunkov
2021-04-28 14:04 ` [PATCH 5.13 0/3] drain rsrc fix Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2021-04-27 15:13 UTC (permalink / raw)
To: Jens Axboe, io-uring
Add a couple of BUILD_BUG_ON() checking some rsrc uapi structs and SQE
flags.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 3419548ccaf5..a48b88b3e289 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -10131,6 +10131,13 @@ static int __init io_uring_init(void)
BUILD_BUG_SQE_ELEM(42, __u16, personality);
BUILD_BUG_SQE_ELEM(44, __s32, splice_fd_in);
+ BUILD_BUG_ON(sizeof(struct io_uring_files_update) !=
+ sizeof(struct io_uring_rsrc_update));
+ BUILD_BUG_ON(sizeof(struct io_uring_rsrc_update) >
+ sizeof(struct io_uring_rsrc_update2));
+ /* should fit into one byte */
+ BUILD_BUG_ON(SQE_VALID_FLAGS >= (1 << 8));
+
BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST);
BUILD_BUG_ON(__REQ_F_LAST_BIT >= 8 * sizeof(int));
req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC |
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 5.13 0/3] drain rsrc fix
2021-04-27 15:13 [PATCH 5.13 0/3] drain rsrc fix Pavel Begunkov
` (2 preceding siblings ...)
2021-04-27 15:13 ` [PATCH 3/3] io_uring: add more build check for uapi Pavel Begunkov
@ 2021-04-28 14:04 ` Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2021-04-28 14:04 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 4/27/21 9:13 AM, Pavel Begunkov wrote:
> 1/3 is a rsrc-related follow up/fix after Hao's drain fix.
> Other two are simple hardening.
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-04-28 14:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-27 15:13 [PATCH 5.13 0/3] drain rsrc fix Pavel Begunkov
2021-04-27 15:13 ` [PATCH 1/3] io_uring: fix drain with rsrc CQEs Pavel Begunkov
2021-04-27 15:13 ` [PATCH 2/3] io_uring: dont overlap internal and user req flags Pavel Begunkov
2021-04-27 15:13 ` [PATCH 3/3] io_uring: add more build check for uapi Pavel Begunkov
2021-04-28 14:04 ` [PATCH 5.13 0/3] drain rsrc fix Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox