From: Cyrill Gorcunov <gorcunov@gmail.com>
Date: Wed, 6 Aug 2014 23:07:05 +0000 (-0700)
Subject: mm/memory.c: don't forget to set softdirty on file mapped fault
X-Git-Tag: firefly_0821_release~176^2~3462^2~122
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9aed8614af5a05cdaa32a0b78b0f1a424754a958;p=firefly-linux-kernel-4.4.55.git

mm/memory.c: don't forget to set softdirty on file mapped fault

Otherwise we may not notice that pte was softdirty because
pte_mksoft_dirty helper _returns_ new pte but doesn't modify the
argument.

In case if page fault happend on dirty filemapping the newly created pte
may loose softdirty bit thus if a userspace program is tracking memory
changes with help of a memory tracker (CONFIG_MEM_SOFT_DIRTY) it might
miss modification of a memory page (which in worts case may lead to data
inconsistency).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

diff --git a/mm/memory.c b/mm/memory.c
index 01d0289f30a7..7e131325bdf8 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2744,7 +2744,7 @@ void do_set_pte(struct vm_area_struct *vma, unsigned long address,
 	if (write)
 		entry = maybe_mkwrite(pte_mkdirty(entry), vma);
 	else if (pte_file(*pte) && pte_file_soft_dirty(*pte))
-		pte_mksoft_dirty(entry);
+		entry = pte_mksoft_dirty(entry);
 	if (anon) {
 		inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES);
 		page_add_new_anon_rmap(page, vma, address);