Skip to contentSkip to conversation

io-wq: ensure work->task_pid is cleared on init

PATCH In review Jens Axboe 2 participants 3 messages Feb 25, 2020

Subsystems (2)
lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io-wq: ensure work->task_pid is cleared on init

We use ->task_pid for exit cancellation, but we need to ensure it's cleared to zero for io_req_work_grab_env() to do the right thing.

Fixes 36282881a795 ("io-wq: add io_wq_cancel_pid() to cancel based on a specific pid")

---

fs/io-wq.h +1 -0
index ccc7d84af57d..9e9419c08bc1 100644
@@ -88,6 +88,7 @@ struct io_wq_work {
 		(work)->creds = NULL;			\
 		(work)->fs = NULL;			\
 		(work)->flags = 0;			\
+		(work)->task_pid = 0;			\
 	} while (0)					\
 
 typedef void (get_work_fn)(struct io_wq_work *);
Signature · 1 line
Jens Axboe
#1 lore raw
Quoted 2 lines · Jens Axboe

We use ->task_pid for exit cancellation, but we need to ensure it's cleared to zero for io_req_work_grab_env() to do the right thing.

How about initializing .task_pid with this (totally untested) patch?

fs/io-wq.h +1 -9
index ccc7d84af57d..b8d3287cec57 100644
@@ -80,15 +80,7 @@ struct io_wq_work {
 };
 
 #define INIT_IO_WORK(work, _func)			\
-	do {						\
-		(work)->list.next = NULL;		\
-		(work)->func = _func;			\
-		(work)->files = NULL;			\
-		(work)->mm = NULL;			\
-		(work)->creds = NULL;			\
-		(work)->fs = NULL;			\
-		(work)->flags = 0;			\
-	} while (0)					\
+	do { *(work) = (struct io_wq_work){ .func = _func }; } while (0)
 
 typedef void (get_work_fn)(struct io_wq_work *);
 typedef void (put_work_fn)(struct io_wq_work *);

Thanks,

Bart.

author maintainer
#2 lore raw
Quoted 17 lines · Bart Van Assche
Quoted 2 lines · Jens Axboe

We use ->task_pid for exit cancellation, but we need to ensure it's cleared to zero for io_req_work_grab_env() to do the right thing.

How about initializing .task_pid with this (totally untested) patch?

fs/io-wq.h +0 -3
index ccc7d84af57d..b8d3287cec57 100644
@@ -80,15 +80,7 @@ struct io_wq_work {
  };
 
  #define INIT_IO_WORK(work, _func)			\
-	do {						\
-		(work)->list.next = NULL;		\
-		(work)->func = _func;			\

fs/io-wq.h struct io_wq_work { · line 86

Quoted 10 lines
fs/io-wq.h +1 -6
-		(work)->files = NULL;			\
-		(work)->mm = NULL;			\
-		(work)->creds = NULL;			\
-		(work)->fs = NULL;			\
-		(work)->flags = 0;			\
-	} while (0)					\
+	do { *(work) = (struct io_wq_work){ .func = _func }; } while (0)
 
  typedef void (get_work_fn)(struct io_wq_work *);
  typedef void (put_work_fn)(struct io_wq_work *);

That's not a bad idea and would be more future proof, in case more fields are added at a later date.

Signature · 1 line
Jens Axboe