From nobody Mon Apr 6 11:52:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0C84C32771 for ; Mon, 26 Sep 2022 17:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231237AbiIZRmr (ORCPT ); Mon, 26 Sep 2022 13:42:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbiIZRmP (ORCPT ); Mon, 26 Sep 2022 13:42:15 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 193AC17AA8 for ; Mon, 26 Sep 2022 10:09:40 -0700 (PDT) Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28QApP6J006398 for ; Mon, 26 Sep 2022 10:09:39 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=vLUCidGyBbc0aglagMzLHklot9FF2ixj2NRn9pzX/t8=; b=iImqhsF3FzWHg1MJQmaYM4F/Xu00lJY821fzOkSoEikc8tMsv0pPVIcKugCsQIw/gqg5 zmlOjIL2h/Bfb/qYtWL2RXMmp84XAN52i8qebqraB4UaOTespZH23La35V68MjnOovMe K4Lp4FwD69YIuSW8LJRrUVrquWzWqu8V9GY= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3jsyknmms3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 26 Sep 2022 10:09:39 -0700 Received: from twshared8247.08.ash8.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:11d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 26 Sep 2022 10:09:38 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id C66116B0A92B; Mon, 26 Sep 2022 10:09:27 -0700 (PDT) From: Dylan Yudaken To: Jens Axboe , Pavel Begunkov CC: , , , Dylan Yudaken Subject: [PATCH v2 1/3] io_uring: register single issuer task at creation Date: Mon, 26 Sep 2022 10:09:25 -0700 Message-ID: <20220926170927.3309091-2-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220926170927.3309091-1-dylany@fb.com> References: <20220926170927.3309091-1-dylany@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe X-Proofpoint-GUID: sX_s_IQcl5FxPz2Fo9n8TSw3fwwn1zE6 X-Proofpoint-ORIG-GUID: sX_s_IQcl5FxPz2Fo9n8TSw3fwwn1zE6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-26_09,2022-09-22_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Instead of picking the task from the first submitter task, rather use the creator task or in the case of disabled (IORING_SETUP_R_DISABLED) the enabling task. This approach allows a lot of simplification of the logic here. This removes init logic from the submission path, which can always be a bit confusing, but also removes the need for locking to write (or read) the submitter_task. Users that want to move a ring before submitting can create the ring disabled and then enable it on the submitting task. Signed-off-by: Dylan Yudaken --- io_uring/io_uring.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 2965b354efc8..242d896c00f3 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3357,6 +3357,10 @@ static __cold int io_uring_create(unsigned entries, = struct io_uring_params *p, goto err; } =20 + if (ctx->flags & IORING_SETUP_SINGLE_ISSUER + && !(ctx->flags & IORING_SETUP_R_DISABLED)) + ctx->submitter_task =3D get_task_struct(current); + file =3D io_uring_get_file(ctx); if (IS_ERR(file)) { ret =3D PTR_ERR(file); @@ -3548,6 +3552,9 @@ static int io_register_enable_rings(struct io_ring_ct= x *ctx) if (!(ctx->flags & IORING_SETUP_R_DISABLED)) return -EBADFD; =20 + if (ctx->flags & IORING_SETUP_SINGLE_ISSUER && !ctx->submitter_task) + ctx->submitter_task =3D get_task_struct(current); + if (ctx->restrictions.registered) ctx->restricted =3D 1; =20 --=20 2.30.2 From nobody Mon Apr 6 11:52:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0A05C32771 for ; Mon, 26 Sep 2022 17:42:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230343AbiIZRmh (ORCPT ); Mon, 26 Sep 2022 13:42:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230137AbiIZRmN (ORCPT ); Mon, 26 Sep 2022 13:42:13 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEF1311C33 for ; Mon, 26 Sep 2022 10:09:35 -0700 (PDT) Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28QA5BKY026969 for ; Mon, 26 Sep 2022 10:09:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=c4USphZiYFgb2XSoT9kDp0XititVsmIX3HgAhXfYStU=; b=L13AApzljZgtxIVRSQt390XYXSNG760bi4uvmNHFRsUIfu/OoMWp4FnuI/pWDLYn1bT+ tBaUF0dajTXjQZqvgPhjQbVtrJXD5nvh5R2EEi1/VL89RaO1zoGOdLsv8/iM7FTJVxWO yK4nvK1pIV7Ug/91L63EHQmssKbaCn+VAGY= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3jsy0tmp79-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 26 Sep 2022 10:09:35 -0700 Received: from twshared3028.05.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 26 Sep 2022 10:09:34 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id D1F636B0A92E; Mon, 26 Sep 2022 10:09:27 -0700 (PDT) From: Dylan Yudaken To: Jens Axboe , Pavel Begunkov CC: , , , Dylan Yudaken Subject: [PATCH v2 2/3] io_uring: simplify __io_uring_add_tctx_node Date: Mon, 26 Sep 2022 10:09:26 -0700 Message-ID: <20220926170927.3309091-3-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220926170927.3309091-1-dylany@fb.com> References: <20220926170927.3309091-1-dylany@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe X-Proofpoint-GUID: Hh_b6el9IyY9tRYy5fLsjM1pPktqVJSI X-Proofpoint-ORIG-GUID: Hh_b6el9IyY9tRYy5fLsjM1pPktqVJSI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-26_09,2022-09-22_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove submitter parameter from __io_uring_add_tctx_node. It was only called from one place, and we can do that logic in that one place. Signed-off-by: Dylan Yudaken --- io_uring/io_uring.c | 2 +- io_uring/tctx.c | 30 ++++++++++++++++++++---------- io_uring/tctx.h | 6 ++++-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 242d896c00f3..a4024d56240f 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3183,7 +3183,7 @@ static int io_uring_install_fd(struct io_ring_ctx *ct= x, struct file *file) if (fd < 0) return fd; =20 - ret =3D __io_uring_add_tctx_node(ctx, false); + ret =3D __io_uring_add_tctx_node(ctx); if (ret) { put_unused_fd(fd); return ret; diff --git a/io_uring/tctx.c b/io_uring/tctx.c index 7f97d97fef0a..dd0205fcdb13 100644 --- a/io_uring/tctx.c +++ b/io_uring/tctx.c @@ -105,18 +105,12 @@ static int io_register_submitter(struct io_ring_ctx *= ctx) return ret; } =20 -int __io_uring_add_tctx_node(struct io_ring_ctx *ctx, bool submitter) +int __io_uring_add_tctx_node(struct io_ring_ctx *ctx) { struct io_uring_task *tctx =3D current->io_uring; struct io_tctx_node *node; int ret; =20 - if ((ctx->flags & IORING_SETUP_SINGLE_ISSUER) && submitter) { - ret =3D io_register_submitter(ctx); - if (ret) - return ret; - } - if (unlikely(!tctx)) { ret =3D io_uring_alloc_task_context(current, ctx); if (unlikely(ret)) @@ -150,8 +144,24 @@ int __io_uring_add_tctx_node(struct io_ring_ctx *ctx, = bool submitter) list_add(&node->ctx_node, &ctx->tctx_list); mutex_unlock(&ctx->uring_lock); } - if (submitter) - tctx->last =3D ctx; + return 0; +} + +int __io_uring_add_tctx_node_from_submit(struct io_ring_ctx *ctx) +{ + int ret; + + if (ctx->flags & IORING_SETUP_SINGLE_ISSUER) { + ret =3D io_register_submitter(ctx); + if (ret) + return ret; + } + + ret =3D __io_uring_add_tctx_node(ctx); + if (ret) + return ret; + + current->io_uring->last =3D ctx; return 0; } =20 @@ -259,7 +269,7 @@ int io_ringfd_register(struct io_ring_ctx *ctx, void __= user *__arg, return -EINVAL; =20 mutex_unlock(&ctx->uring_lock); - ret =3D __io_uring_add_tctx_node(ctx, false); + ret =3D __io_uring_add_tctx_node(ctx); mutex_lock(&ctx->uring_lock); if (ret) return ret; diff --git a/io_uring/tctx.h b/io_uring/tctx.h index 25974beed4d6..608e96de70a2 100644 --- a/io_uring/tctx.h +++ b/io_uring/tctx.h @@ -9,7 +9,8 @@ struct io_tctx_node { int 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, bool submitter); +int __io_uring_add_tctx_node(struct io_ring_ctx *ctx); +int __io_uring_add_tctx_node_from_submit(struct io_ring_ctx *ctx); void io_uring_clean_tctx(struct io_uring_task *tctx); =20 void io_uring_unreg_ringfd(void); @@ -27,5 +28,6 @@ static inline int io_uring_add_tctx_node(struct io_ring_c= tx *ctx) =20 if (likely(tctx && tctx->last =3D=3D ctx)) return 0; - return __io_uring_add_tctx_node(ctx, true); + + return __io_uring_add_tctx_node_from_submit(ctx); } --=20 2.30.2 From nobody Mon Apr 6 11:52:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39803C07E9D for ; Mon, 26 Sep 2022 17:42:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230371AbiIZRmm (ORCPT ); Mon, 26 Sep 2022 13:42:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230186AbiIZRmO (ORCPT ); Mon, 26 Sep 2022 13:42:14 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A473C1788E for ; Mon, 26 Sep 2022 10:09:39 -0700 (PDT) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28QAw4KS008332 for ; Mon, 26 Sep 2022 10:09:38 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=QjTyb5cqB8JpM+faMD/4F0TT8m42x/Q1YTWctvgR8EE=; b=K3MpZKDPFT+Sn8s4QizUGgYe7GZ9DToWTuRPkhEVZPt2THTp0xlX6kmqgk6R7EmqDRj9 dc21rqeaiJg6RVzD+WVZQUAndV/43+m05lt863/QGe3CB7fSeVRYApps70i/VO7LE5+L f62eWmOCLbx6Sdhb0vO95QiEBokXgE6McxM= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3jsyn04fnp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 26 Sep 2022 10:09:38 -0700 Received: from twshared2996.07.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 26 Sep 2022 10:09:38 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id D682A6B0A930; Mon, 26 Sep 2022 10:09:27 -0700 (PDT) From: Dylan Yudaken To: Jens Axboe , Pavel Begunkov CC: , , , Dylan Yudaken Subject: [PATCH v2 3/3] io_uring: remove io_register_submitter Date: Mon, 26 Sep 2022 10:09:27 -0700 Message-ID: <20220926170927.3309091-4-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220926170927.3309091-1-dylany@fb.com> References: <20220926170927.3309091-1-dylany@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe X-Proofpoint-GUID: 5d-zhA2xthEtdZu9b80W-od6WVccU68N X-Proofpoint-ORIG-GUID: 5d-zhA2xthEtdZu9b80W-od6WVccU68N X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-26_09,2022-09-22_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" this is no longer needed, as submitter_task is set at creation time. Signed-off-by: Dylan Yudaken --- io_uring/tctx.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/io_uring/tctx.c b/io_uring/tctx.c index dd0205fcdb13..4324b1cf1f6a 100644 --- a/io_uring/tctx.c +++ b/io_uring/tctx.c @@ -91,20 +91,6 @@ __cold int io_uring_alloc_task_context(struct task_struc= t *task, return 0; } =20 -static int io_register_submitter(struct io_ring_ctx *ctx) -{ - int ret =3D 0; - - mutex_lock(&ctx->uring_lock); - if (!ctx->submitter_task) - ctx->submitter_task =3D get_task_struct(current); - else if (ctx->submitter_task !=3D current) - ret =3D -EEXIST; - mutex_unlock(&ctx->uring_lock); - - return ret; -} - int __io_uring_add_tctx_node(struct io_ring_ctx *ctx) { struct io_uring_task *tctx =3D current->io_uring; @@ -151,11 +137,9 @@ int __io_uring_add_tctx_node_from_submit(struct io_rin= g_ctx *ctx) { int ret; =20 - if (ctx->flags & IORING_SETUP_SINGLE_ISSUER) { - ret =3D io_register_submitter(ctx); - if (ret) - return ret; - } + if (ctx->flags & IORING_SETUP_SINGLE_ISSUER + && ctx->submitter_task !=3D current) + return -EEXIST; =20 ret =3D __io_uring_add_tctx_node(ctx); if (ret) --=20 2.30.2