Re: [PATCH v2] mm: mprotect: check page dirty when change ptes
From: Jerome Glisse
Date: Wed Sep 12 2018 - 09:04:03 EST
On Wed, Sep 12, 2018 at 02:49:21PM +0800, Peter Xu wrote:
> Add an extra check on page dirty bit in change_pte_range() since there
> might be case where PTE dirty bit is unset but it's actually dirtied.
> One example is when a huge PMD is splitted after written: the dirty bit
> will be set on the compound page however we won't have the dirty bit set
> on each of the small page PTEs.
>
> I noticed this when debugging with a customized kernel that implemented
> userfaultfd write-protect. In that case, the dirty bit will be critical
> since that's required for userspace to handle the write protect page
> fault (otherwise it'll get a SIGBUS with a loop of page faults).
> However it should still be good even for upstream Linux to cover more
> scenarios where we shouldn't need to do extra page faults on the small
> pages if the previous huge page is already written, so the dirty bit
> optimization path underneath can cover more.
>
So as said by Kirill NAK you are not looking at the right place for
your bug please first apply the below patch and read my analysis in
my last reply.
Below patch fix userfaultfd bug. I am not posting it as it is on a
branch and i am not sure when Andrea plan to post. Andrea feel free
to squash that fix.