Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Xu
On Tue, Jan 05, 2021 at 04:06:27PM -0500, Andrea Arcangeli wrote: > The postcopy live snapshoitting was the #1 use case so it's hard not > to mention it, but there's still other interesting userland use cases > of uffd-wp with various users already testing it in their apps, that > may ultimately

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Andrea Arcangeli
On Tue, Jan 05, 2021 at 08:06:22PM +, Nadav Amit wrote: > I just thought that there might be some insinuation, as you mentioned VMware > by name. My response was half-jokingly and should have had a smiley to > prevent you from wasting your time on the explanation. No problem, actually I

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Nadav Amit
> On Jan 5, 2021, at 11:45 AM, Andrea Arcangeli wrote: > > On Tue, Jan 05, 2021 at 07:05:22PM +, Nadav Amit wrote: >>> On Jan 5, 2021, at 10:45 AM, Andrea Arcangeli wrote: >>> I just don't like to slow down a feature required in the future for >>> implementing postcopy live snapshotting or

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Andrea Arcangeli
On Tue, Jan 05, 2021 at 07:05:22PM +, Nadav Amit wrote: > > On Jan 5, 2021, at 10:45 AM, Andrea Arcangeli wrote: > > I just don't like to slow down a feature required in the future for > > implementing postcopy live snapshotting or other snapshots to userland > > processes (for the non-KVM

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Xu
On Tue, Jan 05, 2021 at 07:07:51PM +, Nadav Amit wrote: > > On Jan 5, 2021, at 7:08 AM, Peter Xu wrote: > > > > On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > >> diff --git a/mm/mprotect.c b/mm/mprotect.c > >> index ab709023e9aa..c08c4055b051 100644 > >> --- a/mm/mprotect.c >

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Nadav Amit
> On Jan 5, 2021, at 7:08 AM, Peter Xu wrote: > > On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: >> diff --git a/mm/mprotect.c b/mm/mprotect.c >> index ab709023e9aa..c08c4055b051 100644 >> --- a/mm/mprotect.c >> +++ b/mm/mprotect.c >> @@ -75,7 +75,8 @@ static unsigned long

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Nadav Amit
> On Jan 5, 2021, at 10:45 AM, Andrea Arcangeli wrote: > > On Mon, Jan 04, 2021 at 09:26:33PM +, Nadav Amit wrote: >> I would feel more comfortable if you provide patches for uffd-wp. If you >> want, I will do it, but I restate that I do not feel comfortable with this >> solution (worried as

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Andrea Arcangeli
On Tue, Jan 05, 2021 at 01:41:34PM -0500, Peter Xu wrote: > Agreed. I didn't mention uffd_wp check (which I actually mentioned in the > reply > to v1 patchset) here only because the uffd_wp check is pure optimization; > while Agreed it's a pure optimization. Only if we used the group lock to

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Andrea Arcangeli
On Mon, Jan 04, 2021 at 09:26:33PM +, Nadav Amit wrote: > I would feel more comfortable if you provide patches for uffd-wp. If you > want, I will do it, but I restate that I do not feel comfortable with this > solution (worried as it seems a bit ad-hoc and might leave out a scenario > we all

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Xu
On Tue, Jan 05, 2021 at 01:08:48PM -0500, Andrea Arcangeli wrote: > On Tue, Jan 05, 2021 at 10:08:13AM -0500, Peter Xu wrote: > > On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > > > diff --git a/mm/mprotect.c b/mm/mprotect.c > > > index ab709023e9aa..c08c4055b051 100644 > > > ---

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Andrea Arcangeli
On Tue, Jan 05, 2021 at 10:08:13AM -0500, Peter Xu wrote: > On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > > diff --git a/mm/mprotect.c b/mm/mprotect.c > > index ab709023e9aa..c08c4055b051 100644 > > --- a/mm/mprotect.c > > +++ b/mm/mprotect.c > > @@ -75,7 +75,8 @@ static unsigned

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Andrea Arcangeli
On Tue, Jan 05, 2021 at 09:58:57AM +0100, Peter Zijlstra wrote: > On Mon, Jan 04, 2021 at 02:24:38PM -0500, Andrea Arcangeli wrote: > > On Mon, Jan 04, 2021 at 01:22:27PM +0100, Peter Zijlstra wrote: > > > On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > > > > > > > The scenario that

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Xu
On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > diff --git a/mm/mprotect.c b/mm/mprotect.c > index ab709023e9aa..c08c4055b051 100644 > --- a/mm/mprotect.c > +++ b/mm/mprotect.c > @@ -75,7 +75,8 @@ static unsigned long change_pte_range(struct vm_area_struct > *vma, pmd_t *pmd, >

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Zijlstra
On Tue, Jan 05, 2021 at 12:52:48AM -0800, Nadav Amit wrote: > > On Jan 5, 2021, at 12:13 AM, Peter Zijlstra wrote: > > > > On Mon, Jan 04, 2021 at 02:24:38PM -0500, Andrea Arcangeli wrote: > >> The problematic one not pictured is the one of the wrprotect that has > >> to be running in another

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Nadav Amit
> On Jan 5, 2021, at 12:58 AM, Peter Zijlstra wrote: > > On Mon, Jan 04, 2021 at 02:24:38PM -0500, Andrea Arcangeli wrote: >> On Mon, Jan 04, 2021 at 01:22:27PM +0100, Peter Zijlstra wrote: >>> On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: >>> The scenario that happens in

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Zijlstra
On Mon, Jan 04, 2021 at 02:24:38PM -0500, Andrea Arcangeli wrote: > On Mon, Jan 04, 2021 at 01:22:27PM +0100, Peter Zijlstra wrote: > > On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > > > > > The scenario that happens in selftests/vm/userfaultfd is as follows: > > > > > > cpu0

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Nadav Amit
> On Jan 5, 2021, at 12:13 AM, Peter Zijlstra wrote: > > On Mon, Jan 04, 2021 at 02:24:38PM -0500, Andrea Arcangeli wrote: >> The problematic one not pictured is the one of the wrprotect that has >> to be running in another CPU which is also isn't picture above. More >> accurate traces are

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Zijlstra
On Mon, Jan 04, 2021 at 02:24:38PM -0500, Andrea Arcangeli wrote: > The problematic one not pictured is the one of the wrprotect that has > to be running in another CPU which is also isn't picture above. More > accurate traces are posted later in the thread. What thread? I don't seem to have

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-04 Thread Nadav Amit
> On Jan 4, 2021, at 1:01 PM, Andrea Arcangeli wrote: > > On Mon, Jan 04, 2021 at 08:39:37PM +, Nadav Amit wrote: >>> On Jan 4, 2021, at 12:19 PM, Andrea Arcangeli wrote: >>> >>> On Mon, Jan 04, 2021 at 07:35:06PM +, Nadav Amit wrote: > On Jan 4, 2021, at 11:24 AM, Andrea Arcangeli

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-04 Thread Andrea Arcangeli
On Mon, Jan 04, 2021 at 08:39:37PM +, Nadav Amit wrote: > > On Jan 4, 2021, at 12:19 PM, Andrea Arcangeli wrote: > > > > On Mon, Jan 04, 2021 at 07:35:06PM +, Nadav Amit wrote: > >>> On Jan 4, 2021, at 11:24 AM, Andrea Arcangeli wrote: > >>> > >>> Hello, > >>> > >>> On Mon, Jan 04,

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-04 Thread Nadav Amit
> On Jan 4, 2021, at 12:19 PM, Andrea Arcangeli wrote: > > On Mon, Jan 04, 2021 at 07:35:06PM +, Nadav Amit wrote: >>> On Jan 4, 2021, at 11:24 AM, Andrea Arcangeli wrote: >>> >>> Hello, >>> >>> On Mon, Jan 04, 2021 at 01:22:27PM +0100, Peter Zijlstra wrote: On Fri, Dec 25, 2020 at

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-04 Thread Andrea Arcangeli
On Mon, Jan 04, 2021 at 07:35:06PM +, Nadav Amit wrote: > > On Jan 4, 2021, at 11:24 AM, Andrea Arcangeli wrote: > > > > Hello, > > > > On Mon, Jan 04, 2021 at 01:22:27PM +0100, Peter Zijlstra wrote: > >> On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > >> > >>> The scenario

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-04 Thread Nadav Amit
> On Jan 4, 2021, at 11:24 AM, Andrea Arcangeli wrote: > > Hello, > > On Mon, Jan 04, 2021 at 01:22:27PM +0100, Peter Zijlstra wrote: >> On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: >> >>> The scenario that happens in selftests/vm/userfaultfd is as follows: >>> >>> cpu0

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-04 Thread Andrea Arcangeli
Hello, On Mon, Jan 04, 2021 at 01:22:27PM +0100, Peter Zijlstra wrote: > On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > > > The scenario that happens in selftests/vm/userfaultfd is as follows: > > > > cpu0cpu1cpu2 > >

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-04 Thread Peter Zijlstra
On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > The scenario that happens in selftests/vm/userfaultfd is as follows: > > cpu0 cpu1cpu2 > >

[RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2020-12-25 Thread Nadav Amit
From: Nadav Amit Userfaultfd self-test fails occasionally, indicating a memory corruption. Analyzing this problem indicates that there is a real bug since mmap_lock is only taken for read in mwriteprotect_range() and defers flushes, and since there is insufficient consideration of concurrent