Skip to contentSkip to conversation

5.15 small improvements

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

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover 5.15 small improvements

Just two small patches following past and potential problems

Pavel Begunkov (2):
io_uring: clarify io_req_task_cancel() locking
io_uring: add build check for buf_index overflows

 fs/io_uring.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/2 io_uring: clarify io_req_task_cancel() locking

It's too easy to forget and misjudge about synchronisation in io_req_task_cancel(), add a comment clarifying it.

---
 fs/io_uring.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/io_uring.c +1 -2
index 15728e63d6f9..712605fd04c2 100644
@@ -2138,7 +2138,7 @@ static void io_req_task_cancel(struct io_kiocb *req, bool *locked)
 {
 	struct io_ring_ctx *ctx = req->ctx;
 
-	/* ctx is guaranteed to stay alive while we hold uring_lock */
+	/* not needed for normal modes, but SQPOLL depends on it */
 	io_tw_lock(ctx, locked);
 	io_req_complete_failed(req, req->result);
 }
@@ -2147,7 +2147,6 @@ static void io_req_task_submit(struct io_kiocb *req, bool *locked)
 {
 	struct io_ring_ctx *ctx = req->ctx;
 
-	/* ctx stays valid until unlock, even if we drop all ours ctx->refs */
 	io_tw_lock(ctx, locked);
 	/* req->task == current here, checking PF_EXITING is safe */
 	if (likely(!(req->task->flags & PF_EXITING)))
Signature · 1 line
2.32.0
#2 lore raw

PATCH 2/2 io_uring: add build check for buf_index overflows

In reply to Pavel Begunkov

req->buf_index is u16 and so we rely on registered buffers indexes fitting into it. Add a build check, so when the upper limit for the number of buffers is lifted we get a compliation fail but not lurking problems.

---
 fs/io_uring.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/io_uring.c +4 -0
index 712605fd04c2..6112318a770c 100644
@@ -10450,6 +10450,10 @@ static int __init io_uring_init(void)
 		     sizeof(struct io_uring_rsrc_update));
 	BUILD_BUG_ON(sizeof(struct io_uring_rsrc_update) >
 		     sizeof(struct io_uring_rsrc_update2));
+
+	/* ->buf_index is u16 */
+	BUILD_BUG_ON(IORING_MAX_REG_BUFFERS >= (1u << 16));
+
 	/* should fit into one byte */
 	BUILD_BUG_ON(SQE_VALID_FLAGS >= (1 << 8));
 
Signature · 1 line
2.32.0
maintainer Applied
#3 lore raw
In reply to Pavel Begunkov
Quoted 8 lines · Pavel Begunkov

Just two small patches following past and potential problems

Pavel Begunkov (2):
io_uring: clarify io_req_task_cancel() locking
io_uring: add build check for buf_index overflows

 fs/io_uring.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Applied, thanks.

Signature · 1 line
Jens Axboe