From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benjamin LaHaise Subject: Re: [PATCH 2/2] aio: fix the confliction of read events and migrating ring page Date: Thu, 20 Mar 2014 12:30:04 -0400 Message-ID: <20140320163004.GE28970@kvack.org> References: <532A80B1.5010002@cn.fujitsu.com> <20140320143207.GA3760@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: Dave Jones , Gu Zheng , Al Viro , jmoyer@redhat.com, kosaki.motohiro@jp.fujitsu.com, KAMEZAWA Hiroyuki , Yasuaki Ishimatsu , tangchen , miaox@cn.fujitsu.com, linux-aio@kvack.org, fsdevel , linux-kernel , Andrew Morton Return-path: Content-Disposition: inline In-Reply-To: <20140320143207.GA3760@redhat.com> Sender: owner-linux-aio@kvack.org List-Id: linux-fsdevel.vger.kernel.org On Thu, Mar 20, 2014 at 10:32:07AM -0400, Dave Jones wrote: > On Thu, Mar 20, 2014 at 01:46:25PM +0800, Gu Zheng wrote: > > > diff --git a/fs/aio.c b/fs/aio.c > > index 88ad40c..e353085 100644 > > --- a/fs/aio.c > > +++ b/fs/aio.c > > @@ -319,6 +319,9 @@ static int aio_migratepage(struct address_space *mapping, struct page *new, > > ctx->ring_pages[old->index] = new; > > spin_unlock_irqrestore(&ctx->completion_lock, flags); > > > > + /* Ensure read event is completed before putting old page */ > > + mutex_lock(&ctx->ring_lock); > > + mutex_unlock(&ctx->ring_lock); > > put_page(old); > > > > return rc; > > This looks a bit weird. Would using a completion work here ? Nope. This is actually the most elegant fix I've seen for this approach, as everything else has relied on adding additional spin locks (which only end up being needed in the migration case) around access to the ring_pages on the reader side. That said, this patch is not a complete solution to the problem, as the update of the ring's head pointer could still get lost with this patch. I think the right thing is just taking the ring_lock mutex over the entire page migration operation. That should be safe, as nowhere else is the ring_lock mutex nested with any other locks. -ben > Dave -- "Thought is the essence of where you are now." -- To unsubscribe, send a message with 'unsubscribe linux-aio' in the body to majordomo@kvack.org. For more info on Linux AIO, see: http://www.kvack.org/aio/ Don't email: aart@kvack.org