Skip to content

Commit 294e73f

Browse files
committed
Merge tag 'io_uring-6.1-2022-10-20' of git://git.kernel.dk/linux
Pull io_uring fixes from Jens Axboe: - Fix a potential memory leak in the error handling path of io-wq setup (Rafael) - Kill an errant debug statement that got added in this release (me) - Fix an oops with an invalid direct descriptor with IORING_OP_MSG_RING (Harshit) - Remove unneeded FFS_SCM flagging (Pavel) - Remove polling off the exit path (Pavel) - Move out direct descriptor debug check to the cleanup path (Pavel) - Use the proper helper rather than open-coding cached request get (Pavel) * tag 'io_uring-6.1-2022-10-20' of git://git.kernel.dk/linux: io-wq: Fix memory leak in worker creation io_uring/msg_ring: Fix NULL pointer dereference in io_msg_send_fd() io_uring/rw: remove leftover debug statement io_uring: don't iopoll from io_ring_ctx_wait_and_kill() io_uring: reuse io_alloc_req() io_uring: kill hot path fixed file bitmap debug checks io_uring: remove FFS_SCM
2 parents 1d61754 + 996d3ef commit 294e73f

File tree

7 files changed

+15
-43
lines changed

7 files changed

+15
-43
lines changed

io_uring/filetable.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,9 @@
55
#include <linux/file.h>
66
#include <linux/io_uring_types.h>
77

8-
/*
9-
* FFS_SCM is only available on 64-bit archs, for 32-bit we just define it as 0
10-
* and define IO_URING_SCM_ALL. For this case, we use SCM for all files as we
11-
* can't safely always dereference the file when the task has exited and ring
12-
* cleanup is done. If a file is tracked and part of SCM, then unix gc on
13-
* process exit may reap it before __io_sqe_files_unregister() is run.
14-
*/
158
#define FFS_NOWAIT 0x1UL
169
#define FFS_ISREG 0x2UL
17-
#if defined(CONFIG_64BIT)
18-
#define FFS_SCM 0x4UL
19-
#else
20-
#define IO_URING_SCM_ALL
21-
#define FFS_SCM 0x0UL
22-
#endif
23-
#define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG|FFS_SCM)
10+
#define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG)
2411

2512
bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files);
2613
void io_free_file_tables(struct io_file_table *table);
@@ -38,6 +25,7 @@ unsigned int io_file_get_flags(struct file *file);
3825

3926
static inline void io_file_bitmap_clear(struct io_file_table *table, int bit)
4027
{
28+
WARN_ON_ONCE(!test_bit(bit, table->bitmap));
4129
__clear_bit(bit, table->bitmap);
4230
table->alloc_hint = bit;
4331
}

io_uring/io-wq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,10 +1164,10 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
11641164
wqe = kzalloc_node(sizeof(struct io_wqe), GFP_KERNEL, alloc_node);
11651165
if (!wqe)
11661166
goto err;
1167+
wq->wqes[node] = wqe;
11671168
if (!alloc_cpumask_var(&wqe->cpu_mask, GFP_KERNEL))
11681169
goto err;
11691170
cpumask_copy(wqe->cpu_mask, cpumask_of_node(node));
1170-
wq->wqes[node] = wqe;
11711171
wqe->node = alloc_node;
11721172
wqe->acct[IO_WQ_ACCT_BOUND].max_workers = bounded;
11731173
wqe->acct[IO_WQ_ACCT_UNBOUND].max_workers =

io_uring/io_uring.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,8 +1587,6 @@ unsigned int io_file_get_flags(struct file *file)
15871587
res |= FFS_ISREG;
15881588
if (__io_file_supports_nowait(file, mode))
15891589
res |= FFS_NOWAIT;
1590-
if (io_file_need_scm(file))
1591-
res |= FFS_SCM;
15921590
return res;
15931591
}
15941592

