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=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,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 56852C433B4 for ; Tue, 13 Apr 2021 17:19:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E08B613B7 for ; Tue, 13 Apr 2021 17:19:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345759AbhDMRUA (ORCPT ); Tue, 13 Apr 2021 13:20:00 -0400 Received: from mail-wr1-f49.google.com ([209.85.221.49]:33741 "EHLO mail-wr1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345795AbhDMRT7 (ORCPT ); Tue, 13 Apr 2021 13:19:59 -0400 Received: by mail-wr1-f49.google.com with SMTP id g9so1185192wrx.0 for ; Tue, 13 Apr 2021 10:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:references:autocrypt:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=c+AO+pcruZ6JJv6DIPkzWdMEnGNAXxD18jdmuzOFbKY=; b=WhGCe2XYUntz2qeoNZJ5+lCtaofgXQQucSX/pd5Bj0gkBGu/JJROyUXHqS1mKV7JyA 5PJlH+UcSv9G2M9XX027srMRoSSYDTsyJZN1j2K05queTGK00QLqfYNk08LAZ5bJ/Mk/ gxSuk6rj6bZxSw9g9dvTQPkZ4EIRCiH/htIVagfwHGm+ecY3WUPIPmJFu+JJlzvIZXzR MSpYWBBrx4owNGgtqOWbTIxjlIDBDNf39y7EpOWbQpqxkx2Ym2SV3uuu4tHhRsBQxNfE hPTyq3iBjEyQ1M5kplgQeDm7EP4lSXe54NyZ8PV1Cy/LUK8BxCDIwXOCuzb2qRpoh9w9 uXPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:references:autocrypt:subject:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=c+AO+pcruZ6JJv6DIPkzWdMEnGNAXxD18jdmuzOFbKY=; b=niYblLkcYpKt8iW/TNp9kks1XKjUG5OdNW7JaBnHskBAbsvzSTS80d6tXhAIZux8gh +66NwxkYd9s6ZTGBbfd+erDgLI5FYKwGR7ZTiqCCme4mr8Vdxktqy9PfKUz2KNjeATHr V8O/BXAQWTeCTsH6cVO7crZ2mjWOamU7UNATKCGntZqmiuw4Yb/aTExfXg899iR4FO/S 2mjs1iaG8jcLNjPtiOB9dn1X7iHe9+b6qBRzQE2tWDzlZGu/5sVxM3AuYc0dgZrsDM47 fpkNxNQ7gDMbOp4AtrKcai58zOD7FcNa25/NyM8S1yPnztWkVZ6zgUtFYgJnUj100BPf K8gQ== X-Gm-Message-State: AOAM53105cUOG5fqpT3qHI134yiDsXLbNE9rWlW3vBti76BS4Oewkbe4 w/t4hz6ujHDkjMqBKFFwAHTgoqD9G8FC9Q== X-Google-Smtp-Source: ABdhPJwyYWhJX1Vj8hfZTQmPAfmQnz8Zh05TKO1Kw4i9In4uzHYHGE3B4LNvuRMJw40wCxsjC9vOdA== X-Received: by 2002:adf:f308:: with SMTP id i8mr18580630wro.209.1618334318816; Tue, 13 Apr 2021 10:18:38 -0700 (PDT) Received: from [192.168.8.181] ([148.252.128.208]) by smtp.gmail.com with ESMTPSA id b15sm20998531wrx.73.2021.04.13.10.18.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Apr 2021 10:18:38 -0700 (PDT) From: Pavel Begunkov To: Jens Axboe , io-uring@vger.kernel.org References: 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+6UFAlmKBOQCGwMFCwkIBwIGFQgJCgsCBBYCAwECH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F8jZQbhMCC8vMGukZtWaAwpjWiiH bA== Subject: Re: [PATCH 3/9] io_uring: split poll and poll update structures Message-ID: Date: Tue, 13 Apr 2021 18:14:28 +0100 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: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On 13/04/2021 02:58, Pavel Begunkov wrote: > struct io_poll_iocb became pretty nasty combining also update fields. > Split them, so we would have more clarity to it. I think we should move update into IORING_OP_POLL_REMOVE until it's not too late. Would have better struct layouts and didn't get in way of POLL_ADD, which should be more popular. Another thing, looks IORING_OP_POLL_REMOVE may cancel apoll, that doesn't sound great. IMHO we need to limit it to only poll requests, rather confusing otherwise. note: it can't be used reliably from the userspace, so we may probably not care about change in behaviour > > Signed-off-by: Pavel Begunkov > --- > fs/io_uring.c | 55 ++++++++++++++++++++++++++++++--------------------- > 1 file changed, 32 insertions(+), 23 deletions(-) > > diff --git a/fs/io_uring.c b/fs/io_uring.c > index 429ee5fd9044..a0f207e62e32 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -490,15 +490,16 @@ struct io_poll_iocb { > __poll_t events; > bool done; > bool canceled; > + struct wait_queue_entry wait; > +}; > + > +struct io_poll_update { > + struct file *file; > + u64 old_user_data; > + u64 new_user_data; > + __poll_t events; > bool update_events; > bool update_user_data; > - union { > - struct wait_queue_entry wait; > - struct { > - u64 old_user_data; > - u64 new_user_data; > - }; > - }; > }; > > struct io_poll_remove { > @@ -715,6 +716,7 @@ enum { > REQ_F_COMPLETE_INLINE_BIT, > REQ_F_REISSUE_BIT, > REQ_F_DONT_REISSUE_BIT, > + REQ_F_POLL_UPDATE_BIT, > /* keep async read/write and isreg together and in order */ > REQ_F_ASYNC_READ_BIT, > REQ_F_ASYNC_WRITE_BIT, > @@ -762,6 +764,8 @@ enum { > REQ_F_REISSUE = BIT(REQ_F_REISSUE_BIT), > /* don't attempt request reissue, see io_rw_reissue() */ > REQ_F_DONT_REISSUE = BIT(REQ_F_DONT_REISSUE_BIT), > + /* switches between poll and poll update */ > + REQ_F_POLL_UPDATE = BIT(REQ_F_POLL_UPDATE_BIT), > /* supports async reads */ > REQ_F_ASYNC_READ = BIT(REQ_F_ASYNC_READ_BIT), > /* supports async writes */ > @@ -791,6 +795,7 @@ struct io_kiocb { > struct file *file; > struct io_rw rw; > struct io_poll_iocb poll; > + struct io_poll_update poll_update; > struct io_poll_remove poll_remove; > struct io_accept accept; > struct io_sync sync; > @@ -4989,7 +4994,6 @@ static void io_init_poll_iocb(struct io_poll_iocb *poll, __poll_t events, > poll->head = NULL; > poll->done = false; > poll->canceled = false; > - poll->update_events = poll->update_user_data = false; > #define IO_POLL_UNMASK (EPOLLERR|EPOLLHUP|EPOLLNVAL|EPOLLRDHUP) > /* mask in events that we always want/need */ > poll->events = events | IO_POLL_UNMASK; > @@ -5366,7 +5370,6 @@ static void io_poll_queue_proc(struct file *file, struct wait_queue_head *head, > > static int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) > { > - struct io_poll_iocb *poll = &req->poll; > u32 events, flags; > > if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) > @@ -5383,20 +5386,26 @@ static int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe > #endif > if (!(flags & IORING_POLL_ADD_MULTI)) > events |= EPOLLONESHOT; > - poll->update_events = poll->update_user_data = false; > + events = demangle_poll(events) | > + (events & (EPOLLEXCLUSIVE|EPOLLONESHOT)); > > if (flags & (IORING_POLL_UPDATE_EVENTS|IORING_POLL_UPDATE_USER_DATA)) { > - poll->old_user_data = READ_ONCE(sqe->addr); > - poll->update_events = flags & IORING_POLL_UPDATE_EVENTS; > - poll->update_user_data = flags & IORING_POLL_UPDATE_USER_DATA; > - if (poll->update_user_data) > - poll->new_user_data = READ_ONCE(sqe->off); > + struct io_poll_update *poll_upd = &req->poll_update; > + > + req->flags |= REQ_F_POLL_UPDATE; > + poll_upd->events = events; > + poll_upd->old_user_data = READ_ONCE(sqe->addr); > + poll_upd->update_events = flags & IORING_POLL_UPDATE_EVENTS; > + poll_upd->update_user_data = flags & IORING_POLL_UPDATE_USER_DATA; > + if (poll_upd->update_user_data) > + poll_upd->new_user_data = READ_ONCE(sqe->off); > } else { > + struct io_poll_iocb *poll = &req->poll; > + > + poll->events = events; > if (sqe->off || sqe->addr) > return -EINVAL; > } > - poll->events = demangle_poll(events) | > - (events & (EPOLLEXCLUSIVE|EPOLLONESHOT)); > return 0; > } > > @@ -5434,7 +5443,7 @@ static int io_poll_update(struct io_kiocb *req) > int ret; > > spin_lock_irq(&ctx->completion_lock); > - preq = io_poll_find(ctx, req->poll.old_user_data); > + preq = io_poll_find(ctx, req->poll_update.old_user_data); > if (!preq) { > ret = -ENOENT; > goto err; > @@ -5464,13 +5473,13 @@ static int io_poll_update(struct io_kiocb *req) > return 0; > } > /* only mask one event flags, keep behavior flags */ > - if (req->poll.update_events) { > + if (req->poll_update.update_events) { > preq->poll.events &= ~0xffff; > - preq->poll.events |= req->poll.events & 0xffff; > + preq->poll.events |= req->poll_update.events & 0xffff; > preq->poll.events |= IO_POLL_UNMASK; > } > - if (req->poll.update_user_data) > - preq->user_data = req->poll.new_user_data; > + if (req->poll_update.update_user_data) > + preq->user_data = req->poll_update.new_user_data; > > spin_unlock_irq(&ctx->completion_lock); > > @@ -5489,7 +5498,7 @@ static int io_poll_update(struct io_kiocb *req) > > static int io_poll_add(struct io_kiocb *req, unsigned int issue_flags) > { > - if (!req->poll.update_events && !req->poll.update_user_data) > + if (!(req->flags & REQ_F_POLL_UPDATE)) > return __io_poll_add(req); > return io_poll_update(req); > } > -- Pavel Begunkov