From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 E93CE32B981 for ; Wed, 8 Apr 2026 19:27:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775676437; cv=none; b=LDbDbexerrzF9hvxHebNaRTjyC5MXTg5U1SKSi0oQKoLLctBdSOkQLoO5u5aYqJY7h5n6+KdSTKogSel3J4OCKSg3UyJ3ppGKFp0DzfbTIJIWoV5W+xshng5i/u6UsPkbeaVrlajGLl1RFQ79YrU/UyxCbQPm1JaKSvIKi72KYA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775676437; c=relaxed/simple; bh=hNyUfT4yB3oo30ZYg1WCe+kgly/TTehAjbzjHtGFxwE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S+0E7Ak42bG5PPjOXhRwUcwSDQZ1ux4WHVRVvcBVuLvEvDg/PIrHcdPcRCuKRtvqv4HfaOevAGSLXjENtV2pYSmElIDsIhPLQ+B9CBl8H9YOvBYQNvmJy2xUZtxpJcDPY7O7CvgkOjU+Bn/kr+j/WggGFtu/GS7SzC7cAsEMg2E= 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.20251104.gappssmtp.com header.i=@kernel-dk.20251104.gappssmtp.com header.b=urjQ7lwF; arc=none smtp.client-ip=209.85.210.41 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.20251104.gappssmtp.com header.i=@kernel-dk.20251104.gappssmtp.com header.b="urjQ7lwF" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-7dbdcb85067so86903a34.1 for ; Wed, 08 Apr 2026 12:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20251104.gappssmtp.com; s=20251104; t=1775676434; x=1776281234; 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=IhrudRYYudIPEKNi9zX8pTiElDrwhwnXrXpdF7r5gh0=; b=urjQ7lwFDqHgy1I82nV8J3KkVasR1M6kd3CRiPF+Z+nmN1VN/Am9YamVX/Yc540re6 MB3qgiowEz4CiZXvCxWj6bUOJ656I8zKiDJkF+JgTNmxLZiwOsJij2OS93zm4/tkZSru 2E+QiMcjQOeXNq1MSj75vfICQcPAwh5nS0mQEio6JFgASyGpjgF+/Q+VCG06a6kceXIw wighobxMuxreO61iExQ6yJxBc1kyVoumRUSXNkY1HVNFAM/WF5xu5WElJq12I6auBlgh mFAOiy+6r59p+zxP4Yo4S5L8XauVHI7tiUq/3EJkwSNRzQu+b9Tm31AzGWomToaC8hTO OMqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775676434; x=1776281234; 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=IhrudRYYudIPEKNi9zX8pTiElDrwhwnXrXpdF7r5gh0=; b=GPqIydEEKUqx234jIPReao3NyDEwrrxuCXvvspHQK4VYKQ8P36TvkoGXC8L0Rqru/4 XysHB7yI+iUiNIFvc6mRoN18f6UZizxVLIkODbHGQM9TYixrYOxbYtbeNrYTJau8Cjgn /M6820gfPfdxE3JRLHHYMf0olMHNLXROBwC0tH5a+Yd0Qwt68y8ONoa+SMlMwF9nL3zG EyxjqyMTrRC5kJN2bKrDoNOZGKSkhzcMWYCTaf9sy2tPy8ytr7DVse2xb4O57fAueNAF X4C1K7+0irFX1Rp697Kmg29xCdm7RqA0/gn3sc91vdw3fbxlF89+2bD1V3EvSQVhXmuC ri7w== X-Gm-Message-State: AOJu0Yz4qrOGFBOMJg9ZBhz1+d/Q1BdaDeejRfuCyAeGctnhsYAEEPW4 zdVjGgoBcwqAjlJPcqZU93nB7e5A26s4ufHO1VZFhSdClk63Yq4K625F0QZI657zJsBMuejhkAZ SID+S X-Gm-Gg: AeBDies9xVwSulnLWwhI1+p8arLNLDBaKu13+pX8QrbbOFiUQ1+4yVAS9XmGhUns8Yq plWHEoL9bvc0T2prf1H/Q4f+WBFuRXM+2MGxzIB+ba0Nv3DZIIwQjCnG+qnVqO7BNA84npk7TGJ N6uyhwUwRyT1o+xCT+Oo7BejazGACvac7LP9vhEFN+xiZoRnEYVPz1fNN2z4FrIIb+2x4Wq5a3q QVPu/PRmTr8iRjZZjYf5nXh6Op3S7qvQpxdyiOrrRjneKJ8m7GlnWHJeEGFfj0OPh1/Q9YYS9h8 rPU4bZom9pRHi7Vq/HsiUezigPoVCLzYOVUGDa1T3+4WCmC45ILJz4Sm/cT62jOrK6UykqVpiSf f4pDUi3AcI2Yslf9uBT7z3PFICbvv35vFCyor0I9EO/iz0j7iJJKfhDfU41YKSlXMCvIx8111wk 9M4Lrqy4a6GsPHt7wh7xJmwRgc9YxRAbORqJyJT2HGUCNNzQBSRFH/V/No1Pvlvj0XE/s= X-Received: by 2002:a05:6830:8281:b0:7d7:4aa5:5210 with SMTP id 46e09a7af769-7dc16f2dfa2mr528103a34.19.1775676434519; Wed, 08 Apr 2026 12:27:14 -0700 (PDT) Received: from m2max ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7dbfc1cb79esm3359699a34.15.2026.04.08.12.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 12:27:13 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/2] io_uring/tctx: have io_uring_alloc_task_context() return tctx Date: Wed, 8 Apr 2026 13:24:07 -0600 Message-ID: <20260408192711.396827-2-axboe@kernel.dk> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408192711.396827-1-axboe@kernel.dk> References: <20260408192711.396827-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Instead of having io_uring_alloc_task_context() return an int and assign tsk->io_uring, just have it return the task context directly. This enables cleaner error handling in callers, which may have failure points post calling io_uring_alloc_task_context(). Signed-off-by: Jens Axboe --- io_uring/sqpoll.c | 8 +++++++- io_uring/tctx.c | 21 ++++++++++----------- io_uring/tctx.h | 4 ++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c index c6bb938ec5ea..46c12afec73e 100644 --- a/io_uring/sqpoll.c +++ b/io_uring/sqpoll.c @@ -458,6 +458,7 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx, return -EINVAL; } if (ctx->flags & IORING_SETUP_SQPOLL) { + struct io_uring_task *tctx; struct task_struct *tsk; struct io_sq_data *sqd; bool attached; @@ -524,8 +525,13 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx, rcu_assign_pointer(sqd->thread, tsk); mutex_unlock(&sqd->lock); + ret = 0; get_task_struct(tsk); - ret = io_uring_alloc_task_context(tsk, ctx); + tctx = io_uring_alloc_task_context(tsk, ctx); + if (!IS_ERR(tctx)) + tsk->io_uring = tctx; + else + ret = PTR_ERR(tctx); wake_up_new_task(tsk); if (ret) goto err; diff --git a/io_uring/tctx.c b/io_uring/tctx.c index 143de8e990eb..e5cef6a8dde0 100644 --- a/io_uring/tctx.c +++ b/io_uring/tctx.c @@ -74,20 +74,20 @@ void __io_uring_free(struct task_struct *tsk) } } -__cold int io_uring_alloc_task_context(struct task_struct *task, - struct io_ring_ctx *ctx) +__cold struct io_uring_task *io_uring_alloc_task_context(struct task_struct *task, + struct io_ring_ctx *ctx) { struct io_uring_task *tctx; int ret; tctx = kzalloc_obj(*tctx); if (unlikely(!tctx)) - return -ENOMEM; + return ERR_PTR(-ENOMEM); ret = percpu_counter_init(&tctx->inflight, 0, GFP_KERNEL); if (unlikely(ret)) { kfree(tctx); - return ret; + return ERR_PTR(ret); } tctx->io_wq = io_init_wq_offload(ctx, task); @@ -95,7 +95,7 @@ __cold int io_uring_alloc_task_context(struct task_struct *task, ret = PTR_ERR(tctx->io_wq); percpu_counter_destroy(&tctx->inflight); kfree(tctx); - return ret; + return ERR_PTR(ret); } tctx->task = task; @@ -103,10 +103,9 @@ __cold int io_uring_alloc_task_context(struct task_struct *task, init_waitqueue_head(&tctx->wait); atomic_set(&tctx->in_cancel, 0); atomic_set(&tctx->inflight_tracked, 0); - task->io_uring = tctx; init_llist_head(&tctx->task_list); init_task_work(&tctx->task_work, tctx_task_work); - return 0; + return tctx; } int __io_uring_add_tctx_node(struct io_ring_ctx *ctx) @@ -116,11 +115,11 @@ int __io_uring_add_tctx_node(struct io_ring_ctx *ctx) int ret; if (unlikely(!tctx)) { - ret = io_uring_alloc_task_context(current, ctx); - if (unlikely(ret)) - return ret; + tctx = io_uring_alloc_task_context(current, ctx); + if (IS_ERR(tctx)) + return PTR_ERR(tctx); - tctx = current->io_uring; + current->io_uring = tctx; if (ctx->int_flags & IO_RING_F_IOWQ_LIMITS_SET) { unsigned int limits[2] = { ctx->iowq_limits[0], ctx->iowq_limits[1], }; diff --git a/io_uring/tctx.h b/io_uring/tctx.h index 608e96de70a2..2310d2a0c46d 100644 --- a/io_uring/tctx.h +++ b/io_uring/tctx.h @@ -6,8 +6,8 @@ struct io_tctx_node { struct io_ring_ctx *ctx; }; -int io_uring_alloc_task_context(struct task_struct *task, - struct io_ring_ctx *ctx); +struct io_uring_task *io_uring_alloc_task_context(struct task_struct *task, + struct io_ring_ctx *ctx); void io_uring_del_tctx_node(unsigned long index); int __io_uring_add_tctx_node(struct io_ring_ctx *ctx); int __io_uring_add_tctx_node_from_submit(struct io_ring_ctx *ctx); -- 2.53.0