Skip to content

Commit 36e4c58

Browse files
committed
io-wq: invoke work cancelation with wqe->lock held
io_wqe_cancel_pending_work() grabs it internally, grab it upfront instead. For the running work cancelation, grab the lock around it as well. Signed-off-by: Jens Axboe <[email protected]>
1 parent 081b582 commit 36e4c58

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

fs/io-wq.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,17 +1038,16 @@ static void io_wqe_cancel_pending_work(struct io_wqe *wqe,
10381038
{
10391039
int i;
10401040
retry:
1041-
raw_spin_lock(&wqe->lock);
10421041
for (i = 0; i < IO_WQ_ACCT_NR; i++) {
10431042
struct io_wqe_acct *acct = io_get_acct(wqe, i == 0);
10441043

10451044
if (io_acct_cancel_pending_work(wqe, acct, match)) {
1045+
raw_spin_lock(&wqe->lock);
10461046
if (match->cancel_all)
10471047
goto retry;
1048-
return;
1048+
break;
10491049
}
10501050
}
1051-
raw_spin_unlock(&wqe->lock);
10521051
}
10531052

10541053
static void io_wqe_cancel_running_work(struct io_wqe *wqe,
@@ -1077,7 +1076,9 @@ enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
10771076
for_each_node(node) {
10781077
struct io_wqe *wqe = wq->wqes[node];
10791078

1079+
raw_spin_lock(&wqe->lock);
10801080
io_wqe_cancel_pending_work(wqe, &match);
1081+
raw_spin_unlock(&wqe->lock);
10811082
if (match.nr_pending && !match.cancel_all)
10821083
return IO_WQ_CANCEL_OK;
10831084
}
@@ -1091,7 +1092,9 @@ enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
10911092
for_each_node(node) {
10921093
struct io_wqe *wqe = wq->wqes[node];
10931094

1095+
raw_spin_lock(&wqe->lock);
10941096
io_wqe_cancel_running_work(wqe, &match);
1097+
raw_spin_unlock(&wqe->lock);
10951098
if (match.nr_running && !match.cancel_all)
10961099
return IO_WQ_CANCEL_RUNNING;
10971100
}
@@ -1262,7 +1265,9 @@ static void io_wq_destroy(struct io_wq *wq)
12621265
.fn = io_wq_work_match_all,
12631266
.cancel_all = true,
12641267
};
1268+
raw_spin_lock(&wqe->lock);
12651269
io_wqe_cancel_pending_work(wqe, &match);
1270+
raw_spin_unlock(&wqe->lock);
12661271
free_cpumask_var(wqe->cpu_mask);
12671272
kfree(wqe);
12681273
}

0 commit comments

Comments
 (0)