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=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=no 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 B2E16C433E0 for ; Wed, 24 Feb 2021 02:33:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6ED7664EC3 for ; Wed, 24 Feb 2021 02:33:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232397AbhBXCdw (ORCPT ); Tue, 23 Feb 2021 21:33:52 -0500 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:51400 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232278AbhBXCdu (ORCPT ); Tue, 23 Feb 2021 21:33:50 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=xiaoguang.wang@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0UPPA0Bp_1614133985; Received: from 30.225.32.114(mailfrom:xiaoguang.wang@linux.alibaba.com fp:SMTPD_---0UPPA0Bp_1614133985) by smtp.aliyun-inc.com(127.0.0.1); Wed, 24 Feb 2021 10:33:05 +0800 Subject: Re: [PATCH] io_uring: don't issue reqs in iopoll mode when ctx is dying To: Pavel Begunkov , io-uring@vger.kernel.org Cc: axboe@kernel.dk, joseph.qi@linux.alibaba.com References: <20210206150006.1945-1-xiaoguang.wang@linux.alibaba.com> <3e3cb8da-d925-7ebd-11a0-f9e145861962@linux.alibaba.com> From: Xiaoguang Wang Message-ID: <754563ed-5b2b-075d-16f8-d980e51102e6@linux.alibaba.com> Date: Wed, 24 Feb 2021 10:30:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: 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 Pavel, > On 08/02/2021 13:35, Pavel Begunkov wrote: >> On 08/02/2021 02:50, Xiaoguang Wang wrote: >>>>> The io_identity's count is underflowed. It's because in io_put_identity, >>>>> first argument tctx comes from req->task->io_uring, the second argument >>>>> comes from the task context that calls io_req_init_async, so the compare >>>>> in io_put_identity maybe meaningless. See below case: >>>>>      task context A issue one polled req, then req->task = A. >>>>>      task context B do iopoll, above req returns with EAGAIN error. >>>>>      task context B re-issue req, call io_queue_async_work for req. >>>>>      req->task->io_uring will set to task context B's identity, or cow new one. >>>>> then for above case, in io_put_identity(), the compare is meaningless. >>>>> >>>>> IIUC, req->task should indicates the initial task context that issues req, >>>>> then if it gets EAGAIN error, we'll call io_prep_async_work() in req->task >>>>> context, but iopoll reqs seems special, they maybe issued successfully and >>>>> got re-issued in other task context because of EAGAIN error. >>>> >>>> Looks as you say, but the patch doesn't solve the issue completely. >>>> 1. We must not do io_queue_async_work() under a different task context, >>>> because of it potentially uses a different set of resources. So, I just >>>> thought that it would be better to punt it to the right task context >>>> via task_work. But... >>>> >>>> 2. ...iovec import from io_resubmit_prep() might happen after submit ends, >>>> i.e. when iovec was freed in userspace. And that's not great at all. >>> Yes, agree, that's why I say we neeed to re-consider the io identity codes >>> more in commit message :) I'll have a try to prepare a better one. >> >> I'd vote for dragging -AGAIN'ed reqs that don't need io_import_iovec() >> through task_work for resubmission, and fail everything else. Not great, >> but imho better than always setting async_data. > > Hey Xiaoguang, are you working on this? I would like to leave it to you, > If you do. Sorry, currently I'm busy with other project and don't have much time to work on it yet. Hao Xu will help to continue work on the new version patch. Regards, Xiaoguang Wang >