From mboxrd@z Thu Jan 1 00:00:00 1970 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 CB638C433F5 for ; Tue, 5 Apr 2022 02:37:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbiDECjG (ORCPT ); Mon, 4 Apr 2022 22:39:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbiDECi7 (ORCPT ); Mon, 4 Apr 2022 22:38:59 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7329254951 for ; Mon, 4 Apr 2022 18:39:25 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id gt4so4538903pjb.4 for ; Mon, 04 Apr 2022 18:39:25 -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=oUSkiCIKDszKfMa2Axzg9BrbFIepg9ZI9Q2puU5x6rA=; b=IvpqiESKT2bbOm8PxEjnVW7PRd2mEMS1DEOkcc5HHSBoVCS+RNmS2PJEDgd14+Neb8 bgcpnEaF27WXTCOTVPg5CxRNl4h3vUlaMdkP/55vHT/AvF3Uw+RjCsEkNA5vOBoZp75A UEujNWpGtLbFNmrlqWbzO654dPb+Gk9BW/vmDbfmmGfEr9J/FE7ii3tS+fpza1C35Gmw QMET71bIjB5to3Qwy2vRn3nq1DVel5jytfHbkr2VctYTnHv6aaGmM0Y0iwwanZNV+FhO 5cdPyXjTROYHf0KCI4hNy9v5xevAhV3z1ZaV1othnD2FdUAl7yQir9DaiDx8Z2/WdHOo bEYQ== 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=oUSkiCIKDszKfMa2Axzg9BrbFIepg9ZI9Q2puU5x6rA=; b=6W3kuxOjpFs1bBmSZNmQGfx/a57jVSiLeYK7SmB18RVdWZFuptT+F79zvlkp+uyeWZ oIS1wPqAjsMJftZB4PvZfLVvpIH11Vuh2tT9SXXB9SwR2A2Bm5XappKIh+3l6dhkG+Pl eViJ4ZRsDoAdUoeVuzj1UOaYyPxihucjD/urjX9Ndq4oQDnWE2fp1RuR5pAJcB86aY6U 0Fdgh25x/xRxk7g/um0+Ma/UtLw1srkwvwgbZHujanX1iNBAeSFJM1R5FhI209oQ9PpB G3PKXEUNSY+yAUICnSZP7s8nXlafIIWY9RcfUUI47aNzUz2dqedx0R8+0h6UzJwktu95 4ehQ== X-Gm-Message-State: AOAM532o10LVAXfP1ePTuczkn661vouqzz2NaOzpGEbXaUHNxSbCR5aS s6sAToXDr2hbtrmrlJfMur6rsyr3Nb/KZA== X-Google-Smtp-Source: ABdhPJwofPNRykDB98EX86mbuRhidKD3QC3l8EqNCZttbCCnJV2I5vX+2W8UEML7OhO4P5r/nQ5rYQ== X-Received: by 2002:a05:6a00:1c9e:b0:4fa:d946:378b with SMTP id y30-20020a056a001c9e00b004fad946378bmr598956pfw.46.1649116596282; Mon, 04 Apr 2022 16:56:36 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id i7-20020a628707000000b004fa6eb33b02sm13157977pfe.49.2022.04.04.16.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 16:56:35 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe , stable@vger.kernel.org Subject: [PATCH 2/6] io_uring: defer splice/tee file validity check until command issue Date: Mon, 4 Apr 2022 17:56:22 -0600 Message-Id: <20220404235626.374753-3-axboe@kernel.dk> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220404235626.374753-1-axboe@kernel.dk> References: <20220404235626.374753-1-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org In preparation for not using the file at prep time, defer checking if this file refers to a valid io_uring instance until issue time. This also means we can get rid of the cleanup flag for splice and tee. Cc: stable@vger.kernel.org # v5.15+ Signed-off-by: Jens Axboe --- fs/io_uring.c | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 9108c56bff5b..0152ef49cf46 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -654,10 +654,10 @@ struct io_epoll { struct io_splice { struct file *file_out; - struct file *file_in; loff_t off_out; loff_t off_in; u64 len; + int splice_fd_in; unsigned int flags; }; @@ -1687,14 +1687,6 @@ static void io_prep_async_work(struct io_kiocb *req) if (def->unbound_nonreg_file) req->work.flags |= IO_WQ_WORK_UNBOUND; } - - switch (req->opcode) { - case IORING_OP_SPLICE: - case IORING_OP_TEE: - if (!S_ISREG(file_inode(req->splice.file_in)->i_mode)) - req->work.flags |= IO_WQ_WORK_UNBOUND; - break; - } } static void io_prep_async_link(struct io_kiocb *req) @@ -4369,18 +4361,11 @@ static int __io_splice_prep(struct io_kiocb *req, if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) return -EINVAL; - sp->file_in = NULL; sp->len = READ_ONCE(sqe->len); sp->flags = READ_ONCE(sqe->splice_flags); - if (unlikely(sp->flags & ~valid_flags)) return -EINVAL; - - sp->file_in = io_file_get(req->ctx, req, READ_ONCE(sqe->splice_fd_in), - (sp->flags & SPLICE_F_FD_IN_FIXED)); - if (!sp->file_in) - return -EBADF; - req->flags |= REQ_F_NEED_CLEANUP; + sp->splice_fd_in = READ_ONCE(sqe->splice_fd_in); return 0; } @@ -4395,20 +4380,27 @@ static int io_tee_prep(struct io_kiocb *req, static int io_tee(struct io_kiocb *req, unsigned int issue_flags) { struct io_splice *sp = &req->splice; - struct file *in = sp->file_in; struct file *out = sp->file_out; unsigned int flags = sp->flags & ~SPLICE_F_FD_IN_FIXED; + struct file *in; long ret = 0; if (issue_flags & IO_URING_F_NONBLOCK) return -EAGAIN; + + in = io_file_get(req->ctx, req, sp->splice_fd_in, + (sp->flags & SPLICE_F_FD_IN_FIXED)); + if (!in) { + ret = -EBADF; + goto done; + } + if (sp->len) ret = do_tee(in, out, sp->len, flags); if (!(sp->flags & SPLICE_F_FD_IN_FIXED)) io_put_file(in); - req->flags &= ~REQ_F_NEED_CLEANUP; - +done: if (ret != sp->len) req_set_fail(req); io_req_complete(req, ret); @@ -4427,15 +4419,22 @@ static int io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) static int io_splice(struct io_kiocb *req, unsigned int issue_flags) { struct io_splice *sp = &req->splice; - struct file *in = sp->file_in; struct file *out = sp->file_out; unsigned int flags = sp->flags & ~SPLICE_F_FD_IN_FIXED; loff_t *poff_in, *poff_out; + struct file *in; long ret = 0; if (issue_flags & IO_URING_F_NONBLOCK) return -EAGAIN; + in = io_file_get(req->ctx, req, sp->splice_fd_in, + (sp->flags & SPLICE_F_FD_IN_FIXED)); + if (!in) { + ret = -EBADF; + goto done; + } + poff_in = (sp->off_in == -1) ? NULL : &sp->off_in; poff_out = (sp->off_out == -1) ? NULL : &sp->off_out; @@ -4444,8 +4443,7 @@ static int io_splice(struct io_kiocb *req, unsigned int issue_flags) if (!(sp->flags & SPLICE_F_FD_IN_FIXED)) io_put_file(in); - req->flags &= ~REQ_F_NEED_CLEANUP; - +done: if (ret != sp->len) req_set_fail(req); io_req_complete(req, ret); @@ -7176,11 +7174,6 @@ static void io_clean_op(struct io_kiocb *req) kfree(io->free_iov); break; } - case IORING_OP_SPLICE: - case IORING_OP_TEE: - if (!(req->splice.flags & SPLICE_F_FD_IN_FIXED)) - io_put_file(req->splice.file_in); - break; case IORING_OP_OPENAT: case IORING_OP_OPENAT2: if (req->open.filename) -- 2.35.1