From patchwork Mon Sep 26 14:03:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 12988857 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 541F1C07E9D for ; Mon, 26 Sep 2022 15:17:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236085AbiIZPRk (ORCPT ); Mon, 26 Sep 2022 11:17:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235911AbiIZPQs (ORCPT ); Mon, 26 Sep 2022 11:16:48 -0400 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 781A427D for ; Mon, 26 Sep 2022 07:03:25 -0700 (PDT) Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 28Q9OiHT020937 for ; Mon, 26 Sep 2022 07:03:24 -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=k8e9XhReGPOptOw1DYeKjrBV9CjaPrV9yHOCxxhlJFU=; b=lppCbCxFHVAzTHD+1WMAbeJS6i673QDtY5cBg4uEkuamPn+oy8k1FiyHHKfb38NmwmYU OOUITycrHWoqRVSxUOWqh8+I1CXUmhno49cHUpAs3vAPRwr4PDZb/Zi3Qiiuu1lMBsoi zenam7B5yS2RQyFZ1FnlwJCX79g5nanUrzc= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net (PPS) with ESMTPS id 3jswjuk8w9-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 26 Sep 2022 07:03:24 -0700 Received: from twshared2996.07.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) 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 07:03:23 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 7E8636AEBEF6; Mon, 26 Sep 2022 07:03:17 -0700 (PDT) From: Dylan Yudaken To: Jens Axboe , Pavel Begunkov CC: , , , Dylan Yudaken Subject: [PATCH 1/3] io_uring: register single issuer task at creation Date: Mon, 26 Sep 2022 07:03:02 -0700 Message-ID: <20220926140304.1973990-2-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220926140304.1973990-1-dylany@fb.com> References: <20220926140304.1973990-1-dylany@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: LDlQn4xe-rT73bCpyjp-ywZHcAnT6GpK X-Proofpoint-ORIG-GUID: LDlQn4xe-rT73bCpyjp-ywZHcAnT6GpK 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_08,2022-09-22_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Instead of picking the task from the first submitter task, rather use the creator task. The downside of this is that users are unable to move tasks before submitting. However this simplifies the logic here. For example CQEs are able to be posted by io_uring_register, which could also be from a separate task. This could be confusing as this does not count as a submit, and so would not be the registered task. Additionally this removes init logic from the submission path, which can always be a bit confusing. Signed-off-by: Dylan Yudaken --- io_uring/io_uring.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 2965b354efc8..3f40defd721d 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3357,6 +3357,9 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p, goto err; } + if (ctx->flags & IORING_SETUP_SINGLE_ISSUER) + ctx->submitter_task = get_task_struct(current); + file = io_uring_get_file(ctx); if (IS_ERR(file)) { ret = PTR_ERR(file); From patchwork Mon Sep 26 14:03:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 12988858 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 E4937C6FA90 for ; Mon, 26 Sep 2022 15:17:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236100AbiIZPRm (ORCPT ); Mon, 26 Sep 2022 11:17:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236055AbiIZPQt (ORCPT ); Mon, 26 Sep 2022 11:16:49 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22DB55FEA for ; Mon, 26 Sep 2022 07:03:26 -0700 (PDT) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28PLQvO7016119 for ; Mon, 26 Sep 2022 07:03:25 -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=hT+4gTMKePBBA3f8O2UIS1QlPHJ9LqcravhbpAUEnQE=; b=jk7+V31/g01oHQ/r3JvRVUhUaxcRLHZA7Bl9hKqDfd1FLMkmNlqO2uZlThMXCOFpC9Nn jA5Enqtxi/QSnKi5uJM/zXElDYmyniq5eSSoZ2/bj4kRxJ9avrK5NOXTof07Nk/FqwWt 6+xYBO6rig+JIZEeaQ9zE2xiLQQeJWAYX/o= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3jt174jsfx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 26 Sep 2022 07:03:25 -0700 Received: from twshared14494.08.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) 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 07:03:24 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 85CB16AEBEF8; Mon, 26 Sep 2022 07:03:17 -0700 (PDT) From: Dylan Yudaken To: Jens Axboe , Pavel Begunkov CC: , , , Dylan Yudaken Subject: [PATCH 2/3] io_uring: simplify __io_uring_add_tctx_node Date: Mon, 26 Sep 2022 07:03:03 -0700 Message-ID: <20220926140304.1973990-3-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220926140304.1973990-1-dylany@fb.com> References: <20220926140304.1973990-1-dylany@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: jeIo3RHjljbc5fzlqcRKnw_xagsKDF-a X-Proofpoint-ORIG-GUID: jeIo3RHjljbc5fzlqcRKnw_xagsKDF-a 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_08,2022-09-22_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org 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 3f40defd721d..57315a49b85c 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 *ctx, struct file *file) if (fd < 0) return fd; - ret = __io_uring_add_tctx_node(ctx, false); + ret = __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; } -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 = current->io_uring; struct io_tctx_node *node; int ret; - if ((ctx->flags & IORING_SETUP_SINGLE_ISSUER) && submitter) { - ret = io_register_submitter(ctx); - if (ret) - return ret; - } - if (unlikely(!tctx)) { ret = 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 = 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 = io_register_submitter(ctx); + if (ret) + return ret; + } + + ret = __io_uring_add_tctx_node(ctx); + if (ret) + return ret; + + current->io_uring->last = ctx; return 0; } @@ -259,7 +269,7 @@ int io_ringfd_register(struct io_ring_ctx *ctx, void __user *__arg, return -EINVAL; mutex_unlock(&ctx->uring_lock); - ret = __io_uring_add_tctx_node(ctx, false); + ret = __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); void io_uring_unreg_ringfd(void); @@ -27,5 +28,6 @@ static inline int io_uring_add_tctx_node(struct io_ring_ctx *ctx) if (likely(tctx && tctx->last == ctx)) return 0; - return __io_uring_add_tctx_node(ctx, true); + + return __io_uring_add_tctx_node_from_submit(ctx); } From patchwork Mon Sep 26 14:03:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 12988859 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 B1BB2C6FA83 for ; Mon, 26 Sep 2022 15:17:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236106AbiIZPRn (ORCPT ); Mon, 26 Sep 2022 11:17:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235888AbiIZPQt (ORCPT ); Mon, 26 Sep 2022 11:16:49 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 010DD14039 for ; Mon, 26 Sep 2022 07:03:26 -0700 (PDT) Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28Q4MFiX026435 for ; Mon, 26 Sep 2022 07:03:26 -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=VOkC8FQpC4zEdwZGjv8fsTnFHjzx11x0ZIHzXALRfqbJai3D+nSPMcVHXjeYWtZPngaS py8aeP9W/ETmNQVOXK9sEN+jkRf8WlzTkRXW8DXU5Dnyzv3uBEqbbsMkH0EOslV8Kc56 RQLYpWeoLlS37/SjxTAVLsl6t7xE5w2NoXU= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3jsydxtwrf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 26 Sep 2022 07:03:25 -0700 Received: from twshared14494.08.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) 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 07:03:24 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 8CC906AEBEFC; Mon, 26 Sep 2022 07:03:17 -0700 (PDT) From: Dylan Yudaken To: Jens Axboe , Pavel Begunkov CC: , , , Dylan Yudaken Subject: [PATCH 3/3] io_uring: remove io_register_submitter Date: Mon, 26 Sep 2022 07:03:04 -0700 Message-ID: <20220926140304.1973990-4-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220926140304.1973990-1-dylany@fb.com> References: <20220926140304.1973990-1-dylany@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: PNAM7hDsd9EWP7USUqz_xomtnLEPfAJ0 X-Proofpoint-GUID: PNAM7hDsd9EWP7USUqz_xomtnLEPfAJ0 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_08,2022-09-22_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org 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_struct *task, return 0; } -static int io_register_submitter(struct io_ring_ctx *ctx) -{ - int ret = 0; - - mutex_lock(&ctx->uring_lock); - if (!ctx->submitter_task) - ctx->submitter_task = get_task_struct(current); - else if (ctx->submitter_task != current) - ret = -EEXIST; - mutex_unlock(&ctx->uring_lock); - - return ret; -} - int __io_uring_add_tctx_node(struct io_ring_ctx *ctx) { struct io_uring_task *tctx = current->io_uring; @@ -151,11 +137,9 @@ int __io_uring_add_tctx_node_from_submit(struct io_ring_ctx *ctx) { int ret; - if (ctx->flags & IORING_SETUP_SINGLE_ISSUER) { - ret = io_register_submitter(ctx); - if (ret) - return ret; - } + if (ctx->flags & IORING_SETUP_SINGLE_ISSUER + && ctx->submitter_task != current) + return -EEXIST; ret = __io_uring_add_tctx_node(ctx); if (ret)