Skip to content

Commit a8205e3

Browse files
committed
Merge tag 'io_uring-5.9-2020-09-06' of git://git.kernel.dk/linux-block
Pull more io_uring fixes from Jens Axboe: "Two followup fixes. One is fixing a regression from this merge window, the other is two commits fixing cancelation of deferred requests. Both have gone through full testing, and both spawned a few new regression test additions to liburing. - Don't play games with const, properly store the output iovec and assign it as needed. - Deferred request cancelation fix (Pavel)" * tag 'io_uring-5.9-2020-09-06' of git://git.kernel.dk/linux-block: io_uring: fix linked deferred ->files cancellation io_uring: fix cancel of deferred reqs with ->files io_uring: fix explicit async read/write mapping for large segments
2 parents 2ccdd9f + c127a2a commit a8205e3

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

fs/io_uring.c

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,14 +2980,15 @@ static inline int io_rw_prep_async(struct io_kiocb *req, int rw,
29802980
bool force_nonblock)
29812981
{
29822982
struct io_async_rw *iorw = &req->io->rw;
2983+
struct iovec *iov;
29832984
ssize_t ret;
29842985

2985-
iorw->iter.iov = iorw->fast_iov;
2986-
ret = __io_import_iovec(rw, req, (struct iovec **) &iorw->iter.iov,
2987-
&iorw->iter, !force_nonblock);
2986+
iorw->iter.iov = iov = iorw->fast_iov;
2987+
ret = __io_import_iovec(rw, req, &iov, &iorw->iter, !force_nonblock);
29882988
if (unlikely(ret < 0))
29892989
return ret;
29902990

2991+
iorw->iter.iov = iov;
29912992
io_req_map_rw(req, iorw->iter.iov, iorw->fast_iov, &iorw->iter);
29922993
return 0;
29932994
}
@@ -8023,6 +8024,28 @@ static bool io_match_link(struct io_kiocb *preq, struct io_kiocb *req)
80238024
return false;
80248025
}
80258026

8027+
static inline bool io_match_files(struct io_kiocb *req,
8028+
struct files_struct *files)
8029+
{
8030+
return (req->flags & REQ_F_WORK_INITIALIZED) && req->work.files == files;
8031+
}
8032+
8033+
static bool io_match_link_files(struct io_kiocb *req,
8034+
struct files_struct *files)
8035+
{
8036+
struct io_kiocb *link;
8037+
8038+
if (io_match_files(req, files))
8039+
return true;
8040+
if (req->flags & REQ_F_LINK_HEAD) {
8041+
list_for_each_entry(link, &req->link_list, link_list) {
8042+
if (io_match_files(link, files))
8043+
return true;
8044+
}
8045+
}
8046+
return false;
8047+
}
8048+
80268049
/*
80278050
* We're looking to cancel 'req' because it's holding on to our files, but
80288051
* 'req' could be a link to another request. See if it is, and cancel that
@@ -8097,12 +8120,38 @@ static void io_attempt_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req)
80978120
io_timeout_remove_link(ctx, req);
80988121
}
80998122

8123+
static void io_cancel_defer_files(struct io_ring_ctx *ctx,
8124+
struct files_struct *files)
8125+
{
8126+
struct io_defer_entry *de = NULL;
8127+
LIST_HEAD(list);
8128+
8129+
spin_lock_irq(&ctx->completion_lock);
8130+
list_for_each_entry_reverse(de, &ctx->defer_list, list) {
8131+
if (io_match_link_files(de->req, files)) {
8132+
list_cut_position(&list, &ctx->defer_list, &de->list);
8133+
break;
8134+
}
8135+
}
8136+
spin_unlock_irq(&ctx->completion_lock);
8137+
8138+
while (!list_empty(&list)) {
8139+
de = list_first_entry(&list, struct io_defer_entry, list);
8140+
list_del_init(&de->list);
8141+
req_set_fail_links(de->req);
8142+
io_put_req(de->req);
8143+
io_req_complete(de->req, -ECANCELED);
8144+
kfree(de);
8145+
}
8146+
}
8147+
81008148
static void io_uring_cancel_files(struct io_ring_ctx *ctx,
81018149
struct files_struct *files)
81028150
{
81038151
if (list_empty_careful(&ctx->inflight_list))
81048152
return;
81058153

8154+
io_cancel_defer_files(ctx, files);
81068155
/* cancel all at once, should be faster than doing it one by one*/
81078156
io_wq_cancel_cb(ctx->io_wq, io_wq_files_match, files, true);
81088157

0 commit comments

Comments
 (0)