From: David Hildenbrand <david@redhat.com> To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, David Hildenbrand <david@redhat.com>, Linus Torvalds <torvalds@linux-foundation.org>, Andrew Morton <akpm@linux-foundation.org>, Mel Gorman <mgorman@techsingularity.net>, Dave Chinner <david@fromorbit.com>, Nadav Amit <namit@vmware.com>, Peter Xu <peterx@redhat.com>, Andrea Arcangeli <aarcange@redhat.com>, Hugh Dickins <hughd@google.com>, Vlastimil Babka <vbabka@suse.cz>, Michael Ellerman <mpe@ellerman.id.au>, Nicholas Piggin <npiggin@gmail.com>, Mike Rapoport <rppt@kernel.org>, Anshuman Khandual <anshuman.khandual@arm.com> Subject: [PATCH RFC 1/5] mm/mprotect: allow clean exclusive anon pages to be writable Date: Mon, 26 Sep 2022 17:26:14 +0200 [thread overview] Message-ID: <20220926152618.194810-2-david@redhat.com> (raw) In-Reply-To: <20220926152618.194810-1-david@redhat.com> From: Nadav Amit <namit@vmware.com> Anonymous pages might have the dirty bit clear, but this should not prevent mprotect from making them writable if they are exclusive. Therefore, skip the test whether the page is dirty in this case. Note that there are already other ways to get a writable PTE mapping an anonymous page that is clean: for example, via MADV_FREE. In an ideal world, we'd have a different indication from the FS whether writenotify is still required. Signed-off-by: Nadav Amit <namit@vmware.com> [ comment for dirty/clean handling; return directly; update description ] Signed-off-by: David Hildenbrand <david@redhat.com> --- mm/mprotect.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index ed013f836b4a..c6c13a0a4bcc 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -45,7 +45,7 @@ static inline bool can_change_pte_writable(struct vm_area_struct *vma, VM_BUG_ON(!(vma->vm_flags & VM_WRITE) || pte_write(pte)); - if (pte_protnone(pte) || !pte_dirty(pte)) + if (pte_protnone(pte)) return false; /* Do we need write faults for softdirty tracking? */ @@ -64,11 +64,15 @@ static inline bool can_change_pte_writable(struct vm_area_struct *vma, * the PT lock. */ page = vm_normal_page(vma, addr, pte); - if (!page || !PageAnon(page) || !PageAnonExclusive(page)) - return false; + return page && PageAnon(page) && PageAnonExclusive(page); } - return true; + /* + * Shared mapping: "clean" might indicate that the FS still has to be + * notified via a write fault once first -- see vma_wants_writenotify(). + * If "dirty", the assumtion is that there already was a write fault. + */ + return pte_dirty(pte); } static unsigned long change_pte_range(struct mmu_gather *tlb, -- 2.37.3
WARNING: multiple messages have this Message-ID (diff)
From: David Hildenbrand <david@redhat.com> To: linux-kernel@vger.kernel.org Cc: Andrea Arcangeli <aarcange@redhat.com>, David Hildenbrand <david@redhat.com>, linuxppc-dev@lists.ozlabs.org, Anshuman Khandual <anshuman.khandual@arm.com>, Dave Chinner <david@fromorbit.com>, Mel Gorman <mgorman@techsingularity.net>, Peter Xu <peterx@redhat.com>, linux-mm@kvack.org, Hugh Dickins <hughd@google.com>, Nadav Amit <namit@vmware.com>, Nicholas Piggin <npiggin@gmail.com>, Mike Rapoport <rppt@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, Linus Torvalds <torvalds@linux-foundation.org>, Vlastimil Babka <vbabka@suse.cz> Subject: [PATCH RFC 1/5] mm/mprotect: allow clean exclusive anon pages to be writable Date: Mon, 26 Sep 2022 17:26:14 +0200 [thread overview] Message-ID: <20220926152618.194810-2-david@redhat.com> (raw) In-Reply-To: <20220926152618.194810-1-david@redhat.com> From: Nadav Amit <namit@vmware.com> Anonymous pages might have the dirty bit clear, but this should not prevent mprotect from making them writable if they are exclusive. Therefore, skip the test whether the page is dirty in this case. Note that there are already other ways to get a writable PTE mapping an anonymous page that is clean: for example, via MADV_FREE. In an ideal world, we'd have a different indication from the FS whether writenotify is still required. Signed-off-by: Nadav Amit <namit@vmware.com> [ comment for dirty/clean handling; return directly; update description ] Signed-off-by: David Hildenbrand <david@redhat.com> --- mm/mprotect.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index ed013f836b4a..c6c13a0a4bcc 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -45,7 +45,7 @@ static inline bool can_change_pte_writable(struct vm_area_struct *vma, VM_BUG_ON(!(vma->vm_flags & VM_WRITE) || pte_write(pte)); - if (pte_protnone(pte) || !pte_dirty(pte)) + if (pte_protnone(pte)) return false; /* Do we need write faults for softdirty tracking? */ @@ -64,11 +64,15 @@ static inline bool can_change_pte_writable(struct vm_area_struct *vma, * the PT lock. */ page = vm_normal_page(vma, addr, pte); - if (!page || !PageAnon(page) || !PageAnonExclusive(page)) - return false; + return page && PageAnon(page) && PageAnonExclusive(page); } - return true; + /* + * Shared mapping: "clean" might indicate that the FS still has to be + * notified via a write fault once first -- see vma_wants_writenotify(). + * If "dirty", the assumtion is that there already was a write fault. + */ + return pte_dirty(pte); } static unsigned long change_pte_range(struct mmu_gather *tlb, -- 2.37.3
next prev parent reply other threads:[~2022-09-26 16:40 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-26 15:26 [PATCH RFC 0/5] mm/autonuma: replace savedwrite infrastructure David Hildenbrand 2022-09-26 15:26 ` David Hildenbrand 2022-09-26 15:26 ` David Hildenbrand [this message] 2022-09-26 15:26 ` [PATCH RFC 1/5] mm/mprotect: allow clean exclusive anon pages to be writable David Hildenbrand 2022-09-26 15:26 ` [PATCH RFC 2/5] mm/mprotect: minor can_change_pte_writable() cleanups David Hildenbrand 2022-09-26 15:26 ` David Hildenbrand 2022-09-26 15:26 ` [PATCH RFC 3/5] mm/huge_memory: try avoiding write faults when changing PMD protection David Hildenbrand 2022-09-26 15:26 ` David Hildenbrand 2022-09-26 15:26 ` [PATCH RFC 4/5] mm/autonuma: use can_change_(pte|pmd)_writable() to replace savedwrite David Hildenbrand 2022-09-26 15:26 ` David Hildenbrand 2022-09-26 15:26 ` [PATCH RFC 5/5] mm: remove unused savedwrite infrastructure David Hildenbrand 2022-09-26 15:26 ` David Hildenbrand
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220926152618.194810-2-david@redhat.com \ --to=david@redhat.com \ --cc=aarcange@redhat.com \ --cc=akpm@linux-foundation.org \ --cc=anshuman.khandual@arm.com \ --cc=david@fromorbit.com \ --cc=hughd@google.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=linuxppc-dev@lists.ozlabs.org \ --cc=mgorman@techsingularity.net \ --cc=mpe@ellerman.id.au \ --cc=namit@vmware.com \ --cc=npiggin@gmail.com \ --cc=peterx@redhat.com \ --cc=rppt@kernel.org \ --cc=torvalds@linux-foundation.org \ --cc=vbabka@suse.cz \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.