Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork
From: Ahmed S. Darwish
Date: Mon Nov 02 2020 - 18:58:49 EST
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 *src_vma)
> mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_PAGE,
> 0, src_vma, src_mm, addr, end);
> mmu_notifier_invalidate_range_start(&range);
> + /*
> + * The read side doesn't spin, it goes to the mmap_lock, so the
> + * raw version is used to avoid disabling preemption here
> + */
> + mmap_assert_write_locked(src_mm);
> + raw_write_seqcount_t_begin(&src_mm->write_protect_seq);
> }
>
Please, s/raw_write_seqcount_t_begin()/raw_write_seqcount_begin()/g. For
plain seqcount_t, it's the same, while still respecting the seqlock.h
API boundaries.
Let's make the comment also a bit more clear (IMHO, "lockdep" needs to
be mentioned somewhere):
/*
* Disabling preemption is not needed for the write side, as
* the read side doesn't spin, but goes to the mmap_lock.
*
* Use the raw variant of the seqcount_t write API to avoid
* lockdep complaining about preemptibility.
*/
mmap_assert_write_locked(src_mm);
raw_write_seqcount_t_begin(&src_mm->write_protect_seq);
> ret = 0;
> @@ -1187,8 +1193,10 @@ copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma)
> }
> } while (dst_pgd++, src_pgd++, addr = next, addr != end);
>
> - if (is_cow)
> + if (is_cow) {
> + raw_write_seqcount_t_end(&src_mm->write_protect_seq);
ditto.
s/raw_write_seqcount_t_end()/raw_write_seqcount_end()/g
> mmu_notifier_invalidate_range_end(&range);
> + }
> return ret;
> }
>
Thanks,
--
Ahmed S. Darwish
Linutronix GmbH