Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-10 Thread Peter Zijlstra
On Wed, Nov 04, 2020 at 04:17:11AM +0100, Ahmed S. Darwish wrote: > On Tue, Nov 03, 2020 at 06:01:30PM -0800, John Hubbard wrote: > > On 11/3/20 5:32 PM, Ahmed S. Darwish wrote: > ... > > > #define __read_seqcount_retry(s, start) > > > \ > > > - __read_seqcount_t_

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-04 Thread Ahmed S. Darwish
On Wed, Nov 04, 2020 at 10:38:57AM -0800, Linus Torvalds wrote: ... > > Looks reasonable to me. > > And can you add a few comments to the magic type macros, so that it's > a lot more obvious what the end result was. ... > > I can see it when I really look, but when looking at the actual use, > it's

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-04 Thread Linus Torvalds
On Tue, Nov 3, 2020 at 7:17 PM Ahmed S. Darwish wrote: > > Nonetheless, as you mentioned in the later (dropped) part of your > message, I think do_ is better than __do_, so the final result will be: > > do___read_seqcount_retry() > do_read_seqcount_retry() > do_raw_write_seqcount_begin() >

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-03 Thread Ahmed S. Darwish
On Tue, Nov 03, 2020 at 06:01:30PM -0800, John Hubbard wrote: > On 11/3/20 5:32 PM, Ahmed S. Darwish wrote: ... > > #define __read_seqcount_retry(s, start) > > \ > > - __read_seqcount_t_retry(__seqcount_ptr(s), start) > > + __do___read_seqcount_retry(__seqco

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-03 Thread John Hubbard
On 11/3/20 5:32 PM, Ahmed S. Darwish wrote: On Tue, Nov 03, 2020 at 09:40:22AM -0800, Linus Torvalds wrote: On Mon, Nov 2, 2020 at 10:52 PM Ahmed S. Darwish wrote: ... > > patch #1: > Subject: [RFC][PATCH 1/2] seqlock: Use __do_ prefix instead of non-standed _seqcount_t_ marke

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-03 Thread Ahmed S. Darwish
On Tue, Nov 03, 2020 at 09:40:22AM -0800, Linus Torvalds wrote: > On Mon, Nov 2, 2020 at 10:52 PM Ahmed S. Darwish > wrote: > > > > The problem is, I've already documented seqlock.h to death There are > > more comments than code in there, and there is "seqlock.rst" under > > Documentation/ to

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-03 Thread Linus Torvalds
On Mon, Nov 2, 2020 at 10:52 PM Ahmed S. Darwish wrote: > > The problem is, I've already documented seqlock.h to death There are > more comments than code in there, and there is "seqlock.rst" under > Documentation/ to further describe the big picture. Well, honestly, I think the correct thing

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-03 Thread Peter Xu
On Tue, Nov 03, 2020 at 01:17:12AM +0100, Ahmed S. Darwish wrote: > > > > diff --git a/mm/memory.c b/mm/memory.c > > > > index c48f8df6e50268..294c2c3c4fe00d 100644 > > > > +++ b/mm/memory.c > > > > @@ -1171,6 +1171,12 @@ copy_page_range(struct vm_area_struct *dst_vma, > > > > struct vm_area_struc

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-02 Thread Ahmed S. Darwish
On Mon, Nov 02, 2020 at 06:20:45PM -0800, John Hubbard wrote: > On 11/2/20 4:41 PM, Ahmed S. Darwish wrote: > > On Mon, Nov 02, 2020 at 08:25:32PM -0400, Jason Gunthorpe wrote: > > > On Tue, Nov 03, 2020 at 01:17:12AM +0100, Ahmed S. Darwish wrote: > > > > > > > Please stick with the official expor

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-02 Thread John Hubbard
On 11/2/20 4:41 PM, Ahmed S. Darwish wrote: On Mon, Nov 02, 2020 at 08:25:32PM -0400, Jason Gunthorpe wrote: On Tue, Nov 03, 2020 at 01:17:12AM +0100, Ahmed S. Darwish wrote: Please stick with the official exported API: raw_write_seqcount_begin(). How did you know this was 'offical exported

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-02 Thread Ahmed S. Darwish
On Mon, Nov 02, 2020 at 08:25:32PM -0400, Jason Gunthorpe wrote: > On Tue, Nov 03, 2020 at 01:17:12AM +0100, Ahmed S. Darwish wrote: > > > Please stick with the official exported API: raw_write_seqcount_begin(). > > How did you know this was 'offical exported API' ?? > All the official exported se

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-02 Thread Ahmed S. Darwish
On Sat, Oct 31, 2020 at 11:26:05AM -0400, Peter Xu wrote: ... > Shall we document this explicitly (if this patch still needs a repost)? Yes, this patch series needs a v3 :) > Seems not straightforward since that seems not the usual way to use seqcount, > not sure whether I'm the only one that f

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-02 Thread Ahmed S. Darwish
On Fri, Oct 30, 2020 at 08:51:21PM -0300, Jason Gunthorpe wrote: > On Fri, Oct 30, 2020 at 06:52:50PM -0400, Peter Xu wrote: ... > > > > diff --git a/mm/memory.c b/mm/memory.c > > > index c48f8df6e50268..294c2c3c4fe00d 100644 > > > +++ b/mm/memory.c > > > @@ -1171,6 +1171,12 @@ copy_page_range(st

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-02 Thread Ahmed S. Darwish
On Fri, Oct 30, 2020 at 11:46:21AM -0300, Jason Gunthorpe wrote: ... > diff --git a/mm/memory.c b/mm/memory.c > index c48f8df6e50268..294c2c3c4fe00d 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -1171,6 +1171,12 @@ copy_page_range(struct vm_area_struct *dst_vma, struct > vm_area_struct *sr

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-11-02 Thread Jan Kara
On Fri 30-10-20 14:02:26, Jason Gunthorpe wrote: > On Fri, Oct 30, 2020 at 05:51:05PM +0100, Jan Kara wrote: > > > @@ -446,6 +447,12 @@ struct mm_struct { > > >*/ > > > atomic_t has_pinned; > > > > > > + /** > > > + * @write_protect_seq: Odd when any thread

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-10-31 Thread Peter Xu
On Fri, Oct 30, 2020 at 08:51:21PM -0300, Jason Gunthorpe wrote: > > Another pure question: I'm just curious how you find all the statically > > definied mm_structs, and to make sure all of them are covered (just in case > > un-initialized seqcount could fail strangely). > > I searched for all MMA

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-10-30 Thread Peter Xu
Hi, Jason, I think majorly the patch looks good to me, but I have a few pure questions majorly not directly related to the patch itself, but around the contexts. Since I _feel_ like there'll be a new version to update the comments below, maybe I can still ask aloud... Please bare with me. :) On F

Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork

2020-10-30 Thread Jan Kara
On Fri 30-10-20 11:46:21, Jason Gunthorpe wrote: > Since commit 70e806e4e645 ("mm: Do early cow for pinned pages during > fork() for ptes") pages under a FOLL_PIN will not be write protected > during COW for fork. This means that pages returned from > pin_user_pages(FOLL_WRITE) should not become wr