Skip to contentSkip to conversation

random 5.20 patches

PATCH Applied Pavel Begunkov 2 participants 6 messages Jun 21, 2022 io_uring

lore
Share & tools
lore
#0 lore raw

cover random 5.20 patches

Just random patches, 1/4 is a poll fix.

Pavel Begunkov (4):
io_uring: fix poll_add error handling
io_uring: improve io_run_task_work()
io_uring: move list helpers to a separate file
io_uring: dedup io_run_task_work

 io_uring/filetable.h |   2 +
 io_uring/io-wq.c     |  18 ++----
 io_uring/io-wq.h     | 131 ----------------------------------------
 io_uring/io_uring.h  |   3 +-
 io_uring/poll.c      |   9 +--
 io_uring/slist.h     | 138 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 148 insertions(+), 153 deletions(-)
 create mode 100644 io_uring/slist.h
Signature · 1 line
2.36.1
#1 lore raw

PATCH 1/4 io_uring: fix poll_add error handling

We should first look at the return value of __io_arm_poll_handler() and only if zero checking for ipt.error, not the other way around. Currently we may enqueue a tw for such request and then release it inline causing UAF.

Fixes 9c1d09f56425e ("io_uring: handle completions in the core")
---
 io_uring/poll.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
io_uring/poll.c +2 -7
index 8f4fff76d3b4..528418aaf3f6 100644
@@ -782,16 +782,11 @@ int io_poll_add(struct io_kiocb *req, unsigned int issue_flags)
 		req->flags &= ~REQ_F_HASH_LOCKED;
 
 	ret = __io_arm_poll_handler(req, poll, &ipt, poll->events);
-	if (ipt.error) {
-		return ipt.error;
-	} else if (ret > 0) {
+	if (ret) {
 		io_req_set_res(req, ret, 0);
 		return IOU_OK;
-	} else if (!ret) {
-		return IOU_ISSUE_SKIP_COMPLETE;
 	}
-
-	return ret;
+	return ipt.error ?: IOU_ISSUE_SKIP_COMPLETE;
 }
 
 int io_poll_remove(struct io_kiocb *req, unsigned int issue_flags)
Signature · 1 line
2.36.1
#2 lore raw

PATCH 2/4 io_uring: improve io_run_task_work()

In reply to Pavel Begunkov

Since SQPOLL now uses TWA_SIGNAL_NO_IPI, there won't be task work items without TIF_NOTIFY_SIGNAL. Simplify io_run_task_work() by removing task->task_works check. Even though looks it doesn't cause extra cache bouncing, it's still nice to not touch it an extra time when it might be not cached.

---
 io_uring/io_uring.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/io_uring.h +1 -1
index 7a00bbe85d35..4c4d38ffc5ec 100644
@@ -203,7 +203,7 @@ static inline unsigned int io_sqring_entries(struct io_ring_ctx *ctx)
 
 static inline bool io_run_task_work(void)
 {
-	if (test_thread_flag(TIF_NOTIFY_SIGNAL) || task_work_pending(current)) {
+	if (test_thread_flag(TIF_NOTIFY_SIGNAL)) {
 		__set_current_state(TASK_RUNNING);
 		clear_notify_signal();
 		if (task_work_pending(current))
Signature · 1 line
2.36.1
#3 lore raw

PATCH 3/4 io_uring: move list helpers to a separate file

In reply to Pavel Begunkov

It's annoying to have io-wq.h as a dependency every time we want some of struct io_wq_work_list helpers, move them into a separate file.

---
 io_uring/io-wq.c    |   1 +
 io_uring/io-wq.h    | 131 -----------------------------------------
 io_uring/io_uring.h |   1 +
 io_uring/slist.h    | 138 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 140 insertions(+), 131 deletions(-)
 create mode 100644 io_uring/slist.h
io_uring/io-wq.c +1 -0
index 824623bcf1a5..3e34dfbdf946 100644
@@ -18,6 +18,7 @@
 #include <uapi/linux/io_uring.h>
 
 #include "io-wq.h"
+#include "slist.h"
 
 #define WORKER_IDLE_TIMEOUT	(5 * HZ)
 
io_uring/io-wq.h +0 -131

137 lines not on this page · raw message

io_uring/io_uring.h +1 -0
index 4c4d38ffc5ec..f026d2670959 100644
@@ -5,6 +5,7 @@
 #include <linux/lockdep.h>
 #include <linux/io_uring_types.h>
 #include "io-wq.h"
+#include "slist.h"
 #include "filetable.h"
 
 #ifndef CREATE_TRACE_POINTS
io_uring/slist.h new file +138 -0

139 lines not on this page · raw message

Signature · 1 line
2.36.1
#4 lore raw

PATCH 4/4 io_uring: dedup io_run_task_work

In reply to Pavel Begunkov

We have an identical copy of io_run_task_work() for io-wq called io_flush_signals(), deduplicate them.

---
 io_uring/filetable.h |  2 ++
 io_uring/io-wq.c     | 17 +++--------------
 2 files changed, 5 insertions(+), 14 deletions(-)
io_uring/filetable.h +2 -0
index 6b58aa48bc45..fb5a274c08ff 100644
@@ -2,6 +2,8 @@
 #ifndef IOU_FILE_TABLE_H
 #define IOU_FILE_TABLE_H
 
+#include <linux/file.h>
+
 struct io_ring_ctx;
 struct io_kiocb;
 
io_uring/io-wq.c +3 -14
index 3e34dfbdf946..77df5b43bf52 100644
@@ -19,6 +19,7 @@
 
 #include "io-wq.h"
 #include "slist.h"
+#include "io_uring.h"
 
 #define WORKER_IDLE_TIMEOUT	(5 * HZ)
 
@@ -519,23 +520,11 @@ static struct io_wq_work *io_get_next_work(struct io_wqe_acct *acct,
 	return NULL;
 }
 
-static bool io_flush_signals(void)
-{
-	if (unlikely(test_thread_flag(TIF_NOTIFY_SIGNAL))) {
-		__set_current_state(TASK_RUNNING);
-		clear_notify_signal();
-		if (task_work_pending(current))
-			task_work_run();
-		return true;
-	}
-	return false;
-}
-
 static void io_assign_current_work(struct io_worker *worker,
 				   struct io_wq_work *work)
 {
 	if (work) {
-		io_flush_signals();
+		io_run_task_work();
 		cond_resched();
 	}
 
@@ -655,7 +644,7 @@ static int io_wqe_worker(void *data)
 		last_timeout = false;
 		__io_worker_idle(wqe, worker);
 		raw_spin_unlock(&wqe->lock);
-		if (io_flush_signals())
+		if (io_run_task_work())
 			continue;
 		ret = schedule_timeout(WORKER_IDLE_TIMEOUT);
 		if (signal_pending(current)) {
Signature · 1 line
2.36.1
maintainer Applied
#5 lore raw
In reply to Pavel Begunkov
Quoted 9 lines · Pavel Begunkov

Just random patches, 1/4 is a poll fix.

Pavel Begunkov (4):
io_uring: fix poll_add error handling
io_uring: improve io_run_task_work()
io_uring: move list helpers to a separate file
io_uring: dedup io_run_task_work

[...]

Applied, thanks!

[1/4] io_uring: fix poll_add error handling
(no commit info)
[2/4] io_uring: improve io_run_task_work()
(no commit info)
[3/4] io_uring: move list helpers to a separate file
(no commit info)
[4/4] io_uring: dedup io_run_task_work
(no commit info)

Best regards,

Signature · 1 line
Jens Axboe