Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring: add task fork hook

Called when copy_process() is called to copy state to a new child.
Right now this is just a stub, but will be used shortly to properly
handle fork'ing of task based io_uring restrictions.

Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

+36 -10
+13 -1
include/linux/io_uring.h
··· 12 12 void io_uring_unreg_ringfd(void); 13 13 const char *io_uring_get_opcode(u8 opcode); 14 14 bool io_is_uring_fops(struct file *file); 15 + int __io_uring_fork(struct task_struct *tsk); 15 16 16 17 static inline void io_uring_files_cancel(void) 17 18 { ··· 26 25 } 27 26 static inline void io_uring_free(struct task_struct *tsk) 28 27 { 29 - if (tsk->io_uring) 28 + if (tsk->io_uring || tsk->io_uring_restrict) 30 29 __io_uring_free(tsk); 30 + } 31 + static inline int io_uring_fork(struct task_struct *tsk) 32 + { 33 + if (tsk->io_uring_restrict) 34 + return __io_uring_fork(tsk); 35 + 36 + return 0; 31 37 } 32 38 #else 33 39 static inline void io_uring_task_cancel(void) ··· 53 45 static inline bool io_is_uring_fops(struct file *file) 54 46 { 55 47 return false; 48 + } 49 + static inline int io_uring_fork(struct task_struct *tsk) 50 + { 51 + return 0; 56 52 } 57 53 #endif 58 54
+1
include/linux/sched.h
··· 1190 1190 1191 1191 #ifdef CONFIG_IO_URING 1192 1192 struct io_uring_task *io_uring; 1193 + struct io_restriction *io_uring_restrict; 1193 1194 #endif 1194 1195 1195 1196 /* Namespaces: */
+16 -9
io_uring/tctx.c
··· 54 54 * node is stored in the xarray. Until that gets sorted out, attempt 55 55 * an iteration here and warn if any entries are found. 56 56 */ 57 - xa_for_each(&tctx->xa, index, node) { 58 - WARN_ON_ONCE(1); 59 - break; 60 - } 61 - WARN_ON_ONCE(tctx->io_wq); 62 - WARN_ON_ONCE(tctx->cached_refs); 57 + if (tctx) { 58 + xa_for_each(&tctx->xa, index, node) { 59 + WARN_ON_ONCE(1); 60 + break; 61 + } 62 + WARN_ON_ONCE(tctx->io_wq); 63 + WARN_ON_ONCE(tctx->cached_refs); 63 64 64 - percpu_counter_destroy(&tctx->inflight); 65 - kfree(tctx); 66 - tsk->io_uring = NULL; 65 + percpu_counter_destroy(&tctx->inflight); 66 + kfree(tctx); 67 + tsk->io_uring = NULL; 68 + } 67 69 } 68 70 69 71 __cold int io_uring_alloc_task_context(struct task_struct *task, ··· 352 350 } 353 351 354 352 return i ? i : ret; 353 + } 354 + 355 + int __io_uring_fork(struct task_struct *tsk) 356 + { 357 + return 0; 355 358 }
+6
kernel/fork.c
··· 97 97 #include <linux/kasan.h> 98 98 #include <linux/scs.h> 99 99 #include <linux/io_uring.h> 100 + #include <linux/io_uring_types.h> 100 101 #include <linux/bpf.h> 101 102 #include <linux/stackprotector.h> 102 103 #include <linux/user_events.h> ··· 2130 2129 2131 2130 #ifdef CONFIG_IO_URING 2132 2131 p->io_uring = NULL; 2132 + retval = io_uring_fork(p); 2133 + if (unlikely(retval)) 2134 + goto bad_fork_cleanup_delayacct; 2135 + retval = -EAGAIN; 2133 2136 #endif 2134 2137 2135 2138 p->default_timer_slack_ns = current->timer_slack_ns; ··· 2530 2525 mpol_put(p->mempolicy); 2531 2526 #endif 2532 2527 bad_fork_cleanup_delayacct: 2528 + io_uring_free(p); 2533 2529 delayacct_tsk_free(p); 2534 2530 bad_fork_cleanup_count: 2535 2531 dec_rlimit_ucounts(task_ucounts(p), UCOUNT_RLIMIT_NPROC, 1);