@@ -1860,7 +1858,6 @@ inline struct file *io_file_get_fixed(struct io_kiocb *req, int fd,
18601858
/* mask in overlapping REQ_F and FFS bits */
18611859
req->flags |= (file_ptr << REQ_F_SUPPORT_NOWAIT_BIT);
18621860
io_req_set_rsrc_node(req, ctx, 0);
1863-
WARN_ON_ONCE(file && !test_bit(fd, ctx->file_table.bitmap));
18641861
out:
18651862
io_ring_submit_unlock(ctx, issue_flags);
18661863
return file;
@@ -2563,18 +2560,14 @@ static int io_eventfd_unregister(struct io_ring_ctx *ctx)
25632560

25642561
static void io_req_caches_free(struct io_ring_ctx *ctx)
25652562
{
2566-
struct io_submit_state *state = &ctx->submit_state;
25672563
int nr = 0;
25682564

25692565
mutex_lock(&ctx->uring_lock);
2570-
io_flush_cached_locked_reqs(ctx, state);
2566+
io_flush_cached_locked_reqs(ctx, &ctx->submit_state);
25712567

25722568
while (!io_req_cache_empty(ctx)) {
2573-
struct io_wq_work_node *node;
2574-
struct io_kiocb *req;
2569+
struct io_kiocb *req = io_alloc_req(ctx);
25752570

2576-
node = wq_stack_extract(&state->free_list);
2577-
req = container_of(node, struct io_kiocb, comp_list);
25782571
kmem_cache_free(req_cachep, req);
25792572
nr++;
25802573
}
@@ -2811,15 +2804,12 @@ static __cold void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
28112804
io_poll_remove_all(ctx, NULL, true);
28122805
mutex_unlock(&ctx->uring_lock);
28132806

2814-
/* failed during ring init, it couldn't have issued any requests */
2815-
if (ctx->rings) {
2807+
/*
2808+
* If we failed setting up the ctx, we might not have any rings
2809+
* and therefore did not submit any requests
2810+
*/
2811+
if (ctx->rings)
28162812
io_kill_timeouts(ctx, NULL, true);
2817-
/* if we failed setting up the ctx, we might not have any rings */
2818-
io_iopoll_try_reap_events(ctx);
2819-
/* drop cached put refs after potentially doing completions */
2820-
if (current->io_uring)
2821-
io_uring_drop_tctx_refs(current);
2822-
}
28232813

28242814
INIT_WORK(&ctx->exit_work, io_ring_exit_work);
28252815
/*

io_uring/msg_ring.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)
9595

9696
msg->src_fd = array_index_nospec(msg->src_fd, ctx->nr_user_files);
9797
file_ptr = io_fixed_file_slot(&ctx->file_table, msg->src_fd)->file_ptr;
98+
if (!file_ptr)
99+
goto out_unlock;
100+
98101
src_file = (struct file *) (file_ptr & FFS_MASK);
99102
get_file(src_file);
100103

io_uring/rsrc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -757,20 +757,17 @@ int io_queue_rsrc_removal(struct io_rsrc_data *data, unsigned idx,
757757

758758
void __io_sqe_files_unregister(struct io_ring_ctx *ctx)
759759
{
760-
#if !defined(IO_URING_SCM_ALL)
761760
int i;
762761

763762
for (i = 0; i < ctx->nr_user_files; i++) {
764763
struct file *file = io_file_from_index(&ctx->file_table, i);
765764

766-
if (!file)
767-
continue;
768-
if (io_fixed_file_slot(&ctx->file_table, i)->file_ptr & FFS_SCM)
765+
/* skip scm accounted files, they'll be freed by ->ring_sock */
766+
if (!file || io_file_need_scm(file))
769767
continue;
770768
io_file_bitmap_clear(&ctx->file_table, i);
771769
fput(file);
772770
}
773-
#endif
774771

775772
#if defined(CONFIG_UNIX)
776773
if (ctx->ring_sock) {

io_uring/rsrc.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ int __io_scm_file_account(struct io_ring_ctx *ctx, struct file *file);
8282
#if defined(CONFIG_UNIX)
8383
static inline bool io_file_need_scm(struct file *filp)
8484
{
85-
#if defined(IO_URING_SCM_ALL)
86-
return true;
87-
#else
8885
return !!unix_get_socket(filp);
89-
#endif
9086
}
9187
#else
9288
static inline bool io_file_need_scm(struct file *filp)

io_uring/rw.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ static void io_req_io_end(struct io_kiocb *req)
242242
{
243243
struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
244244

245-
WARN_ON(!in_task());
246-
247245
if (rw->kiocb.ki_flags & IOCB_WRITE) {
248246
kiocb_end_write(req);
249247
fsnotify_modify(req->file);

0 commit comments

Comments
 (0)