Skip to content

Commit 9278be9

Browse files
committed
Merge tag 'io_uring-5.12-2021-03-12' of git://git.kernel.dk/linux-block
Pull io_uring fixes from Jens Axboe: "Not quite as small this week as I had hoped, but at least this should be the end of it. All the little known issues have been ironed out - most of it little stuff, but cancelations being the bigger part. Only minor tweaks and/or regular fixes expected beyond this point. - Fix the creds tracking for async (io-wq and SQPOLL) - Various SQPOLL fixes related to parking, sharing, forking, IOPOLL, completions, and life times. Much simpler now. - Make IO threads unfreezable by default, on account of a bug report that had them spinning on resume. Honestly not quite sure why thawing leaves us with a perpetual signal pending (causing the spin), but for now make them unfreezable like there were in 5.11 and prior. - Move personality_idr to xarray, solving a use-after-free related to removing an entry from the iterator callback. Buffer idr needs the same treatment. - Re-org around and task vs context tracking, enabling the fixing of cancelations, and then cancelation fixes on top. - Various little bits of cleanups and hardening, and removal of now dead parts" * tag 'io_uring-5.12-2021-03-12' of git://git.kernel.dk/linux-block: (34 commits) io_uring: fix OP_ASYNC_CANCEL across tasks io_uring: cancel sqpoll via task_work io_uring: prevent racy sqd->thread checks io_uring: remove useless ->startup completion io_uring: cancel deferred requests in try_cancel io_uring: perform IOPOLL reaping if canceler is thread itself io_uring: force creation of separate context for ATTACH_WQ and non-threads io_uring: remove indirect ctx into sqo injection io_uring: fix invalid ctx->sq_thread_idle kernel: make IO threads unfreezable by default io_uring: always wait for sqd exited when stopping SQPOLL thread io_uring: remove unneeded variable 'ret' io_uring: move all io_kiocb init early in io_init_req() io-wq: fix ref leak for req in case of exit cancelations io_uring: fix complete_post races for linked req io_uring: add io_disarm_next() helper io_uring: fix io_sq_offload_create error handling io-wq: remove unused 'user' member of io_wq io_uring: Convert personality_idr to XArray io_uring: clean R_DISABLED startup mess ...
2 parents 2614100 + 58f9937 commit 9278be9

5 files changed

Lines changed: 470 additions & 397 deletions

File tree

fs/io-wq.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ struct io_wq {
110110
io_wq_work_fn *do_work;
111111

112112
struct task_struct *manager;
113-
struct user_struct *user;
114113

115114
struct io_wq_hash *hash;
116115

@@ -592,7 +591,7 @@ static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)
592591
tsk->pf_io_worker = worker;
593592
worker->task = tsk;
594593
set_cpus_allowed_ptr(tsk, cpumask_of_node(wqe->node));
595-
tsk->flags |= PF_NOFREEZE | PF_NO_SETAFFINITY;
594+
tsk->flags |= PF_NO_SETAFFINITY;
596595

597596
raw_spin_lock_irq(&wqe->lock);
598597
hlist_nulls_add_head_rcu(&worker->nulls_node, &wqe->free_list);
@@ -710,7 +709,6 @@ static int io_wq_manager(void *data)
710709
set_current_state(TASK_INTERRUPTIBLE);
711710
io_wq_check_workers(wq);
712711
schedule_timeout(HZ);
713-
try_to_freeze();
714712
if (fatal_signal_pending(current))
715713
set_bit(IO_WQ_BIT_EXIT, &wq->state);
716714
} while (!test_bit(IO_WQ_BIT_EXIT, &wq->state));
@@ -722,9 +720,9 @@ static int io_wq_manager(void *data)
722720
io_wq_for_each_worker(wq->wqes[node], io_wq_worker_wake, NULL);
723721
rcu_read_unlock();
724722

725-
/* we might not ever have created any workers */
726-
if (atomic_read(&wq->worker_refs))
727-
wait_for_completion(&wq->worker_done);
723+
if (atomic_dec_and_test(&wq->worker_refs))
724+
complete(&wq->worker_done);
725+
wait_for_completion(&wq->worker_done);
728726

729727
spin_lock_irq(&wq->hash->wait.lock);
730728
for_each_node(node)
@@ -774,14 +772,20 @@ static int io_wq_fork_manager(struct io_wq *wq)
774772
if (wq->manager)
775773
return 0;
776774

777-
reinit_completion(&wq->worker_done);
775+
WARN_ON_ONCE(test_bit(IO_WQ_BIT_EXIT, &wq->state));
776+
777+
init_completion(&wq->worker_done);
778+
atomic_set(&wq->worker_refs, 1);
778779
tsk = create_io_thread(io_wq_manager, wq, NUMA_NO_NODE);
779780
if (!IS_ERR(tsk)) {
780781
wq->manager = get_task_struct(tsk);
781782
wake_up_new_task(tsk);
782783
return 0;
783784
}
784785

786+
if (atomic_dec_and_test(&wq->worker_refs))
787+
complete(&wq->worker_done);
788+
785789
return PTR_ERR(tsk);
786790
}
787791

@@ -794,8 +798,7 @@ static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work)
794798
/* Can only happen if manager creation fails after exec */
795799
if (io_wq_fork_manager(wqe->wq) ||
796800
test_bit(IO_WQ_BIT_EXIT, &wqe->wq->state)) {
797-
work->flags |= IO_WQ_WORK_CANCEL;
798-
wqe->wq->do_work(work);
801+
io_run_cancel(work, wqe);
799802
return;
800803
}
801804

@@ -1018,13 +1021,9 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
10181021
init_completion(&wq->exited);
10191022
refcount_set(&wq->refs, 1);
10201023

1021-
init_completion(&wq->worker_done);
1022-
atomic_set(&wq->worker_refs, 0);
1023-
10241024
ret = io_wq_fork_manager(wq);
10251025
if (!ret)
10261026
return wq;
1027-
10281027
err:
10291028
io_wq_put_hash(data->hash);
10301029
cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node);

fs/io-wq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ static inline void wq_list_del(struct io_wq_work_list *list,
7979

8080
struct io_wq_work {
8181
struct io_wq_work_node list;
82+
const struct cred *creds;
8283
unsigned flags;
83-
unsigned short personality;
8484
};
8585

8686
static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)

0 commit comments

Comments
 (0)