Skip to contentSkip to conversation

io-wq: close cancel gap for hashed linked work

PATCH Superseded Pavel Begunkov 2 participants 4 messages Mar 22, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io-wq: close cancel gap for hashed linked work

After io_assign_current_work() of a linked work, it can be decided to offloaded to another thread so doing io_wqe_enqueue(). However, until next io_assign_current_work() it can be cancelled, that isn't handled.

Don't assign it, if it's not going to be executed.

---
 fs/io-wq.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/io-wq.c +7 -3
index 9541df2729de..b3fb61ec0870 100644
@@ -485,7 +485,7 @@ static void io_worker_handle_work(struct io_worker *worker)
 	struct io_wq *wq = wqe->wq;
 
 	do {
-		struct io_wq_work *work;
+		struct io_wq_work *work, *assign_work;
 		unsigned int hash;
 get_next:
 		/*
@@ -522,10 +522,14 @@ static void io_worker_handle_work(struct io_worker *worker)
 			hash = io_get_work_hash(work);
 			work->func(&work);
 			work = (old_work == work) ? NULL : work;
-			io_assign_current_work(worker, work);
+
+			assign_work = work;
+			if (work && io_wq_is_hashed(work))
+				assign_work = NULL;
+			io_assign_current_work(worker, assign_work);
 			wq->free_work(old_work);
 
-			if (work && io_wq_is_hashed(work)) {
+			if (work && !assign_work) {
 				io_wqe_enqueue(wqe, work);
 				work = NULL;
 			}
Signature · 1 line
2.24.0
maintainer
#1 lore raw
Quoted 5 lines · Pavel Begunkov

After io_assign_current_work() of a linked work, it can be decided to offloaded to another thread so doing io_wqe_enqueue(). However, until next io_assign_current_work() it can be cancelled, that isn't handled.

Don't assign it, if it's not going to be executed.

This needs a Fixes: line as well. I'm guessing like this:

Fixes 60cf46ae6054 ("io-wq: hash dependent work")

but I didn't look too closely yet... Fix looks good, though.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 5 lines · Jens Axboe
Quoted 4 lines · Pavel Begunkov

After io_assign_current_work() of a linked work, it can be decided to offloaded to another thread so doing io_wqe_enqueue(). However, until next io_assign_current_work() it can be cancelled, that isn't handled.

Quoted 7 lines
Quoted 1 line

Don't assign it, if it's not going to be executed.

This needs a Fixes: line as well. I'm guessing like this:

Fixes 60cf46ae6054 ("io-wq: hash dependent work")

but I didn't look too closely yet... Fix looks good, though.

Yep, this one

Signature · 1 line
Pavel Begunkov
#3 lore raw

PATCH v2 1/1 io-wq: close cancel gap for hashed linked work

In reply to Jens Axboe

After io_assign_current_work() of a linked work, it can be decided to offloaded to another thread so doing io_wqe_enqueue(). However, until next io_assign_current_work() it can be cancelled, that isn't handled.

Don't assign it, if it's not going to be executed.

Fixes 60cf46ae605446feb0c43c472c0 ("io-wq: hash dependent work")
---
 fs/io-wq.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/io-wq.c +7 -3
index 9541df2729de..b3fb61ec0870 100644
@@ -485,7 +485,7 @@ static void io_worker_handle_work(struct io_worker *worker)
 	struct io_wq *wq = wqe->wq;
 
 	do {
-		struct io_wq_work *work;
+		struct io_wq_work *work, *assign_work;
 		unsigned int hash;
 get_next:
 		/*
@@ -522,10 +522,14 @@ static void io_worker_handle_work(struct io_worker *worker)
 			hash = io_get_work_hash(work);
 			work->func(&work);
 			work = (old_work == work) ? NULL : work;
-			io_assign_current_work(worker, work);
+
+			assign_work = work;
+			if (work && io_wq_is_hashed(work))
+				assign_work = NULL;
+			io_assign_current_work(worker, assign_work);
 			wq->free_work(old_work);
 
-			if (work && io_wq_is_hashed(work)) {
+			if (work && !assign_work) {
 				io_wqe_enqueue(wqe, work);
 				work = NULL;
 			}
Signature · 1 line
2.24.0