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=-10.4 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,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 B8D0AC4363A for ; Fri, 23 Oct 2020 03:34:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A69F21D43 for ; Fri, 23 Oct 2020 03:34:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S369330AbgJWDeh (ORCPT ); Thu, 22 Oct 2020 23:34:37 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:56351 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S368871AbgJWDeg (ORCPT ); Thu, 22 Oct 2020 23:34:36 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=xiaoguang.wang@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0UCthlsO_1603424074; Received: from 30.225.32.192(mailfrom:xiaoguang.wang@linux.alibaba.com fp:SMTPD_---0UCthlsO_1603424074) by smtp.aliyun-inc.com(127.0.0.1); Fri, 23 Oct 2020 11:34:35 +0800 Subject: Re: [PATCH for-5.10] io_uring: remove req cancel in ->flush() To: Pavel Begunkov , Jens Axboe , io-uring@vger.kernel.org References: <21aca47e03c82a06e4ea1140b328a86d04d1f422.1603122023.git.asml.silence@gmail.com> <13c73e10-040f-9a0b-5396-b3f2a0c301b0@linux.alibaba.com> <97c154a6-1020-d5b0-7ff4-9777b6df13c7@gmail.com> From: Xiaoguang Wang Message-ID: <18fecee1-05a4-ca49-0530-73790f584d7e@linux.alibaba.com> Date: Fri, 23 Oct 2020 11:33:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <97c154a6-1020-d5b0-7ff4-9777b6df13c7@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org hi, > On 22/10/2020 07:42, Xiaoguang Wang wrote: >>> Every close(io_uring) causes cancellation of all inflight requests >>> carrying ->files. That's not nice but was neccessary up until recently. >>> Now task->files removal is handled in the core code, so that part of >>> flush can be removed. >> I don't catch up with newest io_uring codes yet, but have one question about >> the initial implementation "io_uring: io_uring: add support for async work >> inheriting files": https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fcb323cc53e29d9cc696d606bb42736b32dd9825 >> There was such comments: >> +static int io_grab_files(struct io_ring_ctx *ctx, struct io_kiocb *req) >> +{ >> +       int ret = -EBADF; >> + >> +       rcu_read_lock(); >> +       spin_lock_irq(&ctx->inflight_lock); >> +       /* >> +        * We use the f_ops->flush() handler to ensure that we can flush >> +        * out work accessing these files if the fd is closed. Check if >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> I wonder why we only need to flush reqs specifically when they access current->files, are there >> any special reasons? > We could have taken a reference to ->files, so it doesn't get freed > while a request is using it, but that creates a circular dependency. > > IIUC, because if there are ->files refs io_uring won't be closed on exit, > but io_uring would be holding ->files refs. > > So, it was working without taking ->files references (i.e. weak refs) > on the basis that the files won't be destroyed until the task itself is > gone, and we can *kind of* intercept when task is exiting by ->flush() > and cancel all requests with ->files there. Now I see :) will help me to understand current codes better. Really thanks for your explanations. Regards, Xiaoguang Wang >