From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753942Ab2EBJSl (ORCPT ); Wed, 2 May 2012 05:18:41 -0400 Received: from cantor2.suse.de ([195.135.220.15]:36034 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752889Ab2EBJSj (ORCPT ); Wed, 2 May 2012 05:18:39 -0400 Date: Wed, 2 May 2012 11:18:37 +0200 From: Jan Kara To: Nick Piggin Cc: Jan Kara , Jeff Moyer , KOSAKI Motohiro , Michael Kerrisk , LKML , linux-man@vger.kernel.org, linux-mm@kvack.org, mgorman@suse.de, Andrea Arcangeli , Woodman Subject: Re: [PATCH] Describe race of direct read and fork for unaligned buffers Message-ID: <20120502091837.GC16976@quack.suse.cz> References: <1335778207-6511-1-git-send-email-jack@suse.cz> <20120502081705.GB16976@quack.suse.cz> 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 On Wed 02-05-12 19:09:54, Nick Piggin wrote: > On 2 May 2012 18:17, Jan Kara wrote: > > On Wed 02-05-12 01:50:46, Nick Piggin wrote: > > >> KOSAKI-san is correct, I think. > >> > >> The race is something like this: > >> > >> DIO-read > >>     page = get_user_pages() > >>                                                         fork() > >>                                                             COW(page) > >>                                                          touch(page) > >>     DMA(page) > >>     page_cache_release(page); > >> > >> So whether parent or child touches the page, determines who gets the > >> actual DMA target, and who gets the copy. > >  OK, this is roughly what I understood from original threads as well. So > > if our buffer is page aligned and its size is page aligned, you would hit > > the corruption only if you do modify the buffer while IO to / from that buffer > > is in progress. And that would seem like a really bad programming practice > > anyway. So I still believe that having everything page size aligned will > > effectively remove the problem although I agree it does not aim at the core > > of it. > > I see what you mean. > > I'm not sure, though. For most apps it's bad practice I think. If you get into > realm of sophisticated, performance critical IO/storage managers, it would > not surprise me if such concurrent buffer modifications could be allowed. > We allow exactly such a thing in our pagecache layer. Although probably > those would be using shared mmaps for their buffer cache. > > I think it is safest to make a default policy of asking for IOs against private > cow-able mappings to be quiesced before fork, so there are no surprises > or reliance on COW details in the mm. Do you think? Yes, I agree that (and MADV_DONTFORK) is probably the best thing to have in documentation. Otherwise it's a bit too hairy... Honza -- Jan Kara SUSE Labs, CR