From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752839Ab1ARTBS (ORCPT ); Tue, 18 Jan 2011 14:01:18 -0500 Received: from cantor.suse.de ([195.135.220.2]:50437 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752297Ab1ARTBR (ORCPT ); Tue, 18 Jan 2011 14:01:17 -0500 Date: Tue, 18 Jan 2011 20:01:14 +0100 From: Jan Kara To: Nick Piggin Cc: Jeff Moyer , Andrew Morton , linux-fsdevel , linux-kernel@vger.kernel.org Subject: Re: [patch] fs: aio fix rcu lookup Message-ID: <20110118190114.GA5070@quack.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue 18-01-11 10:24:24, Nick Piggin wrote: > On Tue, Jan 18, 2011 at 6:07 AM, Jeff Moyer wrote: > > Nick Piggin writes: > >> Do you agree with the theoretical problem? I didn't try to > >> write a racer to break it yet. Inserting a delay before the > >> get_ioctx might do the trick. > > > > I'm not convinced, no.  The last reference to the kioctx is always the > > process, released in the exit_aio path, or via sys_io_destroy.  In both > > cases, we cancel all aios, then wait for them all to complete before > > dropping the final reference to the context. > > That wouldn't appear to prevent a concurrent thread from doing an > io operation that requires ioctx lookup, and taking the last reference > after the io_cancel thread drops the ref. > > > So, while I agree that what you wrote is better, I remain unconvinced of > > it solving a real-world problem.  Feel free to push it in as a cleanup, > > though. > > Well I think it has to be technically correct first. If there is indeed a > guaranteed ref somehow, it just needs a comment. Hmm, the code in io_destroy() indeed looks fishy. We delete the ioctx from the hash table and set ioctx->dead which is supposed to stop lookup_ioctx() from finding it (see the !ctx->dead check in lookup_ioctx()). There's even a comment in io_destroy() saying: /* * Wake up any waiters. The setting of ctx->dead must be seen * by other CPUs at this point. Right now, we rely on the * locking done by the above calls to ensure this consistency. */ But since lookup_ioctx() is called without any lock or barrier nothing really seems to prevent the list traversal and ioctx->dead test to happen before io_destroy() and get_ioctx() after io_destroy(). But wouldn't the right fix be to call synchronize_rcu() in io_destroy()? Because with your fix we could still return 'dead' ioctx and I don't think we are supposed to do that... Honza -- Jan Kara SUSE Labs, CR