From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: Re: [PATCH XEN v8 24/29] tools/libs/call: linux: touch newly allocated pages after madvise lockdown Date: Tue, 19 Jan 2016 15:49:31 +0000 Message-ID: <20160119154931.GL1691@citrix.com> References: <1452864168.32341.97.camel@citrix.com> <1452864188-2417-1-git-send-email-ian.campbell@citrix.com> <1452864188-2417-25-git-send-email-ian.campbell@citrix.com> <20160119132420.GZ1691@citrix.com> <569E4E3E.9060103@citrix.com> <20160119145848.GJ1691@citrix.com> <1453215811.29930.78.camel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline In-Reply-To: <1453215811.29930.78.camel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: ian.jackson@eu.citrix.com, xen-devel@lists.xen.org, Wei Liu , Roger Pau =?iso-8859-1?Q?Monn=E9?= List-Id: xen-devel@lists.xenproject.org On Tue, Jan 19, 2016 at 03:03:31PM +0000, Ian Campbell wrote: > On Tue, 2016-01-19 at 14:58 +0000, Wei Liu wrote: > > On Tue, Jan 19, 2016 at 03:54:54PM +0100, Roger Pau Monn=E9 wrote: > > > El 19/01/16 a les 14.24, Wei Liu ha escrit: > > > > On Fri, Jan 15, 2016 at 01:23:03PM +0000, Ian Campbell wrote: > > > > > This avoids a potential issue with a fork after allocation but > > > > > before > > > > > madvise. > > > > > = > > > > > Signed-off-by: Ian Campbell > > > > > --- > > > > > v7: New, replacing "tools/libs/call: linux: avoid forking between > > > > > mmap > > > > > =A0=A0=A0=A0and madvise". > > > > > --- > > > > > =A0tools/libs/call/linux.c | 14 +++++++++++++- > > > > > =A01 file changed, 13 insertions(+), 1 deletion(-) > > > > > = > > > > > diff --git a/tools/libs/call/linux.c b/tools/libs/call/linux.c > > > > > index 3641e41..651f380 100644 > > > > > --- a/tools/libs/call/linux.c > > > > > +++ b/tools/libs/call/linux.c > > > > = > > > > I didn't notice you only handled this for Linux until now. > > > > = > > > > I think FreeBSD and NetBSD need similar treatment, too? But then > > > > current > > > > BSD* code doesn't even support DONTFORK in madvise. > > > > = > > > > Adding Roger for more input. > > > = > > > Hm, right, thanks for noticing this. I don't think FreeBSD needs a > > > similar treatment (pre-faulting), because mlock will remove any CoW > > > when > > > making the pages wired. > > > = > > > Also, AFAICT we don't need to call madvise or minherit(2) because > > > mlock(2) already takes care of preventing the memory region from being > > > copied to the child on fork: > > > = > > > "Locked mappings are not inherited by the child process after a > > > fork(2)." [0] > > > = > > > So I think we are safe on the FreeBSD side. > > > = > > = > > But what if the process forks between mmap and mlock? I think that > > warrants touching the area like we do for Linux here. > = > mlock guarantees the memory is populated, I think, which is equivalent to > touching it. > = > On Linux we use madvise not mlock, which doesn't make the same claims. > = I see. I wonder why we didn't use mlock(2) in Linux too in the first place. Wei. > > = > Ian.