From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zeniv.linux.org.uk ([195.92.253.2]:53168 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751191AbeC2WfG (ORCPT ); Thu, 29 Mar 2018 18:35:06 -0400 Date: Thu, 29 Mar 2018 23:35:00 +0100 From: Al Viro To: Christoph Hellwig Cc: Avi Kivity , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 07/30] aio: add delayed cancel support Message-ID: <20180329223500.GY30522@ZenIV.linux.org.uk> References: <20180329203328.3248-1-hch@lst.de> <20180329203328.3248-8-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180329203328.3248-8-hch@lst.de> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Thu, Mar 29, 2018 at 10:33:05PM +0200, Christoph Hellwig wrote: > The upcoming aio poll support would like to be able to complete the > iocb inline from the cancellation context, but that would cause a > double lock of ctx_lock with the current locking scheme. Move the > cancelation outside the context lock to avoid this reversal, which > suits the existing usb gadgets users just fine as well (in fact > both unconditionally disable irqs and thus seem broken without > this change). > > To make this safe aio_complete needs to check if this call should > complete the iocb. If it didn't the callers must not release any > other resources. Uh-oh... What happens to existing users of kiocb_set_cancel_fn() now? AFAICS, those guys will *not* get aio_kiocb freed at all in case of io_cancel(2). Look: we mark them with AIO_IOCB_CANCELLED and call whatever ->ki_cancel() the driver has set. Later the damn thing calls ->ki_complete() (i.e. aio_complete_rw()), which calls aio_complete(iocb, res, res2, 0) and gets false. Nothing's freed, struct file is leaked. Frankly, the more I look at that, the less I like what you've done with ->ki_cancel() overloading. In regular case it's just accelerating the call of ->ki_complete(), which will do freeing. Here you have ->ki_cancel() free the damn thing, with the resulting need to play silly buggers with locking, freeing logics in aio_complete(), etc.