linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: softdirty: write protect PTEs created for read faults after VM_SOFTDIRTY cleared
@ 2014-08-20 21:46 Peter Feiner
  2014-08-20 23:45 ` Kirill A. Shutemov
                   ` (5 more replies)
  0 siblings, 6 replies; 36+ messages in thread
From: Peter Feiner @ 2014-08-20 21:46 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, Peter Feiner, Cyrill Gorcunov, Pavel Emelyanov,
	Jamie Liu, Hugh Dickins, Naoya Horiguchi, Andrew Morton

In readable+writable+shared VMAs, PTEs created for read faults have
their write bit set. If the read fault happens after VM_SOFTDIRTY is
cleared, then the PTE's softdirty bit will remain clear after
subsequent writes.

Here's a simple code snippet to demonstrate the bug:

  char* m = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE,
                 MAP_ANONYMOUS | MAP_SHARED, -1, 0);
  system("echo 4 > /proc/$PPID/clear_refs"); /* clear VM_SOFTDIRTY */
  assert(*m == '\0');     /* new PTE allows write access */
  assert(!soft_dirty(x));
  *m = 'x';               /* should dirty the page */
  assert(soft_dirty(x));  /* fails */

With this patch, new PTEs created for read faults are write protected
if the VMA has VM_SOFTDIRTY clear.

Signed-off-by: Peter Feiner <pfeiner@google.com>
---
 mm/memory.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/memory.c b/mm/memory.c
index ab3537b..282a959 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2755,6 +2755,8 @@ void do_set_pte(struct vm_area_struct *vma, unsigned long address,
 		entry = maybe_mkwrite(pte_mkdirty(entry), vma);
 	else if (pte_file(*pte) && pte_file_soft_dirty(*pte))
 		entry = pte_mksoft_dirty(entry);
+	else if (!(vma->vm_flags & VM_SOFTDIRTY))
+		entry = pte_wrprotect(entry);
 	if (anon) {
 		inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES);
 		page_add_new_anon_rmap(page, vma, address);
-- 
2.1.0.rc2.206.gedb03e5


^ permalink raw reply related	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2014-09-07 23:01 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-20 21:46 [PATCH] mm: softdirty: write protect PTEs created for read faults after VM_SOFTDIRTY cleared Peter Feiner
2014-08-20 23:45 ` Kirill A. Shutemov
2014-08-21 19:37   ` Peter Feiner
2014-08-21 20:51     ` Cyrill Gorcunov
2014-08-21 21:39       ` Kirill A. Shutemov
2014-08-21 21:46         ` Peter Feiner
2014-08-21 21:51           ` Kirill A. Shutemov
2014-08-21 22:50             ` Peter Feiner
2014-08-22  6:33               ` Cyrill Gorcunov
2014-08-23 22:11 ` [PATCH v2 0/3] softdirty fix and write notification cleanup Peter Feiner
2014-08-23 22:11   ` [PATCH v2 1/3] mm: softdirty: enable write notifications on VMAs after VM_SOFTDIRTY cleared Peter Feiner
2014-08-23 23:00     ` Kirill A. Shutemov
2014-08-23 23:15       ` Peter Feiner
2014-08-23 23:50       ` Kirill A. Shutemov
2014-08-24  0:55         ` Peter Feiner
2014-08-23 22:12   ` [PATCH v2 2/3] mm: mprotect: preserve special page protection bits Peter Feiner
2014-08-23 22:12   ` [PATCH v2 3/3] mm: mmap: cleanup code that preserves special vm_page_prot bits Peter Feiner
2014-08-24  1:43 ` [PATCH v3] mm: softdirty: enable write notifications on VMAs after VM_SOFTDIRTY cleared Peter Feiner
2014-08-24  7:59   ` Kirill A. Shutemov
2014-08-24 19:22     ` Cyrill Gorcunov
2014-08-24 14:41 ` [PATCH v4] " Peter Feiner
2014-08-25  3:34 ` [PATCH v5] " Peter Feiner
2014-08-26  4:45   ` Hugh Dickins
2014-08-26  6:49     ` Cyrill Gorcunov
2014-08-26 14:04       ` Kirill A. Shutemov
2014-08-26 14:19         ` Cyrill Gorcunov
2014-08-26 14:56           ` Kirill A. Shutemov
2014-08-26 15:18             ` Cyrill Gorcunov
2014-08-26 15:43               ` Kirill A. Shutemov
2014-08-26 15:53                 ` Cyrill Gorcunov
2014-08-27 23:12                   ` Hugh Dickins
2014-08-28  6:31                     ` Cyrill Gorcunov
2014-08-27 21:55       ` Hugh Dickins
2014-09-04 16:43     ` Peter Feiner
2014-09-07 21:31       ` Peter Feiner
2014-09-07 23:01 ` [PATCH v6] " Peter Feiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).