From patchwork Tue May 24 21:37:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12860552 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 3C891C433EF for ; Tue, 24 May 2022 21:37:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241914AbiEXVhe (ORCPT ); Tue, 24 May 2022 17:37:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241898AbiEXVhd (ORCPT ); Tue, 24 May 2022 17:37:33 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0331C7C179 for ; Tue, 24 May 2022 14:37:33 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id j6so17532162pfe.13 for ; Tue, 24 May 2022 14:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lgzn2/RNupZuM19wVXWP3Kb3O3MsoN+ITbAK60/ayrA=; b=PguG1nrHMNp1L2LFUmj1GMgG+cSxNkTJHN9wATHFGJUE8pFUKGEnPG7R38AI/gAEbC h7DFgpgYP+f8VOUOzN5WjjZ3d9i8DKh9PzFZUEjyoHL7TV3q6cOh1H0plyw++Wi+fPOP BY/fC4yHugq93tlVi2Sovu3HQZyQUmw6tFgt6lyHQaaMEZympLAo85/3MzaxoDm0vNVF F1afpc6GJvJPHwMHAqws0c2HzyYIiDDHjXkJHSKHIT57WUo4S9eZPGx8CoKAAksMUNCT uKY4KCeeunE+sXWvWcs3cJDHNLtI9CV5z90Og/1gHlP4AUXJx3zBx/dJA2P6Dxg0O7IA dmVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lgzn2/RNupZuM19wVXWP3Kb3O3MsoN+ITbAK60/ayrA=; b=5xPQ5Xt+DrBzgTnWkTXqXfo85uQZkDQZNEqZIOjcFUjIJcA9lfcRL5iBXogVzaMYFD j4FSG+CSSvYnaBAK95FXWKhOPc/EBny7Y4DyScBNnERvQeh+gXagb1XpUl3D/b3hJfnD y9uMS0zZhR2Xjdr/a1qrBi6OS4gsWTyYLQ1MnyzC3pj9g/L6TnO+TpJCBmDo0SW2mkFq BGSlfxTpWlOq+oFAydE7XmamAx+2g55ztJRA4Ggc+y3PfG7FOWzjBH6/oFthRGmCcMkV FW6ZD3EpgAJNHhdVSTgu6zhZjvXJJyWQSy7cd6GN3Lz6lRkrJLXMAU0Fnyk5mzeFvwMh QTPg== X-Gm-Message-State: AOAM533NUmddo9K0D45sqx95dnPuz10h/vopoeW1HvT25sX7WTnvz3YJ 1V+abqIyuveyGbK1QHCqwpL6Zp3cv4Xlqg== X-Google-Smtp-Source: ABdhPJxAdtAjfW7yYfGn55nhXeGwvZZ6Gb0L4+lI0r1GmdzJnmb+uRg90M2QDZHYgbl58nkaoBZ0tQ== X-Received: by 2002:a63:104a:0:b0:3fa:d1ea:54d7 with SMTP id 10-20020a63104a000000b003fad1ea54d7mr1166284pgq.124.1653428252092; Tue, 24 May 2022 14:37:32 -0700 (PDT) Received: from localhost.localdomain ([2600:380:4a61:523:72ca:65a5:f684:5e4]) by smtp.gmail.com with ESMTPSA id k21-20020a170902761500b0015e8d4eb1easm7834327pll.52.2022.05.24.14.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 14:37:31 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/6] io_uring: make timeout prep handlers consistent with other prep handlers Date: Tue, 24 May 2022 15:37:22 -0600 Message-Id: <20220524213727.409630-2-axboe@kernel.dk> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524213727.409630-1-axboe@kernel.dk> References: <20220524213727.409630-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org All other opcodes take a {req, sqe} set for prep handling, split out a timeout prep handler so that timeout and linked timeouts can use the same one. Signed-off-by: Jens Axboe Reviewed-by: Kanchan Joshi --- fs/io_uring.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 9f1c682d7caf..c3991034b26a 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7698,8 +7698,9 @@ static int io_timeout_remove(struct io_kiocb *req, unsigned int issue_flags) return 0; } -static int io_timeout_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe, - bool is_timeout_link) +static int __io_timeout_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe, + bool is_timeout_link) { struct io_timeout_data *data; unsigned flags; @@ -7754,6 +7755,18 @@ static int io_timeout_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe, return 0; } +static int io_timeout_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + return __io_timeout_prep(req, sqe, false); +} + +static int io_link_timeout_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + return __io_timeout_prep(req, sqe, true); +} + static int io_timeout(struct io_kiocb *req, unsigned int issue_flags) { struct io_ring_ctx *ctx = req->ctx; @@ -8039,13 +8052,13 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) case IORING_OP_CONNECT: return io_connect_prep(req, sqe); case IORING_OP_TIMEOUT: - return io_timeout_prep(req, sqe, false); + return io_timeout_prep(req, sqe); case IORING_OP_TIMEOUT_REMOVE: return io_timeout_remove_prep(req, sqe); case IORING_OP_ASYNC_CANCEL: return io_async_cancel_prep(req, sqe); case IORING_OP_LINK_TIMEOUT: - return io_timeout_prep(req, sqe, true); + return io_link_timeout_prep(req, sqe); case IORING_OP_ACCEPT: return io_accept_prep(req, sqe); case IORING_OP_FALLOCATE: From patchwork Tue May 24 21:37:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12860554 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 EC44DC4332F for ; Tue, 24 May 2022 21:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229710AbiEXVhg (ORCPT ); Tue, 24 May 2022 17:37:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241932AbiEXVhf (ORCPT ); Tue, 24 May 2022 17:37:35 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67E197C173 for ; Tue, 24 May 2022 14:37:34 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id f4so2059165pgf.4 for ; Tue, 24 May 2022 14:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FFlSgwalLl9Cqqe5Co3myKgHH6/YZh8N+CMAW+ZAMNg=; b=xQWqNFPWnNQ0KF2DbcrJOR7uKh+7q9FROlmdyJ9Lreet5/Txv+SAwgiFDE+1FMKaGN UCXvTO4wLYa2LY4WRh0jpYiA+tqLUAEwT0MN6n0abKooWYrS1THhnLqfXpGkxE8JJrJY caD30JtbdF0fS3KxhHT7tXrXNE3KToPt4r3VGh9eZvdv7H4vsWa4N8VYefBVQ9b/7Ips OoMtTN0PqMiGt2wURepl5FqhLi5xONur5ZQR3RC83dmAWtGVPJ0tYBOXb4eztGSGbsuW XMH4xGDYoimvjdHJvm9Uy1meR1bg4U1sezqbRexNZvY1y/nmylNoXEx2ouCZsAtEm0SG yelA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FFlSgwalLl9Cqqe5Co3myKgHH6/YZh8N+CMAW+ZAMNg=; b=f5d0V/4kzQzuKMc2la/0GiDDAMX6s7zpw60DxN+hCDAit7utgECCOKl8r1y4teUEXg GA6B6zacSBPHbSzo1sH6I8b2MsScbEIWjiHSfG10oFp6TnXPGpSFZWWGcJNvr8CSw/mq xxzq83cyQQAcsr9g7UX1uDkCMmb03gvpDEJzWwPXp94f/El7v1lWKMs9CVoBM9FcMrI3 G6YwpBcN02j4LBm6L9RwLam9y0MNNx7u74K8hC2Q7oigihN475QYwgr1vnwa4gSf3Ox5 nUsVQhCb9UQYXjTosSoblwX4wybVF3oC2YbPlbTC77zD40l1+qwFmiV4w+BOxAkK+14b CnOg== X-Gm-Message-State: AOAM533LZ9Gt8pGMkZp4vKrh3MQeYDGzYYYTgbNmU/1XDrb0rvM4AIqG pLfDTyVxNKrlmmO1/4lXlu3DE2k/Rd3i1A== X-Google-Smtp-Source: ABdhPJxMs/PxayFSYBW5gtC2pSWVH/jdBZRHLGkNAp/eHjCelgq7k8nT1c+GjuVnt+bhnZUS6ZdU9Q== X-Received: by 2002:a63:e047:0:b0:3c6:bf87:3ab3 with SMTP id n7-20020a63e047000000b003c6bf873ab3mr25368422pgj.373.1653428253557; Tue, 24 May 2022 14:37:33 -0700 (PDT) Received: from localhost.localdomain ([2600:380:4a61:523:72ca:65a5:f684:5e4]) by smtp.gmail.com with ESMTPSA id k21-20020a170902761500b0015e8d4eb1easm7834327pll.52.2022.05.24.14.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 14:37:33 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/6] io_uring: make prep and issue side of req handlers named consistently Date: Tue, 24 May 2022 15:37:23 -0600 Message-Id: <20220524213727.409630-3-axboe@kernel.dk> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524213727.409630-1-axboe@kernel.dk> References: <20220524213727.409630-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Almost all of them are, the odd ones out are the poll remove and the files update request. Name them like the others, which is: io_#cmdname_prep for request preparation io_#cmdname for request issue Signed-off-by: Jens Axboe Reviewed-by: Kanchan Joshi --- fs/io_uring.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index c3991034b26a..01a96fcdb7c6 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7390,7 +7390,7 @@ static __poll_t io_poll_parse_events(const struct io_uring_sqe *sqe, return demangle_poll(events) | (events & (EPOLLEXCLUSIVE|EPOLLONESHOT)); } -static int io_poll_update_prep(struct io_kiocb *req, +static int io_poll_remove_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { struct io_poll_update *upd = &req->poll_update; @@ -7454,7 +7454,7 @@ static int io_poll_add(struct io_kiocb *req, unsigned int issue_flags) return 0; } -static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) +static int io_poll_remove(struct io_kiocb *req, unsigned int issue_flags) { struct io_cancel_data cd = { .data = req->poll_update.old_user_data, }; struct io_ring_ctx *ctx = req->ctx; @@ -7983,7 +7983,7 @@ static int io_async_cancel(struct io_kiocb *req, unsigned int issue_flags) return 0; } -static int io_rsrc_update_prep(struct io_kiocb *req, +static int io_files_update_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { if (unlikely(req->flags & (REQ_F_FIXED_FILE | REQ_F_BUFFER_SELECT))) @@ -8038,7 +8038,7 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) case IORING_OP_POLL_ADD: return io_poll_add_prep(req, sqe); case IORING_OP_POLL_REMOVE: - return io_poll_update_prep(req, sqe); + return io_poll_remove_prep(req, sqe); case IORING_OP_FSYNC: return io_fsync_prep(req, sqe); case IORING_OP_SYNC_FILE_RANGE: @@ -8068,7 +8068,7 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) case IORING_OP_CLOSE: return io_close_prep(req, sqe); case IORING_OP_FILES_UPDATE: - return io_rsrc_update_prep(req, sqe); + return io_files_update_prep(req, sqe); case IORING_OP_STATX: return io_statx_prep(req, sqe); case IORING_OP_FADVISE: @@ -8334,7 +8334,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) ret = io_poll_add(req, issue_flags); break; case IORING_OP_POLL_REMOVE: - ret = io_poll_update(req, issue_flags); + ret = io_poll_remove(req, issue_flags); break; case IORING_OP_SYNC_FILE_RANGE: ret = io_sync_file_range(req, issue_flags); From patchwork Tue May 24 21:37:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12860555 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 340FCC433EF for ; Tue, 24 May 2022 21:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241932AbiEXVhh (ORCPT ); Tue, 24 May 2022 17:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241010AbiEXVhg (ORCPT ); Tue, 24 May 2022 17:37:36 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB01D7C173 for ; Tue, 24 May 2022 14:37:35 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id bo5so17557297pfb.4 for ; Tue, 24 May 2022 14:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eigsg0jgxPfxJrEoqU9bXe0cm4Colyzl4UklgE5fKRM=; b=0boopjExMrbEH3gBHjkRNj1H7hXrqdeBZ0t7li+Z4NdoGmG4eQufovz40fLE4a5Tx8 b2zLpm59Nceigu2duVrbpmL6n1BSOM390eAUZMcTN4HmlwAr04P7XXIwgeQH9yqYfEEG I/sP/IwmJod2BnSMx8zO6rDHgkPm9Awc9uVpEGDm8vVHRf0dcOWtyifbKAl43QoJ8JFL Ui58MDECuO9A6ag0cxc2BNh36PulObS/IguKNndVgJN4GVzVCuWEN6UgD37hQ+FVr60o +EosM3mPbNR5AC9E0Z4Kpo8IJq1OGWcWXlETmUdirMxhOuzlazAoyo0el8vIr4YmXFO1 +gaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eigsg0jgxPfxJrEoqU9bXe0cm4Colyzl4UklgE5fKRM=; b=3SRxgfKt+Qw4RphMImvsNb4YnrAE3LmHyx0Cpf6o5uzFAxgKKXwwtnGp87aJ07+sKH grrsDlb6UWWAPxkmb77V5QDpT9iDSBKNiZ8mu2wNERl8PAkAqif1PoRzJMlXjxfgOBn5 9RDtw5mT1un7CeP3jg7evjBbxlY1cRsQwCsJxjSX2Z62IqQqDzaDxbv6NaFMLNstZgqr HdA6zNA9TSkxL7x+8OZYFeVLg9Bn9mAwGU7kP+/wUTBVacEkFWngWLu150iYRG4KeYqd cUSLGOxtPSbWJGKL80xoo6tFIhVJAoK0nHc4gIl2R61FunDHmspQo+lBpu2H0DVqtvQp 5WsQ== X-Gm-Message-State: AOAM533j4t0110E+Y5aYUxGbX4mChsBFKjNn2OvbxF0IRXsLKp60fWL7 vWAWc6+sJ6x02OFVzw2cOOBp993M6AnmRg== X-Google-Smtp-Source: ABdhPJxJve3VKBA1f107/UCrLPyaJFA0A3vT7uL/Ua9vXjYlL69BjXtXlhFK8e1yxKDwTQYN6vq2Zw== X-Received: by 2002:a05:6a00:1350:b0:518:6df7:7747 with SMTP id k16-20020a056a00135000b005186df77747mr23794894pfu.45.1653428254908; Tue, 24 May 2022 14:37:34 -0700 (PDT) Received: from localhost.localdomain ([2600:380:4a61:523:72ca:65a5:f684:5e4]) by smtp.gmail.com with ESMTPSA id k21-20020a170902761500b0015e8d4eb1easm7834327pll.52.2022.05.24.14.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 14:37:34 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/6] io_uring: add io_op_defs 'def' pointer in req init and issue Date: Tue, 24 May 2022 15:37:24 -0600 Message-Id: <20220524213727.409630-4-axboe@kernel.dk> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524213727.409630-1-axboe@kernel.dk> References: <20220524213727.409630-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Define and set it when appropriate, and use it consistently in the function rather than using io_op_defs[opcode]. Signed-off-by: Jens Axboe Reviewed-by: Kanchan Joshi --- fs/io_uring.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 01a96fcdb7c6..d2c99176b11a 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8301,6 +8301,7 @@ static bool io_assign_file(struct io_kiocb *req, unsigned int issue_flags) static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) { + const struct io_op_def *def = &io_op_defs[req->opcode]; const struct cred *creds = NULL; int ret; @@ -8310,7 +8311,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) if (unlikely((req->flags & REQ_F_CREDS) && req->creds != current_cred())) creds = override_creds(req->creds); - if (!io_op_defs[req->opcode].audit_skip) + if (!def->audit_skip) audit_uring_entry(req->opcode); switch (req->opcode) { @@ -8449,7 +8450,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) break; } - if (!io_op_defs[req->opcode].audit_skip) + if (!def->audit_skip) audit_uring_exit(!ret, ret); if (creds) @@ -8801,12 +8802,14 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, const struct io_uring_sqe *sqe) __must_hold(&ctx->uring_lock) { + const struct io_op_def *def; unsigned int sqe_flags; int personality; u8 opcode; /* req is partially pre-initialised, see io_preinit_req() */ req->opcode = opcode = READ_ONCE(sqe->opcode); + def = &io_op_defs[opcode]; /* same numerical values with corresponding REQ_F_*, safe to copy */ req->flags = sqe_flags = READ_ONCE(sqe->flags); req->cqe.user_data = READ_ONCE(sqe->user_data); @@ -8823,7 +8826,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, if (sqe_flags & ~SQE_VALID_FLAGS) return -EINVAL; if (sqe_flags & IOSQE_BUFFER_SELECT) { - if (!io_op_defs[opcode].buffer_select) + if (!def->buffer_select) return -EOPNOTSUPP; req->buf_index = READ_ONCE(sqe->buf_group); } @@ -8849,12 +8852,12 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, } } - if (!io_op_defs[opcode].ioprio && sqe->ioprio) + if (!def->ioprio && sqe->ioprio) return -EINVAL; - if (!io_op_defs[opcode].iopoll && (ctx->flags & IORING_SETUP_IOPOLL)) + if (!def->iopoll && (ctx->flags & IORING_SETUP_IOPOLL)) return -EINVAL; - if (io_op_defs[opcode].needs_file) { + if (def->needs_file) { struct io_submit_state *state = &ctx->submit_state; req->cqe.fd = READ_ONCE(sqe->fd); @@ -8863,7 +8866,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, * Plug now if we have more than 2 IO left after this, and the * target is potentially a read/write to block based storage. */ - if (state->need_plug && io_op_defs[opcode].plug) { + if (state->need_plug && def->plug) { state->plug_started = true; state->need_plug = false; blk_start_plug_nr_ios(&state->plug, state->submit_nr); From patchwork Tue May 24 21:37:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12860556 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 B9C2DC433F5 for ; Tue, 24 May 2022 21:37:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241934AbiEXVhl (ORCPT ); Tue, 24 May 2022 17:37:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241933AbiEXVhh (ORCPT ); Tue, 24 May 2022 17:37:37 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEBBA7C173 for ; Tue, 24 May 2022 14:37:36 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id a13so6427264plh.6 for ; Tue, 24 May 2022 14:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ph/WGOZONVdcjHqgTL9D/tGOhRzea7cIQH6mVWqydo8=; b=xy3mYHsL1dqcx8FBLuNKKV0mHqOwHXhMKZLC7hXb7tgqADMhEJyxgVgrVG/1rjsN5t 4ZtV5B+iVGMva/LTa75Ha6c5Xk6hr9EW16If4CPJ1bolQxtharcRIRyX8WWlRv7KmD85 u1G+d5wE96GvsKhII5Ufb7i4DO5sptEJiDoygRx0CqU/pmSiK8w92FQJC4DrWjkSNPXB jTTf9XKcXvZ7qQB3KHfIQxwh4yrW8LTBiWyMYOUKDwRmbw3SREiMUPxDUMfNyNXjQtks tvI8any3vVxpr1Pwm8ZbJJcUDmdEX+D3+XjZzc3TAnekhTEF/SLa0ftdkRzSuhpwOxg2 f24Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ph/WGOZONVdcjHqgTL9D/tGOhRzea7cIQH6mVWqydo8=; b=gJQuxymWsAIV8fou8s9m2mDz1xkRg/cSaUxSGKQXB9ovtxns18Rt00p/tkmnN023pN 5K2E4xJqSWQH0xlKdgDj11DgaF5p/blSa2XjuO/fG7WoZeEHMJuhLZlqPaWWIsLeRd7N lFFInrrKGHC5mMkWk1ntU5lJTcHyhd8B74DBNKjq4lnDdrb5XR2UB6CjthS5B8qh475m unY5k1L7iAjZzn/7OlsxQV+qcTniEMGo7sXLsgtm5KMqPgopOb5Fz7YCSa4L5oQ+BdW5 54laYkSCD8oroG/9vmIVCR5LgBNjDpzcS48lGS6VYj8Aq/woJb6rXbCRadOS+60+jWIy rgOw== X-Gm-Message-State: AOAM533KNJ2TvhnRcxl2DSEiV8ujEEuaiSPejm+KPnKibwNLnvaTZLHW 835UDx+mXhVNQJFK+hsTsk+ol4GkljUENQ== X-Google-Smtp-Source: ABdhPJw67HrZxvH7U+54uGxJF1XdB9aMjTAcxwhCy+RZeOyZ98vc74CwU47O+CC4R5o6nwfQzLiMhQ== X-Received: by 2002:a17:903:22d0:b0:162:bc1c:d700 with SMTP id y16-20020a17090322d000b00162bc1cd700mr2225193plg.105.1653428256191; Tue, 24 May 2022 14:37:36 -0700 (PDT) Received: from localhost.localdomain ([2600:380:4a61:523:72ca:65a5:f684:5e4]) by smtp.gmail.com with ESMTPSA id k21-20020a170902761500b0015e8d4eb1easm7834327pll.52.2022.05.24.14.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 14:37:35 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 4/6] io_uring: unify calling convention for async prep handling Date: Tue, 24 May 2022 15:37:25 -0600 Message-Id: <20220524213727.409630-5-axboe@kernel.dk> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524213727.409630-1-axboe@kernel.dk> References: <20220524213727.409630-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Make them consistent in preparation for defining a req async prep handler. The readv/writev requests share a prep handler, move it one level down so the initial one is consistent with the others. Signed-off-by: Jens Axboe --- fs/io_uring.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index d2c99176b11a..408265a03563 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4176,6 +4176,16 @@ static inline int io_rw_prep_async(struct io_kiocb *req, int rw) return 0; } +static int io_readv_prep_async(struct io_kiocb *req) +{ + return io_rw_prep_async(req, READ); +} + +static int io_writev_prep_async(struct io_kiocb *req) +{ + return io_rw_prep_async(req, READ); +} + /* * This is our waitqueue callback handler, registered through __folio_lock_async() * when we initially tried to do the IO with the iocb armed our waitqueue. @@ -8136,9 +8146,9 @@ static int io_req_prep_async(struct io_kiocb *req) switch (req->opcode) { case IORING_OP_READV: - return io_rw_prep_async(req, READ); + return io_readv_prep_async(req); case IORING_OP_WRITEV: - return io_rw_prep_async(req, WRITE); + return io_writev_prep_async(req); case IORING_OP_SENDMSG: return io_sendmsg_prep_async(req); case IORING_OP_RECVMSG: From patchwork Tue May 24 21:37:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12860557 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 24325C433FE for ; Tue, 24 May 2022 21:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241938AbiEXVhm (ORCPT ); Tue, 24 May 2022 17:37:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241010AbiEXVhj (ORCPT ); Tue, 24 May 2022 17:37:39 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 242747C17D for ; Tue, 24 May 2022 14:37:38 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d22so16930986plr.9 for ; Tue, 24 May 2022 14:37:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=x3ipgQpo024kD3RcxwTPeVNFPz0g/sbgu3FNn+sS9wo=; b=UxGl0qwSnl6iGpFGhAn11BKVlKN4ZFfS20X+zCAdygBt/x7CRMr0fFw43aR9tgMbJZ RlHv37ZIyfym7CMTFaiLFhJrucuQcI0rRpcyG1UfhSE1aHJ8wZE60j/9o58UI2lQmQdS n2WrBeqE5qTqo2G8fbTKmYcTDw8x/7UlpEQ8eigwstSFxhMknc1BcbOSnJMcqi/BNem6 6TzdognNR2OvoXcL2w6z8v97GZG8Nj0wbr87FLDoz9xsMinXz8QfOmpw5FaQlt0wM3Yn dwQtOoR3EJkeY+Mi36RIq41kieWkRnYdF0TUXnBriJiXsxDgJaTiQufGWtByefUvPyGY dKDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x3ipgQpo024kD3RcxwTPeVNFPz0g/sbgu3FNn+sS9wo=; b=hgRNlerBI2iK7FuxYsd3qCgYD+CPg8CEg1BDdNd58gryZin6NZxFnlUABfY5UOPO+q gioslQdseiiGmdQk6NkYCPZqJaFoBYRV2q7IGJa+pZGJiDskm+j1VZs8LJLJiQrCq5lT venfVbMa2oBslotAfLf8beNV6vKbv0U/zgv2pKO3ynWNAMVQQFHZ4xPubYDQjUf2wyGA om9zCuybLLS7aTRJU3QIZrK6sYjIfqTwqk4rYb8B+c/f08RVKh6S6DBCwmRrRnUbOhl5 /J4D/K0njRksRFOePVTZctoRUN9vpHICaIHzwkWhSrb01o/a6Cv45D6yiQPfOZXDFt0e kbuA== X-Gm-Message-State: AOAM530vNKH5omvpipA/711EJbdZRCXfGdIQQBxvKcAgBAKamCM1ey0H hhqPkydYeeuXl9g3moL5ttezBOA/jvFKQA== X-Google-Smtp-Source: ABdhPJwze6cPhcmVoi4iIDksmdpAWEwup9dKXw3BR5HM1shY96kvhm4N4rxja5s9QSC+A/x7bLUMbA== X-Received: by 2002:a17:903:240c:b0:153:c452:f282 with SMTP id e12-20020a170903240c00b00153c452f282mr28431942plo.88.1653428257374; Tue, 24 May 2022 14:37:37 -0700 (PDT) Received: from localhost.localdomain ([2600:380:4a61:523:72ca:65a5:f684:5e4]) by smtp.gmail.com with ESMTPSA id k21-20020a170902761500b0015e8d4eb1easm7834327pll.52.2022.05.24.14.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 14:37:36 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 5/6] io_uring: drop confusion between cleanup flags Date: Tue, 24 May 2022 15:37:26 -0600 Message-Id: <20220524213727.409630-6-axboe@kernel.dk> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524213727.409630-1-axboe@kernel.dk> References: <20220524213727.409630-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org If the opcode only stores data that needs to be kfree'ed in req->async_data, then it doesn't need special handling in our cleanup handler. This has the added bonus of removing knowledge of those kinds of special async_data to the io_uring core. Signed-off-by: Jens Axboe --- fs/io_uring.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 408265a03563..8188c47956ad 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8229,24 +8229,6 @@ static void io_clean_op(struct io_kiocb *req) if (req->flags & REQ_F_NEED_CLEANUP) { switch (req->opcode) { - case IORING_OP_READV: - case IORING_OP_READ_FIXED: - case IORING_OP_READ: - case IORING_OP_WRITEV: - case IORING_OP_WRITE_FIXED: - case IORING_OP_WRITE: { - struct io_async_rw *io = req->async_data; - - kfree(io->free_iovec); - break; - } - case IORING_OP_RECVMSG: - case IORING_OP_SENDMSG: { - struct io_async_msghdr *io = req->async_data; - - kfree(io->free_iov); - break; - } case IORING_OP_OPENAT: case IORING_OP_OPENAT2: if (req->open.filename) From patchwork Tue May 24 21:37:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12860558 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 9D279C433EF for ; Tue, 24 May 2022 21:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241010AbiEXVhm (ORCPT ); Tue, 24 May 2022 17:37:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241943AbiEXVhl (ORCPT ); Tue, 24 May 2022 17:37:41 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 906D97CB43 for ; Tue, 24 May 2022 14:37:39 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id gz24so1675pjb.2 for ; Tue, 24 May 2022 14:37:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UtwF8cedt/87lkaIX+o7YF0XPzxX7aNyfWm9R+ZxrV4=; b=4uGvYBII+wErWZK2p1rKZsl0bqAbdQDwOpVwhpFL9PRxh0HhwqzFR7alODAl791dd9 k2OJq546m2MRjav/MIiBMHpTnFC+aQtLLI6HyqtuY708XtwZkDvcETxrdXvY2OGEL2AQ B/zXh7kgvSA8quoiWBv6xcAHr4pNWTW+uB+vvjUsrCWuqcC3D6ZZ7gj46bd90RDMNm+V xFaxua6rDIvKyAyX4Z6vwZQTo4b+bJg2Sl9Jtv17ExwZ2t+HkWIzSus0f+7T5pdo4fF4 x0YTTkRr56eM9hre3FhZsu87DgneoEX/kBBbo3j2CpJdY4VsVMkRajOD0YK+pqcb0M5U HiPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UtwF8cedt/87lkaIX+o7YF0XPzxX7aNyfWm9R+ZxrV4=; b=Qja0MeRcoKxvpRA+CJBKH1IZyPbW27J4eE+ElR+PG6r1ZlCRqdjLvm+XxrwXOXshQl TcmqUkDN7xA8VP6k8aYwQIGrTX4wHkCESFVyrHV4BEZeRkBjgbcLMdUSYnJhE2wWD8lW 7iFkiBC1FP0e9+AK/7e1chRAUgS/Kil65kv2T+++YSxFUcquJzMTkhWyNGzp7k1+O0qi TgYWjhB678RMV/8mWXSEQCCqB2jMmSXsDLoAsBVxss4Xtor3MDkwyd78G9ztHsxsoYtY z5Yx0cN30zKeICCI9DecLfjRL1QFV/5jShQVUYkQT18KczkuHBpemxoEcTzYfqspOX8R RAJA== X-Gm-Message-State: AOAM533DrIF1SGMYoxx3m9HHxpbact26elrVW1Xzm94LNFgL2HJOvQDb 9rB5e7YX+y0yfjwZYVlpnbBmQ0fp/Bb7CQ== X-Google-Smtp-Source: ABdhPJzB7dx+MXuAYBH8OI8fgJrk0LBJGhaCah/r05+rAdo/2lgczzQ7FLNhu2dtQoXi1opZoMS/Og== X-Received: by 2002:a17:902:b58b:b0:162:2e01:9442 with SMTP id a11-20020a170902b58b00b001622e019442mr9151256pls.6.1653428258582; Tue, 24 May 2022 14:37:38 -0700 (PDT) Received: from localhost.localdomain ([2600:380:4a61:523:72ca:65a5:f684:5e4]) by smtp.gmail.com with ESMTPSA id k21-20020a170902761500b0015e8d4eb1easm7834327pll.52.2022.05.24.14.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 14:37:38 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 6/6] io_uring: move shutdown under the general net section Date: Tue, 24 May 2022 15:37:27 -0600 Message-Id: <20220524213727.409630-7-axboe@kernel.dk> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524213727.409630-1-axboe@kernel.dk> References: <20220524213727.409630-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Gets rid of some ifdefs and enables use of the net defines for when CONFIG_NET isn't set. Signed-off-by: Jens Axboe --- fs/io_uring.c | 66 +++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 8188c47956ad..9624ab114a40 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5113,42 +5113,6 @@ static int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags) return 0; } -static int io_shutdown_prep(struct io_kiocb *req, - const struct io_uring_sqe *sqe) -{ -#if defined(CONFIG_NET) - if (unlikely(sqe->off || sqe->addr || sqe->rw_flags || - sqe->buf_index || sqe->splice_fd_in)) - return -EINVAL; - - req->shutdown.how = READ_ONCE(sqe->len); - return 0; -#else - return -EOPNOTSUPP; -#endif -} - -static int io_shutdown(struct io_kiocb *req, unsigned int issue_flags) -{ -#if defined(CONFIG_NET) - struct socket *sock; - int ret; - - if (issue_flags & IO_URING_F_NONBLOCK) - return -EAGAIN; - - sock = sock_from_file(req->file); - if (unlikely(!sock)) - return -ENOTSOCK; - - ret = __sys_shutdown_sock(sock, req->shutdown.how); - io_req_complete(req, ret); - return 0; -#else - return -EOPNOTSUPP; -#endif -} - static int __io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { @@ -6073,6 +6037,34 @@ static int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags) } #if defined(CONFIG_NET) +static int io_shutdown_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + if (unlikely(sqe->off || sqe->addr || sqe->rw_flags || + sqe->buf_index || sqe->splice_fd_in)) + return -EINVAL; + + req->shutdown.how = READ_ONCE(sqe->len); + return 0; +} + +static int io_shutdown(struct io_kiocb *req, unsigned int issue_flags) +{ + struct socket *sock; + int ret; + + if (issue_flags & IO_URING_F_NONBLOCK) + return -EAGAIN; + + sock = sock_from_file(req->file); + if (unlikely(!sock)) + return -ENOTSOCK; + + ret = __sys_shutdown_sock(sock, req->shutdown.how); + io_req_complete(req, ret); + return 0; +} + static bool io_net_retry(struct socket *sock, int flags) { if (!(flags & MSG_WAITALL)) @@ -6777,8 +6769,10 @@ IO_NETOP_PREP_ASYNC(recvmsg); IO_NETOP_PREP_ASYNC(connect); IO_NETOP_PREP(accept); IO_NETOP_PREP(socket); +IO_NETOP_PREP(shutdown); IO_NETOP_FN(send); IO_NETOP_FN(recv); +IO_NETOP_FN(shutdown); #endif /* CONFIG_NET */ struct io_poll_table {