From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrea Arcangeli Subject: Re: [RFC PATCH 1/4] uprobes: use set_pte_at() not set_pte_at_notify() Date: Fri, 1 Feb 2019 19:50:22 -0500 Message-ID: <20190202005022.GC12463@redhat.com> References: <20190131183706.20980-1-jglisse@redhat.com> <20190131183706.20980-2-jglisse@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Peter Xu , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andrew Morton , Matthew Wilcox , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Michal Hocko , kvm@vger.kernel.org To: jglisse@redhat.com Return-path: Content-Disposition: inline In-Reply-To: <20190131183706.20980-2-jglisse@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Thu, Jan 31, 2019 at 01:37:03PM -0500, Jerome Glisse wrote: > @@ -207,8 +207,7 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, > > flush_cache_page(vma, addr, pte_pfn(*pvmw.pte)); > ptep_clear_flush_notify(vma, addr, pvmw.pte); > - set_pte_at_notify(mm, addr, pvmw.pte, > - mk_pte(new_page, vma->vm_page_prot)); > + set_pte_at(mm, addr, pvmw.pte, mk_pte(new_page, vma->vm_page_prot)); > > page_remove_rmap(old_page, false); > if (!page_mapped(old_page)) This seems racy by design in the way it copies the page, if the vma mapping isn't readonly to begin with (in which case it'd be ok to change the pfn with change_pte too, it'd be a from read-only to read-only change which is ok). If the code copies a writable page there's no much issue if coherency is lost by other means too. Said that this isn't a worthwhile optimization for uprobes so because of the lack of explicit read-only enforcement, I agree it's simpler to skip change_pte above. It's orthogonal, but in this function the mmu_notifier_invalidate_range_end(&range); can be optimized to mmu_notifier_invalidate_range_only_end(&range); otherwise there's no point to retain the _notify in ptep_clear_flush_notify.