From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail143.messagelabs.com (mail143.messagelabs.com [216.82.254.35]) by kanga.kvack.org (Postfix) with ESMTP id 346186B0069 for ; Fri, 18 Nov 2011 09:16:05 -0500 (EST) Received: by yenm10 with SMTP id m10so3290322yen.14 for ; Fri, 18 Nov 2011 06:16:03 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 18 Nov 2011 15:16:02 +0100 Message-ID: Subject: Re: [PATCH] hugetlb: detect race if fail to COW From: John Kacur Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org List-ID: To: Hillf Danton Cc: Andrea Arcangeli , Andrew Morton , Michal Hocko , Johannes Weiner , linux-mm@kvack.org, LKML On Fri, Nov 18, 2011 at 3:04 PM, Hillf Danton wrote: > In the error path that we fail to allocate new huge page, before try agai= n, we > have to check race since page_table_lock is re-acquired. > > If racing, our job is done. > > Signed-off-by: Hillf Danton > --- > > --- a/mm/hugetlb.c =A0 =A0 =A0Fri Nov 18 21:38:30 2011 > +++ b/mm/hugetlb.c =A0 =A0 =A0Fri Nov 18 21:48:15 2011 > @@ -2407,7 +2407,14 @@ retry_avoidcopy: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0BUG_ON(pag= e_count(old_page) !=3D 1); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0BUG_ON(hug= e_pte_none(pte)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0spin_lock(= &mm->page_table_lock); > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto retry_= avoidcopy; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ptep =3D hu= ge_pte_offset(mm, address & huge_page_mask(h)); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (likely(= pte_same(huge_ptep_get(ptep), pte))) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 goto retry_avoidcopy; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* race o= ccurs while re-acquiring page_table_lock, and > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* our jo= b is done. > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/ > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0WARN_ON_ONCE(1); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} I'm not sure about the veracity of the race condition, but you better do spin_unlock before you return. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: email@kvack.org