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 X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0565C2D0DB for ; Wed, 29 Jan 2020 22:38:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 779D82071E for ; Wed, 29 Jan 2020 22:38:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gMW0L3Yn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726222AbgA2Wi0 (ORCPT ); Wed, 29 Jan 2020 17:38:26 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37795 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbgA2WiZ (ORCPT ); Wed, 29 Jan 2020 17:38:25 -0500 Received: by mail-wm1-f68.google.com with SMTP id f129so1851679wmf.2 for ; Wed, 29 Jan 2020 14:38:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:autocrypt:message-id:date:user-agent :mime-version:in-reply-to; bh=7osWCWNb8K+14NXV/kaHB64AxuR7v4vfSX68yqI4Xt4=; b=gMW0L3YnPsq831n8DIEw9Qz+oGTNipQxiY3kpopbaIejmPVCauxqEfKE352E6qMD2I 9hgTUGb3vLuiwsP+mQSQErimKoyjYXOxa9XFHnXGYO1RpPSj7XIAxIRrCQySdGwAdJpO YJjaBhkac6Jqp0Ig1D1PmIEFnzme5HdiBybNAs6eL/1zlrTz54j5BO2XEJFaFmKAD6iy aV9WlxjLImSJKnvpW90bDTK7INwqQToHhZk/o9CBOoHSZFumyONlzcpYt/EbQeqB3QpN 6+DOF2sKBGlm4EY42ynZmqYJY84MPsE5ewPZmpAF4Sm9rAdZpAd82as5+urURCjyho1K EkJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:autocrypt:message-id :date:user-agent:mime-version:in-reply-to; bh=7osWCWNb8K+14NXV/kaHB64AxuR7v4vfSX68yqI4Xt4=; b=IoBR7FkM1nKuYANFcIlI8p0FOYIcRAOb4EZL6xXp20FJa1hvrrrj7nxgfmjQNGMKnX 9dgWdXozoWxu2WWbSsBUSHn5BTGUS/pMhNsE1Bh7ubkfSQdQmB4CZfscoaulPGOmFrg0 1H/0N8zJeswZnVorVNs6hcwDnJ+XhTPS4B5r3ouCfHehb6CWNkkVDYOCywJY4bp2vJlK pqXAiR7E932H+n9Ac6o6QKk2SpbCgUGhgma3zA5riBRyVlwn4AxPGYO7sO8lZJPBPGR7 hk8VN93BEmzsvCuH0Ns4ZZGgW/6+H6VbRF9CPKfartKlXOsaKrY1MzlQjxW69RJvj+/M Bpsw== X-Gm-Message-State: APjAAAXEFuJEGNNYDfYaTFpXfje3WcP+9p8qi68VdbtQCL4b9tus2dUm 48v0bsIm845eGmMbFzDfkEPiWfrp X-Google-Smtp-Source: APXvYqzj4qDilDBVg1fuTZZYrRZHxSVkKULGBhpL1N2MsPOciY/YpRvv52Jq/8TB5OyoWYvVP1wpzQ== X-Received: by 2002:a7b:c932:: with SMTP id h18mr1376423wml.171.1580337502221; Wed, 29 Jan 2020 14:38:22 -0800 (PST) Received: from [192.168.43.140] ([109.126.145.157]) by smtp.gmail.com with ESMTPSA id c9sm3885484wmc.47.2020.01.29.14.38.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2020 14:38:21 -0800 (PST) Subject: Re: [PATCH] io_uring: fix linked command file table usage To: Jens Axboe , io-uring References: From: Pavel Begunkov Autocrypt: addr=asml.silence@gmail.com; prefer-encrypt=mutual; keydata= mQINBFmKBOQBEAC76ZFxLAKpDw0bKQ8CEiYJRGn8MHTUhURL02/7n1t0HkKQx2K1fCXClbps bdwSHrhOWdW61pmfMbDYbTj6ZvGRvhoLWfGkzujB2wjNcbNTXIoOzJEGISHaPf6E2IQx1ik9 6uqVkK1OMb7qRvKH0i7HYP4WJzYbEWVyLiAxUj611mC9tgd73oqZ2pLYzGTqF2j6a/obaqha +hXuWTvpDQXqcOZJXIW43atprH03G1tQs7VwR21Q1eq6Yvy2ESLdc38EqCszBfQRMmKy+cfp W3U9Mb1w0L680pXrONcnlDBCN7/sghGeMHjGKfNANjPc+0hzz3rApPxpoE7HC1uRiwC4et83 CKnncH1l7zgeBT9Oa3qEiBlaa1ZCBqrA4dY+z5fWJYjMpwI1SNp37RtF8fKXbKQg+JuUjAa9 Y6oXeyEvDHMyJYMcinl6xCqCBAXPHnHmawkMMgjr3BBRzODmMr+CPVvnYe7BFYfoajzqzq+h EyXSl3aBf0IDPTqSUrhbmjj5OEOYgRW5p+mdYtY1cXeK8copmd+fd/eTkghok5li58AojCba jRjp7zVOLOjDlpxxiKhuFmpV4yWNh5JJaTbwCRSd04sCcDNlJj+TehTr+o1QiORzc2t+N5iJ NbILft19Izdn8U39T5oWiynqa1qCLgbuFtnYx1HlUq/HvAm+kwARAQABtDFQYXZlbCBCZWd1 bmtvdiAoc2lsZW5jZSkgPGFzbWwuc2lsZW5jZUBnbWFpbC5jb20+iQJOBBMBCAA4FiEE+6Ju PTjTbx479o3OWt5b1Glr+6UFAlmKBOQCGwMFCwkIBw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aPrK+Cp+kU1HRactyNtF8jZQbhMCC8vMGukZtWaAwpjWiiH bA== Message-ID: <4a826524-4f77-2126-03e9-802c3567f73f@gmail.com> Date: Thu, 30 Jan 2020 01:37:26 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2NEQ6h4YR7dyXV94aDexQrxNEDOiOkDi5" Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --2NEQ6h4YR7dyXV94aDexQrxNEDOiOkDi5 Content-Type: multipart/mixed; boundary="x9Y4zqy8M8C6VAzORlNj3YInhgetomCp5"; protected-headers="v1" From: Pavel Begunkov To: Jens Axboe , io-uring Message-ID: <4a826524-4f77-2126-03e9-802c3567f73f@gmail.com> Subject: Re: [PATCH] io_uring: fix linked command file table usage References: In-Reply-To: --x9Y4zqy8M8C6VAzORlNj3YInhgetomCp5 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable FYI, for-next fs/io_uring.c: In function =E2=80=98io_epoll_ctl=E2=80=99: fs/io_uring.c:2661:22: error: =E2=80=98IO_WQ_WORK_NEEDS_FILES=E2=80=99 un= declared (first use in this function) 2661 | req->work.flags |=3D IO_WQ_WORK_NEEDS_FILES; | ^~~~~~~~~~~~~~~~~~~~~~ fs/io_uring.c:2661:22: note: each undeclared identifier is reported only = once for each function it appears in make[1]: *** [scripts/Makefile.build:266: fs/io_uring.o] Error 1 make: *** [Makefile:1693: fs] Error 2 On 29/01/2020 23:49, Jens Axboe wrote: > We're not consistent in how the file table is grabbed and assigned if w= e > have a command linked that requires the use of it. >=20 > Add ->file_table to the io_op_defs[] array, and use that to determine > when to grab the table instead of having the handlers set it if they > need to defer. This also means we can kill the IO_WQ_WORK_NEEDS_FILES > flag. We always initialize work->files, so io-wq can just check for > that. >=20 > Signed-off-by: Jens Axboe >=20 > --- >=20 > diff --git a/fs/io-wq.c b/fs/io-wq.c > index f7eb577ccd2d..cb60a42b9fdf 100644 > --- a/fs/io-wq.c > +++ b/fs/io-wq.c > @@ -476,8 +476,7 @@ static void io_worker_handle_work(struct io_worker = *worker) > if (work->flags & IO_WQ_WORK_CB) > work->func(&work); > =20 > - if ((work->flags & IO_WQ_WORK_NEEDS_FILES) && > - current->files !=3D work->files) { > + if (work->files && current->files !=3D work->files) { > task_lock(current); > current->files =3D work->files; > task_unlock(current); > diff --git a/fs/io-wq.h b/fs/io-wq.h > index c42602c58c56..50b3378febf2 100644 > --- a/fs/io-wq.h > +++ b/fs/io-wq.h > @@ -7,7 +7,6 @@ enum { > IO_WQ_WORK_CANCEL =3D 1, > IO_WQ_WORK_HAS_MM =3D 2, > IO_WQ_WORK_HASHED =3D 4, > - IO_WQ_WORK_NEEDS_FILES =3D 16, > IO_WQ_WORK_UNBOUND =3D 32, > IO_WQ_WORK_INTERNAL =3D 64, > IO_WQ_WORK_CB =3D 128, > diff --git a/fs/io_uring.c b/fs/io_uring.c > index 8bcf0538e2e1..0d8d0e217847 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -603,6 +603,8 @@ struct io_op_def { > unsigned unbound_nonreg_file : 1; > /* opcode is not supported by this kernel */ > unsigned not_supported : 1; > + /* needs file table */ > + unsigned file_table : 1; > }; > =20 > static const struct io_op_def io_op_defs[] =3D { > @@ -661,6 +663,7 @@ static const struct io_op_def io_op_defs[] =3D { > .needs_mm =3D 1, > .needs_file =3D 1, > .unbound_nonreg_file =3D 1, > + .file_table =3D 1, > }, > [IORING_OP_ASYNC_CANCEL] =3D {}, > [IORING_OP_LINK_TIMEOUT] =3D { > @@ -679,12 +682,15 @@ static const struct io_op_def io_op_defs[] =3D { > [IORING_OP_OPENAT] =3D { > .needs_file =3D 1, > .fd_non_neg =3D 1, > + .file_table =3D 1, > }, > [IORING_OP_CLOSE] =3D { > .needs_file =3D 1, > + .file_table =3D 1, > }, > [IORING_OP_FILES_UPDATE] =3D { > .needs_mm =3D 1, > + .file_table =3D 1, > }, > [IORING_OP_STATX] =3D { > .needs_mm =3D 1, > @@ -720,6 +726,7 @@ static const struct io_op_def io_op_defs[] =3D { > [IORING_OP_OPENAT2] =3D { > .needs_file =3D 1, > .fd_non_neg =3D 1, > + .file_table =3D 1, > }, > }; > =20 > @@ -732,6 +739,7 @@ static void io_queue_linked_timeout(struct io_kiocb= *req); > static int __io_sqe_files_update(struct io_ring_ctx *ctx, > struct io_uring_files_update *ip, > unsigned nr_args); > +static int io_grab_files(struct io_kiocb *req); > =20 > static struct kmem_cache *req_cachep; > =20 > @@ -2568,10 +2576,8 @@ static int io_openat2(struct io_kiocb *req, stru= ct io_kiocb **nxt, > struct file *file; > int ret; > =20 > - if (force_nonblock) { > - req->work.flags |=3D IO_WQ_WORK_NEEDS_FILES; > + if (force_nonblock) > return -EAGAIN; > - } > =20 > ret =3D build_open_flags(&req->open.how, &op); > if (ret) > @@ -2797,10 +2803,8 @@ static int io_close(struct io_kiocb *req, struct= io_kiocb **nxt, > return ret; > =20 > /* if the file has a flush method, be safe and punt to async */ > - if (req->close.put_file->f_op->flush && !io_wq_current_is_worker()) {= > - req->work.flags |=3D IO_WQ_WORK_NEEDS_FILES; > + if (req->close.put_file->f_op->flush && !io_wq_current_is_worker()) > goto eagain; > - } > =20 > /* > * No ->flush(), safely close from here and just punt the > @@ -3244,7 +3248,6 @@ static int io_accept(struct io_kiocb *req, struct= io_kiocb **nxt, > ret =3D __io_accept(req, nxt, force_nonblock); > if (ret =3D=3D -EAGAIN && force_nonblock) { > req->work.func =3D io_accept_finish; > - req->work.flags |=3D IO_WQ_WORK_NEEDS_FILES; > io_put_req(req); > return -EAGAIN; > } > @@ -3967,10 +3970,8 @@ static int io_files_update(struct io_kiocb *req,= bool force_nonblock) > struct io_uring_files_update up; > int ret; > =20 > - if (force_nonblock) { > - req->work.flags |=3D IO_WQ_WORK_NEEDS_FILES; > + if (force_nonblock) > return -EAGAIN; > - } > =20 > up.offset =3D req->files_update.offset; > up.fds =3D req->files_update.arg; > @@ -3991,6 +3992,12 @@ static int io_req_defer_prep(struct io_kiocb *re= q, > { > ssize_t ret =3D 0; > =20 > + if (io_op_defs[req->opcode].file_table) { > + ret =3D io_grab_files(req); > + if (unlikely(ret)) > + return ret; > + } > + > io_req_work_grab_env(req, &io_op_defs[req->opcode]); > =20 > switch (req->opcode) { > @@ -4424,6 +4431,8 @@ static int io_grab_files(struct io_kiocb *req) > int ret =3D -EBADF; > struct io_ring_ctx *ctx =3D req->ctx; > =20 > + if (req->work.files) > + return 0; > if (!ctx->ring_file) > return -EBADF; > =20 > @@ -4542,7 +4551,7 @@ static void __io_queue_sqe(struct io_kiocb *req, = const struct io_uring_sqe *sqe) > if (ret =3D=3D -EAGAIN && (!(req->flags & REQ_F_NOWAIT) || > (req->flags & REQ_F_MUST_PUNT))) { > punt: > - if (req->work.flags & IO_WQ_WORK_NEEDS_FILES) { > + if (io_op_defs[req->opcode].file_table) { > ret =3D io_grab_files(req); > if (ret) > goto err; >=20 --=20 Pavel Begunkov --x9Y4zqy8M8C6VAzORlNj3YInhgetomCp5-- --2NEQ6h4YR7dyXV94aDexQrxNEDOiOkDi5 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE+6JuPTjTbx479o3OWt5b1Glr+6UFAl4yCTkACgkQWt5b1Glr +6WvJQ/8DgAlwlf519Q8u5/MkHTFchPJKzZWK30NYxbdSo6VDX1wZ4nEzBWkJ1Vj /OTrYOpfGV+jp33rrf9JhSuzM2LMe4gA6+7kEguYT/DGaLYsErx26+Cc8ksos5xJ iwgef4yLaHSif5FwDUPYsKNN3W8ATPn8jujRYc/L7BJ8g4r182Y8kyBmSGwarLB5 Iw0YvuVSkLbOqumSuznytlmhFz1U2eWAVrEaC4GWKWyQ3FYK1M+Ed6M5aH67PMir LWVuKffe6yC0AfidrVcCxZ+spJp/PyQYDCmcKYMka5+PzaW5enPszR55Daw0lhFr KDpXO09RepphzhEZMcvbNAUZnn0tD+FVGFNp0YK41we65m6yxvTdEbsbyKGGyeUu 2SFhk/fcKXVFfXE+J+LWuTweIP6s0PFl5hmIAGi45seJ+KIFXWzKA0YLERpwSIbY LrJUhwR3qIsmesYqQlVY0aUqpfVxTDfmAflEbn9qhBleToAd8tZi4tmeUYiDyV5Q TRmGKY40RewnRECCGep57va0gjOFwexdUiU+7pNG9oT/OWrQWA+cwJLWcvsQKplA KBtzeZsiDFj0JcZC1R4GcZLMcJoOqzuI8LL7vRjYmTdL+MaPmm4yz3rsPGWqTWcn FmlQLhJ1XF2QwY5gtO39gXwHUoAIv2Yref92k5AEi2TWg6coZAc= =xoZz -----END PGP SIGNATURE----- --2NEQ6h4YR7dyXV94aDexQrxNEDOiOkDi5--