Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2367012imc; Tue, 12 Mar 2019 12:18:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8+I75U8bw3g7KcH72rOvnj5wJ+Q7wR4h+mPXfmw6KXRvrYNDpjzAG3N812rM7i+vxj9dU X-Received: by 2002:a62:5543:: with SMTP id j64mr40201758pfb.105.1552418325364; Tue, 12 Mar 2019 12:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552418325; cv=none; d=google.com; s=arc-20160816; b=dxE/qI3seqC0G8fTpBf/HbKmRG0bvqihpK67kCpmq/T7Exwgli437EmSa17SLPYiLO Pb6Mebfq4kVX/SkAZl8Ek+gC1AdwayqAVF+2zOiPJ1S/d7Pi1DzxxXbz1WhgnkLYJg5o ArbMKyo4iQ1S2lhgRQlXgohG8v4+Hw+taazTWMMNwTtAOs8itTyy40t56TMaduJPlCZd Z0pWaok+65dNtuJqh3f2CMkbhld6PVl9JtcJCkiXmZ01d3IpZew03jkE10Y6ElFbZdnO nU7a42X6i1FwWmW/ELC4KtyExsbtgT28NNq/YelR2GqKrdyhQF8gV/8bL2ee8FIgHVZl 2evg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=BbKPZIpUjkagL/JnlvaHjroWbG67wR/MBNOuClXvYhU=; b=eRbMc0Px1x2UT0+hnlmkUycf2LCbqx9tNFCfG3wOuw2FguN3f0aGZ7LKl1E9tSEw0X Q7qYxUA7FU8Q/KR5MxH/rCz7qjCBvwbFw0O97vwNeC1XOoutHBrFsQu4xUc8Is0/JKg3 huBo16yTE9Vt1dwqpTbviuldjR/TfgvFH6GSJY6ZZav8pCaFaY9bUQ6T2bHR6H9OH08+ 7cPRQQoEGOGwvvWTf8gN2t6jD0dp4vRiHgzXNGrLbjG98hE8ARqhnrUeNoUDBTph5a6j /7aMSIZyciVTFBAj6bllTc0EojfLXQcdTRqxE1go/5wtjnQ8eQLR050qd/CSdujq7gKr 81Vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si2663984pfc.238.2019.03.12.12.18.28; Tue, 12 Mar 2019 12:18:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727247AbfCLTSJ (ORCPT + 99 others); Tue, 12 Mar 2019 15:18:09 -0400 Received: from verein.lst.de ([213.95.11.211]:48500 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726501AbfCLTSJ (ORCPT ); Tue, 12 Mar 2019 15:18:09 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id 9AED568C4E; Tue, 12 Mar 2019 20:18:01 +0100 (CET) Date: Tue, 12 Mar 2019 20:18:01 +0100 From: Christoph Hellwig To: Al Viro Cc: Christoph Hellwig , Linus Torvalds , Eric Dumazet , David Miller , Jason Baron , kgraul@linux.ibm.com, ktkhai@virtuozzo.com, kyeongdon.kim@lge.com, Linux List Kernel Mailing , Netdev , pabeni@redhat.com, syzkaller-bugs@googlegroups.com, xiyou.wangcong@gmail.com, zhengbin , bcrl@kvack.org, linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, houtao1@huawei.com, yi.zhang@huawei.com Subject: Re: [PATCH 4/8] Fix aio_poll() races Message-ID: <20190312191801.GA5236@lst.de> References: <20190310070606.GA10138@ZenIV.linux.org.uk> <20190310070822.11564-1-viro@ZenIV.linux.org.uk> <20190310070822.11564-4-viro@ZenIV.linux.org.uk> <20190311195831.GA12807@lst.de> <20190311210618.GL2217@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190311210618.GL2217@ZenIV.linux.org.uk> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 11, 2019 at 09:06:18PM +0000, Al Viro wrote: > On Mon, Mar 11, 2019 at 08:58:31PM +0100, Christoph Hellwig wrote: > > Where do we put the second iocb reference in case we return from > > vfs_poll without ever being woken? > > Depends. If mask is non-zero (i.e. vfs_poll() has returned something > we care about) and it has never been woken, we steal it and drop the > reference ourselves. If it is zero and we see that ->poll() has tried > to put it on two queues, we steal it (again, assuming it's not on > waitqueue and _can_ be stolen) and return -EINVAL. In that case > __io_submit_one() (or, by the end of the series, io_submit_one()) > will call iocb_destroy(). And in the normal waiting case (nothing > interesting reported and no errors) it will end up on the list of > cancellables. Then it either will get completed by later wakeup, which > will drop the reference, or it will get eventually cancelled, which will > hit the same aio_poll_complete_work() and drop the reference... Ok, seems like the logic is sane. I was missing how the actual mask logic worked in aio_poll(). > > Also it seems like the complete code would still benefit from a little > > helper, something like: > > Umm... Not sure I like the name (something like aio_poll_done() seems > to be better), but other than that - no problem. I don't care about the name. Feel free to change it to whatever suits you.