Skip to content

Commit af00418

Browse files
committed
Merge tag 'io_uring-5.10-2020-10-24' of git://git.kernel.dk/linux-block
Pull io_uring fixes from Jens Axboe: - fsize was missed in previous unification of work flags - Few fixes cleaning up the flags unification creds cases (Pavel) - Fix NUMA affinities for completely unplugged/replugged node for io-wq - Two fallout fixes from the set_fs changes. One local to io_uring, one for the splice entry point that io_uring uses. - Linked timeout fixes (Pavel) - Removal of ->flush() ->files work-around that we don't need anymore with referenced files (Pavel) - Various cleanups (Pavel) * tag 'io_uring-5.10-2020-10-24' of git://git.kernel.dk/linux-block: splice: change exported internal do_splice() helper to take kernel offset io_uring: make loop_rw_iter() use original user supplied pointers io_uring: remove req cancel in ->flush() io-wq: re-set NUMA node affinities if CPUs come online io_uring: don't reuse linked_timeout io_uring: unify fsize with def->work_flags io_uring: fix racy REQ_F_LINK_TIMEOUT clearing io_uring: do poll's hash_node init in common code io_uring: inline io_poll_task_handler() io_uring: remove extra ->file check in poll prep io_uring: make cached_cq_overflow non atomic_t io_uring: inline io_fail_links() io_uring: kill ref get/drop in personality init io_uring: flags-based creds init in queue
2 parents cb6b289 + ee6e00c commit af00418

5 files changed

Lines changed: 191 additions & 118 deletions

File tree

fs/io-wq.c

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
#include <linux/task_work.h>
2020
#include <linux/blk-cgroup.h>
2121
#include <linux/audit.h>
22+
#include <linux/cpu.h>
2223

24+
#include "../kernel/sched/sched.h"
2325
#include "io-wq.h"
2426

2527
#define WORKER_IDLE_TIMEOUT (5 * HZ)
@@ -123,9 +125,13 @@ struct io_wq {
123125
refcount_t refs;
124126
struct completion done;
125127

128+
struct hlist_node cpuhp_node;
129+
126130
refcount_t use_refs;
127131
};
128132

133+
static enum cpuhp_state io_wq_online;
134+
129135
static bool io_worker_get(struct io_worker *worker)
130136
{
131137
return refcount_inc_not_zero(&worker->ref);
@@ -187,7 +193,8 @@ static bool __io_worker_unuse(struct io_wqe *wqe, struct io_worker *worker)
187193
worker->blkcg_css = NULL;
188194
}
189195
#endif
190-
196+
if (current->signal->rlim[RLIMIT_FSIZE].rlim_cur != RLIM_INFINITY)
197+
current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
191198
return dropped_lock;
192199
}
193200

@@ -483,7 +490,10 @@ static void io_impersonate_work(struct io_worker *worker,
483490
if ((work->flags & IO_WQ_WORK_CREDS) &&
484491
worker->cur_creds != work->identity->creds)
485492
io_wq_switch_creds(worker, work);
486-
current->signal->rlim[RLIMIT_FSIZE].rlim_cur = work->identity->fsize;
493+
if (work->flags & IO_WQ_WORK_FSIZE)
494+
current->signal->rlim[RLIMIT_FSIZE].rlim_cur = work->identity->fsize;
495+
else if (current->signal->rlim[RLIMIT_FSIZE].rlim_cur != RLIM_INFINITY)
496+
current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
487497
io_wq_switch_blkcg(worker, work);
488498
#ifdef CONFIG_AUDIT
489499
current->loginuid = work->identity->loginuid;
@@ -1087,17 +1097,20 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
10871097
return ERR_PTR(-ENOMEM);
10881098

10891099
wq->wqes = kcalloc(nr_node_ids, sizeof(struct io_wqe *), GFP_KERNEL);
1090-
if (!wq->wqes) {
1091-
kfree(wq);
1092-
return ERR_PTR(-ENOMEM);
1093-
}
1100+
if (!wq->wqes)
1101+
goto err_wq;
1102+
1103+
ret = cpuhp_state_add_instance_nocalls(io_wq_online, &wq->cpuhp_node);
1104+
if (ret)
1105+
goto err_wqes;
10941106

10951107
wq->free_work = data->free_work;
10961108
wq->do_work = data->do_work;
10971109

10981110
/* caller must already hold a reference to this */
10991111
wq->user = data->user;
11001112

1113+
ret = -ENOMEM;
11011114
for_each_node(node) {
11021115
struct io_wqe *wqe;
11031116
int alloc_node = node;
@@ -1141,9 +1154,12 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
11411154
ret = PTR_ERR(wq->manager);
11421155
complete(&wq->done);
11431156
err:
1157+
cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node);
11441158
for_each_node(node)
11451159
kfree(wq->wqes[node]);
1160+
err_wqes:
11461161
kfree(wq->wqes);
1162+
err_wq:
11471163
kfree(wq);
11481164
return ERR_PTR(ret);
11491165
}
@@ -1160,6 +1176,8 @@ static void __io_wq_destroy(struct io_wq *wq)
11601176
{
11611177
int node;
11621178

1179+
cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node);
1180+
11631181
set_bit(IO_WQ_BIT_EXIT, &wq->state);
11641182
if (wq->manager)
11651183
kthread_stop(wq->manager);
@@ -1187,3 +1205,41 @@ struct task_struct *io_wq_get_task(struct io_wq *wq)
11871205
{
11881206
return wq->manager;
11891207
}
1208+
1209+
static bool io_wq_worker_affinity(struct io_worker *worker, void *data)
1210+
{
1211+
struct task_struct *task = worker->task;
1212+
struct rq_flags rf;
1213+
struct rq *rq;
1214+
1215+
rq = task_rq_lock(task, &rf);
1216+
do_set_cpus_allowed(task, cpumask_of_node(worker->wqe->node));
1217+
task->flags |= PF_NO_SETAFFINITY;
1218+
task_rq_unlock(rq, task, &rf);
1219+
return false;
1220+
}
1221+
1222+
static int io_wq_cpu_online(unsigned int cpu, struct hlist_node *node)
1223+
{
1224+
struct io_wq *wq = hlist_entry_safe(node, struct io_wq, cpuhp_node);
1225+
int i;
1226+
1227+
rcu_read_lock();
1228+
for_each_node(i)
1229+
io_wq_for_each_worker(wq->wqes[i], io_wq_worker_affinity, NULL);
1230+
rcu_read_unlock();
1231+
return 0;
1232+
}
1233+
1234+
static __init int io_wq_init(void)
1235+
{
1236+
int ret;
1237+
1238+
ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "io-wq/online",
1239+
io_wq_cpu_online, NULL);
1240+
if (ret < 0)
1241+
return ret;
1242+
io_wq_online = ret;
1243+
return 0;
1244+
}
1245+
subsys_initcall(io_wq_init);

fs/io-wq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum {
1717
IO_WQ_WORK_MM = 128,
1818
IO_WQ_WORK_CREDS = 256,
1919
IO_WQ_WORK_BLKCG = 512,
20+
IO_WQ_WORK_FSIZE = 1024,
2021

2122
IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */
2223
};

0 commit comments

Comments
 (0)