Skip to contentSkip to conversation

check errors in early init

PATCH In review Pavel Begunkov 2 participants 6 messages Jan 31, 2025 io_uring

lore
Share & tools
lore
#0 lore raw

cover check errors in early init

Do the diligence of checking if any of the (inicall) io_uring_init() fail and if so return an error.

Pavel Begunkov (3):
io_uring: propagate req cache creation errors
io_uring: propagate io_buffer creation errors
io_uring: check for iowq alloc_workqueue errors

 io_uring/io_uring.c | 7 +++++++
 1 file changed, 7 insertions(+)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/3 io_uring: propagate req cache creation errors

It's very unlikely, but in theory cache creation can fail during initcall, so don't forget to return errors back if something goes wrong.

Fixes 2b188cc1bb857 ("Add io_uring IO interface")
---
 io_uring/io_uring.c | 3 +++
 1 file changed, 3 insertions(+)
io_uring/io_uring.c +3 -0
index 263e504be4a8b..9335144495299 100644
@@ -3916,6 +3916,9 @@ static int __init io_uring_init(void)
 	req_cachep = kmem_cache_create("io_kiocb", sizeof(struct io_kiocb), &kmem_args,
 				SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT |
 				SLAB_TYPESAFE_BY_RCU);
+	if (!req_cachep)
+		return -ENOMEM;
+
 	io_buf_cachep = KMEM_CACHE(io_buffer,
 					  SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
 
Signature · 1 line
2.47.1
maintainer
#2 lore raw

Re: [PATCH 1/3] io_uring: propagate req cache creation errors

Quoted 2 lines · Pavel Begunkov

It's very unlikely, but in theory cache creation can fail during initcall, so don't forget to return errors back if something goes wrong.

This is why SLAB_PANIC is used, it'll panic if this fails. That's commonly used for setup/init time kind of setups, where we never expect any failure to occur. Hence this can never return NULL.

Signature · 1 line
Jens Axboe
#3 lore raw

Re: [PATCH 1/3] io_uring: propagate req cache creation errors

Quoted 7 lines · Jens Axboe
Quoted 2 lines · Pavel Begunkov

It's very unlikely, but in theory cache creation can fail during initcall, so don't forget to return errors back if something goes wrong.

This is why SLAB_PANIC is used, it'll panic if this fails. That's commonly used for setup/init time kind of setups, where we never expect any failure to occur. Hence this can never return NULL.

Yeah, missed it, thanks

Signature · 1 line
Pavel Begunkov
#4 lore raw

PATCH 2/3 io_uring: propagate io_buffer creation errors

In reply to Pavel Begunkov

It's very unlikely, but in theory cache creation can fail during initcall, so don't forget to return errors back if something goes wrong.

Fixes b3a4dbc89d402 ("io_uring/kbuf: Use slab for struct io_buffer objects")
---
 io_uring/io_uring.c | 2 ++
 1 file changed, 2 insertions(+)
io_uring/io_uring.c +2 -0
index 9335144495299..b05580c1a6424 100644
@@ -3921,6 +3921,8 @@ static int __init io_uring_init(void)
 
 	io_buf_cachep = KMEM_CACHE(io_buffer,
 					  SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
+	if (!io_buf_cachep)
+		return -ENOMEM;
 
 	iou_wq = alloc_workqueue("iou_exit", WQ_UNBOUND, 64);
 
Signature · 1 line
2.47.1
#5 lore raw

PATCH 3/3 io_uring: check for iowq alloc_workqueue errors

In reply to Pavel Begunkov

alloc_workqueue() can fail, check the result and return an error back from io_uring_init() if needed.

Fixes 73eaa2b583493 ("io_uring: use private workqueue for exit work")
---
 io_uring/io_uring.c | 2 ++
 1 file changed, 2 insertions(+)
io_uring/io_uring.c +2 -0
index b05580c1a6424..78a6cc84304f2 100644
@@ -3925,6 +3925,8 @@ static int __init io_uring_init(void)
 		return -ENOMEM;
 
 	iou_wq = alloc_workqueue("iou_exit", WQ_UNBOUND, 64);
+	if (!iou_wq)
+		return -ENOMEM;
 
 #ifdef CONFIG_SYSCTL
 	register_sysctl_init("kernel", kernel_io_uring_disabled_table);
Signature · 1 line
2.47.1