From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Piggin Subject: Re: [PATCH] Describe race of direct read and fork for unaligned buffers Date: Wed, 2 May 2012 19:09:54 +1000 Message-ID: References: <1335778207-6511-1-git-send-email-jack@suse.cz> <20120502081705.GB16976@quack.suse.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: <20120502081705.GB16976-+0h/O2h83AeN3ZZ/Hiejyg@public.gmane.org> Sender: linux-man-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Jan Kara Cc: Jeff Moyer , KOSAKI Motohiro , Michael Kerrisk , LKML , linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, mgorman-l3A5Bk7waGM@public.gmane.org, Andrea Arcangeli , Woodman List-Id: linux-man@vger.kernel.org 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 >> =C2=A0 =C2=A0 page =3D get_user_pages() >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fork() >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 C= OW(page) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0touch(pag= e) >> =C2=A0 =C2=A0 DMA(page) >> =C2=A0 =C2=A0 page_cache_release(page); >> >> So whether parent or child touches the page, determines who gets the >> actual DMA target, and who gets the copy. > =C2=A0OK, 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 th= at buffer > is in progress. And that would seem like a really bad programming pra= ctice > anyway. So I still believe that having everything page size aligned w= ill > effectively remove the problem although I agree it does not aim at th= e core > of it. I see what you mean. I'm not sure, though. For most apps it's bad practice I think. If you g= et into realm of sophisticated, performance critical IO/storage managers, it wo= uld not surprise me if such concurrent buffer modifications could be allowe= d. 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? -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html