From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB44C327C06 for ; Tue, 27 Jan 2026 18:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769538807; cv=none; b=Fuzb+nmvxN9UyNOjj6LrM+D4qgJtGPkEyvzFYsHAdA+vdBB5AlX6QRNPttxX9/uZmjzIN9ucqb8M2dEo4QohKW+Ht+st/rBdxxtAwSCOaJ85c0ZJPXN/eqgVWHuQeLdLrpLMtMXEBvy4hR/JFlThpkQJP9tNtmqJViRxKjpBook= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769538807; c=relaxed/simple; bh=tZI1QB5MnRu4bKUEbLKC/RBZiGFsPlIzdvRmF+J3FfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dR59bkbI40aQTJ7/WczzROez+Kx2d5uT24dEBl0kAkYIQ0xk6Hw77z8fBZV1V3nzbIUSKWywhiKh9CjntEW6/L143/vF1ed27zovkYGnnjlhfom5aoSfFrBPRzzbPVjI2uQNH8wPEuM6SjmJipSq3ZoKcFae4oWeTIkAyWDvkBw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=pBolP3tK; arc=none smtp.client-ip=74.125.82.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="pBolP3tK" Received: by mail-dl1-f48.google.com with SMTP id a92af1059eb24-1233b953bebso1475107c88.1 for ; Tue, 27 Jan 2026 10:33:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1769538803; x=1770143603; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LUez8ctlQKD0wSJt7bnuKaxD6ngfcI5V1NPTGNxZ1OM=; b=pBolP3tKc3wwQahOxjklhMPNXrDOuOrVWhkwIMwcI0eLbH3rkDexCSHgKfEuAJlWXi KyCkhf2LNrNc5W9A2d+UR3H8wZomoec4wQEpOgGFULKtiGPFecOQcpdHaHTCNUNGlNOT qT1hVNBuimiq1bfaTwcrdySKA89uInq/AstlpoezIUYVnWQelkv7qzojhOYi5dpGXg+s u5PLqkoADKj7VFBH2O/+y7QdSmKCXdadsk7d4l/78Tpg3Vv/tE/zWyZDH/CO3kuj0/qT bfVMMBOtm6vGstHKY/YdP41P8vlcHM6PAC8CGCLJ3VU43VIbQvnIEu3oeF78RwC0OSL3 K8Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769538803; x=1770143603; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LUez8ctlQKD0wSJt7bnuKaxD6ngfcI5V1NPTGNxZ1OM=; b=RzQtmj+JgtpP4nfUCOo8UFpahFblNwf+qW28k8xYrzEOF1sMgcA2LaToTgplFrlhgC aISk29gkg7otaCxUFk+VzWKlirtB94vAUQ1rnVE2H4Jviz2qxd03rfnmPrIMfjDv3b69 KmkCzfPsk4srfBpP+42z7sochhNutmMrZQ3ZDIVYwGWGhJ/G/nSxbRIB1pFeQ5RdNBbN kRnMbLfhQBqI6xUKznFEoEDBICoTB3BmPBQU6tugF3mObpCwsKVnG9HbtRkLC3r2ZwN3 Cot3Dy86pD1VPvl/pa0mXbU3oXtFl+k4BZXiU7rOV4BzJrx+f7QqdVRncfE6NGtIgxym 9rvA== X-Forwarded-Encrypted: i=1; AJvYcCVF1QtIggSPk7jBw95CCqF7epSEFFFv+13cvWo3z7JyHtCiN4z+Ro8ufDM8DEIoAAGQ+3c/mvLA9NhVcbQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwWT3XvjxJkc/45S32yPgPHmD5dCX5yBH6JTdbhHIZSCNdUe2iJ yFDKsUuI34EO1Dl34vm3bDvD1bYdzh99oSzp1Z4MteFgVZdhUyQ81lKQ9BVKVppWlAc= X-Gm-Gg: AZuq6aL84JrJMdu2IuKt1DtsLXaYQ24QB9gz4U5lY+Insiq80vlF/EfyjmxHYGU54il 7dxghysGy0mAEgAzxIeUCZv1zf+tJEgixeWO28gMUxraHP+tkBD7F8yJIDDCJr5BjKNBRuwjzK9 OFewFNuaanU+iKlMKr8A1npBUB3mu+fGap8C5x3aq7N1QCgV+mhYtGVTKBMYn6RDg2FftJUp82G Zcv5gt5pg5Ae+MW3+bgoAWT4aKIoYPJNtX2Pms2c2Q1YrnnHWt6xSp/h8FYtV8Cm1bsFS2OZNAJ GvNWFZRJ+bjzDZfeGKmhmJ6rxH5wpGXz3MJe/O/sRcVdONMNuOo3hOPd0wim+ATLkidHNzYbTJy Mqsj4zh0723/6JuJF3ok/KGpt1U9bZ32dlhLQoDOxiETitSe6svUqLLxaHHUgPiyPZReK72AE8I VZ+kbvrSc7zg3Z9XcY9nQfpoA+wo2hUA6bpcH7LCZTnuRto/ZRjC2Pei0AV/FXLA== X-Received: by 2002:a05:7022:118e:b0:123:3360:aa99 with SMTP id a92af1059eb24-124a00f0febmr1115237c88.47.1769538802901; Tue, 27 Jan 2026 10:33:22 -0800 (PST) Received: from m2max.corp.tfbnw.net ([2620:10d:c090:600::cedf]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a7bd05b1sm670139c88.3.2026.01.27.10.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jan 2026 10:33:22 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: brauner@kernel.org, cyphar@cyphar.com, jannh@google.com, kees@kernel.org, linux-kernel@vger.kernel.org, Jens Axboe Subject: [PATCH 6/7] io_uring: add task fork hook Date: Tue, 27 Jan 2026 11:30:01 -0700 Message-ID: <20260127183311.86505-7-axboe@kernel.dk> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260127183311.86505-1-axboe@kernel.dk> References: <20260127183311.86505-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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) Signed-off-by: Jens Axboe --- include/linux/io_uring.h | 14 +++++++++++++- include/linux/sched.h | 1 + io_uring/tctx.c | 25 ++++++++++++++++--------- kernel/fork.c | 5 +++++ 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/linux/io_uring.h b/include/linux/io_uring.h index 85fe4e6b275c..d1aa4edfc2a5 100644 --- a/include/linux/io_uring.h +++ b/include/linux/io_uring.h @@ -12,6 +12,7 @@ void __io_uring_free(struct task_struct *tsk); void io_uring_unreg_ringfd(void); const char *io_uring_get_opcode(u8 opcode); bool io_is_uring_fops(struct file *file); +int __io_uring_fork(struct task_struct *tsk); static inline void io_uring_files_cancel(void) { @@ -25,9 +26,16 @@ static inline void io_uring_task_cancel(void) } static inline void io_uring_free(struct task_struct *tsk) { - if (tsk->io_uring) + if (tsk->io_uring || tsk->io_uring_restrict) __io_uring_free(tsk); } +static inline int io_uring_fork(struct task_struct *tsk) +{ + if (tsk->io_uring_restrict) + return __io_uring_fork(tsk); + + return 0; +} #else static inline void io_uring_task_cancel(void) { @@ -46,6 +54,10 @@ static inline bool io_is_uring_fops(struct file *file) { return false; } +static inline int io_uring_fork(struct task_struct *tsk) +{ + return 0; +} #endif #endif diff --git a/include/linux/sched.h b/include/linux/sched.h index d395f2810fac..9abbd11bb87c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1190,6 +1190,7 @@ struct task_struct { #ifdef CONFIG_IO_URING struct io_uring_task *io_uring; + struct io_restriction *io_uring_restrict; #endif /* Namespaces: */ diff --git a/io_uring/tctx.c b/io_uring/tctx.c index 5b66755579c0..d4f7698805e4 100644 --- a/io_uring/tctx.c +++ b/io_uring/tctx.c @@ -54,16 +54,18 @@ void __io_uring_free(struct task_struct *tsk) * node is stored in the xarray. Until that gets sorted out, attempt * an iteration here and warn if any entries are found. */ - xa_for_each(&tctx->xa, index, node) { - WARN_ON_ONCE(1); - break; - } - WARN_ON_ONCE(tctx->io_wq); - WARN_ON_ONCE(tctx->cached_refs); + if (tctx) { + xa_for_each(&tctx->xa, index, node) { + WARN_ON_ONCE(1); + break; + } + WARN_ON_ONCE(tctx->io_wq); + WARN_ON_ONCE(tctx->cached_refs); - percpu_counter_destroy(&tctx->inflight); - kfree(tctx); - tsk->io_uring = NULL; + percpu_counter_destroy(&tctx->inflight); + kfree(tctx); + tsk->io_uring = NULL; + } } __cold int io_uring_alloc_task_context(struct task_struct *task, @@ -351,3 +353,8 @@ int io_ringfd_unregister(struct io_ring_ctx *ctx, void __user *__arg, return i ? i : ret; } + +int __io_uring_fork(struct task_struct *tsk) +{ + return 0; +} diff --git a/kernel/fork.c b/kernel/fork.c index b1f3915d5f8e..08a2515380ec 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -97,6 +97,7 @@ #include #include #include +#include #include #include #include @@ -2129,6 +2130,9 @@ __latent_entropy struct task_struct *copy_process( #ifdef CONFIG_IO_URING p->io_uring = NULL; + retval = io_uring_fork(p); + if (unlikely(retval)) + goto bad_fork_cleanup_delayacct; #endif p->default_timer_slack_ns = current->timer_slack_ns; @@ -2525,6 +2529,7 @@ __latent_entropy struct task_struct *copy_process( mpol_put(p->mempolicy); #endif bad_fork_cleanup_delayacct: + io_uring_free(p); delayacct_tsk_free(p); bad_fork_cleanup_count: dec_rlimit_ucounts(task_ucounts(p), UCOUNT_RLIMIT_NPROC, 1); -- 2.51.0