From patchwork Thu Aug 10 16:23:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13349711 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 56F85C001B0 for ; Thu, 10 Aug 2023 16:23:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233416AbjHJQXz (ORCPT ); Thu, 10 Aug 2023 12:23:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234307AbjHJQXx (ORCPT ); Thu, 10 Aug 2023 12:23:53 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFFA2213F for ; Thu, 10 Aug 2023 09:23:51 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-790af3bfa5cso14087139f.1 for ; Thu, 10 Aug 2023 09:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1691684631; x=1692289431; 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=iYBIDFS2cG7ajDUc70+r1XOh2p55BEGaXo35Fa744ik=; b=AOqr8NM/23o432Z8XK3tCFcG0gEXCYDjicmlb5TSIGQBgjqWp/IwD0tPqVRds5hMQK yvd/cCOyxWy2N8SqgEGSi4lxKjzFWaoNmDewoCh5Zio/8J4LzI3r94OUwft5Jiea7YsU oU5fCWLTKwWwsmhNXueGTJQhilzC4Pr5/KhyXf67f5ZdLVphuRRpRS2Rlgg8qnXWotds MT4QbH6uJBy9cSQ+38ae62VxSXs5plgVkMhETXEOZJ9EOvInUuLj6mDs5AzB7+HiGWZG El+ZMNal3NA2enpPJF1TGreXSVySXTheaJkGLB8vfyhLgwZIyAnx+AfiUhieg7lVbD6B KDkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691684631; x=1692289431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iYBIDFS2cG7ajDUc70+r1XOh2p55BEGaXo35Fa744ik=; b=jqfa3BkpQqUyFXWii+r5vXlBznDm0E7vz6dBxGfzLFx7hIKhCO0ve1JO+1KJvDY0FB SHaqfLibNtMpJ1olzdxwvSXerZ6vY6TuWHW9RlmYnp0ok6574C5pvnu4QSGwyUsRjzhc 0w7WT0oPWx7TRfmVlKEeevmjsk/0K38PRubzCEfaPccYEWwivuhh6fSJvH4MJmUgHdAM GQmNvMYv79iAGQSuAF9HduDBhjJwm5F5ZZ7XZBZ5KDradqsRBSn7WS8nqsVMSHcDZ8pf jOEugkOnJrTEghLQFbic6PQ1dNXxstVgCXfAN2/4B12zcxPX+7i912rBoWhw6jrKtmTW 0cuA== X-Gm-Message-State: AOJu0YyFs41qUBpb88hL9ZepdoLtJYRoRbW9Hnl8gTbkoX6mA7uTiFWY F/wpVNRHxE9HG7SwWjMxKDcTKU+hZPor8P/4kx0= X-Google-Smtp-Source: AGHT+IFEes5P2t5cJudItfWN/YUFnOmuwPdna+Bz/W3PlbQ03YIqOHCJmhr8p6ze0q68GQWu6GAJDQ== X-Received: by 2002:a05:6602:81c:b0:788:2d78:813c with SMTP id z28-20020a056602081c00b007882d78813cmr3849008iow.0.1691684631181; Thu, 10 Aug 2023 09:23:51 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id j5-20020a02cb05000000b0042ad887f705sm491941jap.143.2023.08.10.09.23.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 09:23:50 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/3] io_uring/fdinfo: get rid of ref tryget Date: Thu, 10 Aug 2023 10:23:44 -0600 Message-Id: <20230810162346.54872-2-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230810162346.54872-1-axboe@kernel.dk> References: <20230810162346.54872-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org The caller holds a reference to the ring itself, so by definition the ring cannot go away. There's no need to play games with tryget for the reference, as we don't need an extra reference at all. Signed-off-by: Jens Axboe --- io_uring/fdinfo.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/io_uring/fdinfo.c b/io_uring/fdinfo.c index 76c279b13aee..300455b4bc12 100644 --- a/io_uring/fdinfo.c +++ b/io_uring/fdinfo.c @@ -46,9 +46,13 @@ static __cold int io_uring_show_cred(struct seq_file *m, unsigned int id, return 0; } -static __cold void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, - struct seq_file *m) +/* + * Caller holds a reference to the file already, we don't need to do + * anything else to get an extra reference. + */ +__cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f) { + struct io_ring_ctx *ctx = f->private_data; struct io_sq_data *sq = NULL; struct io_overflow_cqe *ocqe; struct io_rings *r = ctx->rings; @@ -203,14 +207,4 @@ static __cold void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, spin_unlock(&ctx->completion_lock); } - -__cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f) -{ - struct io_ring_ctx *ctx = f->private_data; - - if (percpu_ref_tryget(&ctx->refs)) { - __io_uring_show_fdinfo(ctx, m); - percpu_ref_put(&ctx->refs); - } -} #endif From patchwork Thu Aug 10 16:23:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13349713 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 1189CC41513 for ; Thu, 10 Aug 2023 16:23:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234601AbjHJQX4 (ORCPT ); Thu, 10 Aug 2023 12:23:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235458AbjHJQXy (ORCPT ); Thu, 10 Aug 2023 12:23:54 -0400 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D142702 for ; Thu, 10 Aug 2023 09:23:53 -0700 (PDT) Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-3498976ebc6so646635ab.0 for ; Thu, 10 Aug 2023 09:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1691684632; x=1692289432; 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=cxaHqbHr486dg1bk6KiT4/voNxx72SQhsGodxfLREeA=; b=rMo9AuQAc6dNcvJBrHSLUUXBqqmQ4y1QW/m57+qEzUQOZOkeTblel/Ocd87tNH05BT unfvYrLAEVUx5B8eWBu5N1fItFOr2RAlWXu+r2Fjo3IFB4iYRg8f2+IzGGyOA84VeCnZ YGXzDKliLjX700pTwOevmAdLm3HrJtoVipyxTXqhj/+uhvEqMOAUXz/0bXP6tNYB1mw6 oeyy7L1hKtDRLDF5MIZxH+tLDk0+PWLpV9MpPs3GqC/UillpbkfNIva368hahec9XFAf B0U8P6nHpawCoJZTuwIpBCk1mvJJl1wohH6LuKcg1wq0Notnv/qCOO1iYVgLJlF5VUpz WYow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691684632; x=1692289432; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cxaHqbHr486dg1bk6KiT4/voNxx72SQhsGodxfLREeA=; b=EW0hDc8vMyct5+qIli4tq/sbmElc1jeT9xsOmlzdUmWwAZgCqeg/ccftA3wsD1pUwF zUmv67FE0517/I2N+YCtFi9NH2OH9Pik6gw21807nsgTiIEU9uxiJIf5SV03ypXgMPm2 H6WHxwp+NdrlviqrqRkjQNmeET+VMQ+IKASBWHU255F1+kpO7bkZQasGmbIsnXuJeIVD AXktqjgLX1l1jjhGovEF1DYZ/gDcRj0UQFGEeZ2EBHIFAKegIFjxbfCqwzfqp24rFvA8 +mt2E58DQncIHlgiKYYBpPCbAV5tF27PkEvMdtfwcXsfQC9GLL8PW1lit+APzOgWUXja W4Og== X-Gm-Message-State: AOJu0YwcvXs5cvSs59S3l3Ujaqv2hBbkXVQCSVzYlrdINGujwqrAezB/ GS577xyaNadPzYkgNP9C5TyZkfhXP0cZIfNIbPQ= X-Google-Smtp-Source: AGHT+IEt2IT5yaBvNdkSNaWIXBaSsWmF0QklmvZCGR5i1ONw4wBOrHOEs6WjvA9HIOJ+1Ti+eUudtw== X-Received: by 2002:a05:6e02:542:b0:349:582c:a68d with SMTP id i2-20020a056e02054200b00349582ca68dmr3404939ils.3.1691684632654; Thu, 10 Aug 2023 09:23:52 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id j5-20020a02cb05000000b0042ad887f705sm491941jap.143.2023.08.10.09.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 09:23:51 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/3] io_uring/splice: use fput() directly Date: Thu, 10 Aug 2023 10:23:45 -0600 Message-Id: <20230810162346.54872-3-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230810162346.54872-1-axboe@kernel.dk> References: <20230810162346.54872-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org No point in using io_file_put() here, as we need to check if it's a fixed file in the caller anyway. Signed-off-by: Jens Axboe --- io_uring/splice.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_uring/splice.c b/io_uring/splice.c index 2a4bbb719531..7c4469e9540e 100644 --- a/io_uring/splice.c +++ b/io_uring/splice.c @@ -68,7 +68,7 @@ int io_tee(struct io_kiocb *req, unsigned int issue_flags) ret = do_tee(in, out, sp->len, flags); if (!(sp->flags & SPLICE_F_FD_IN_FIXED)) - io_put_file(in); + fput(in); done: if (ret != sp->len) req_set_fail(req); @@ -112,7 +112,7 @@ int io_splice(struct io_kiocb *req, unsigned int issue_flags) ret = do_splice(in, poff_in, out, poff_out, sp->len, flags); if (!(sp->flags & SPLICE_F_FD_IN_FIXED)) - io_put_file(in); + fput(in); done: if (ret != sp->len) req_set_fail(req); From patchwork Thu Aug 10 16:23:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13349714 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 D2995C04E69 for ; Thu, 10 Aug 2023 16:23:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234502AbjHJQX5 (ORCPT ); Thu, 10 Aug 2023 12:23:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234588AbjHJQX4 (ORCPT ); Thu, 10 Aug 2023 12:23:56 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FFD8270A for ; Thu, 10 Aug 2023 09:23:54 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7748ca56133so14341639f.0 for ; Thu, 10 Aug 2023 09:23:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1691684633; x=1692289433; 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=/UoasOhdcT9+eZAvIQMPYP5p+87o/o7IGoeDljwITU4=; b=Czq8TDFSJAswQGP12EU5ZmSCOfZ3asfmNyLm/AEpPuFq9NNcWlAxjr+W0XqajGVasD WclhtZBicaia02qvrXvWEhjZCw8bglPncm1GymYZFlvruTVhSuHvz2kA3WUGZnFJnqFB qvjB0JAEc9w1YNAlpoDhBVX5ikgJTNU2GS9ytXqQJfpDcFftOwrwLF13N8youzAuSvap T44ef+hxnAEvKjCscVYzFyMHUbrwScQeWfwiwAohqs5ZF7K6Jn+r3t379X3la9FPM4uY 4JJsYgzK+C7uwfV7IKC11WjbMbaRMv4s7G4xYb44UvG9yh0ykqrcOnhpwXRnOr5RiveU +FTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691684633; x=1692289433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/UoasOhdcT9+eZAvIQMPYP5p+87o/o7IGoeDljwITU4=; b=eVewqvaQwAqfYaSxNA9X7Y6X4Fqw1cMJuoYhdeOS21nTwpY0NzOX6a5V3m7oji5ZGA JK8jih5JZfUwfFjSzp5RP0euzpO2fl3iTN1vjJWbFgI5gf4sCkTbed/SWCeVJS6RqTSb 4M9W9spv212/ZTIQBI323TAMzsqdhFWC/i6V5mRuTGgHckYmTv8hPdBf1dq6Fya5okLE cXLKzkRjvY6eFZJJaBssorep2VjYk1w6VMT1FtSKU3H6L3jcrzyZLEYHa1Q62Z1JaMwG SBRrMjGwqPlII53sPE3Icfc2yidjNJZ6LS2KtQlqtLY3GpxczcRd3+gVwSXvC0nj0Q+i OO+A== X-Gm-Message-State: AOJu0YxMLgxuOZXacL4KAfqSKs+0M2AvGaQhEQP4Ma1UR5f1ypBHohdd CGrpyvLoBTJHh7bzkX3463n+FwZGMHHsggEocCU= X-Google-Smtp-Source: AGHT+IF4ZqppbNKboQ9OsTCD0Rq+MW16YT9XWotEA1Lxf0J7zATPippDPhaVw81r+7wnMEyQ4P7N+g== X-Received: by 2002:a6b:c8c5:0:b0:787:16ec:2699 with SMTP id y188-20020a6bc8c5000000b0078716ec2699mr4768199iof.2.1691684633718; Thu, 10 Aug 2023 09:23:53 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id j5-20020a02cb05000000b0042ad887f705sm491941jap.143.2023.08.10.09.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 09:23:53 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/3] io_uring: have io_file_put() take an io_kiocb rather than the file Date: Thu, 10 Aug 2023 10:23:46 -0600 Message-Id: <20230810162346.54872-4-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230810162346.54872-1-axboe@kernel.dk> References: <20230810162346.54872-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org No functional changes in this patch, just a prep patch for needing the request in io_file_put(). Signed-off-by: Jens Axboe --- io_uring/io_uring.c | 4 ++-- io_uring/io_uring.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 3da26171599b..138635e66d44 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1004,7 +1004,7 @@ static void __io_req_complete_post(struct io_kiocb *req, unsigned issue_flags) if (unlikely(req->flags & IO_REQ_CLEAN_FLAGS)) io_clean_op(req); if (!(req->flags & REQ_F_FIXED_FILE)) - io_put_file(req->file); + io_put_file(req); rsrc_node = req->rsrc_node; /* @@ -1539,7 +1539,7 @@ void io_free_batch_list(struct io_ring_ctx *ctx, struct io_wq_work_node *node) io_clean_op(req); } if (!(req->flags & REQ_F_FIXED_FILE)) - io_put_file(req->file); + io_put_file(req); io_req_put_rsrc_locked(req, ctx); diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 12769bad5cee..46643bc9f3c5 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -196,10 +196,10 @@ static inline bool req_has_async_data(struct io_kiocb *req) return req->flags & REQ_F_ASYNC_DATA; } -static inline void io_put_file(struct file *file) +static inline void io_put_file(struct io_kiocb *req) { - if (file) - fput(file); + if (req->file) + fput(req->file); } static inline void io_ring_submit_unlock(struct io_ring_ctx *ctx,