android_kernel_google_msm/mm
Hugh Dickins 4ff82c7b6e mm: migrate dirty page without clear_page_dirty_for_io etc
commit 42cb14b110a5698ccf26ce59c4441722605a3743 upstream.

clear_page_dirty_for_io() has accumulated writeback and memcg subtleties
since v2.6.16 first introduced page migration; and the set_page_dirty()
which completed its migration of PageDirty, later had to be moderated to
__set_page_dirty_nobuffers(); then PageSwapBacked had to skip that too.

No actual problems seen with this procedure recently, but if you look into
what the clear_page_dirty_for_io(page)+set_page_dirty(newpage) is actually
achieving, it turns out to be nothing more than moving the PageDirty flag,
and its NR_FILE_DIRTY stat from one zone to another.

It would be good to avoid a pile of irrelevant decrementations and
incrementations, and improper event counting, and unnecessary descent of
the radix_tree under tree_lock (to set the PAGECACHE_TAG_DIRTY which
radix_tree_replace_slot() left in place anyway).

Do the NR_FILE_DIRTY movement, like the other stats movements, while
interrupts still disabled in migrate_page_move_mapping(); and don't even
bother if the zone is the same.  Do the PageDirty movement there under
tree_lock too, where old page is frozen and newpage not yet visible:
bearing in mind that as soon as newpage becomes visible in radix_tree, an
un-page-locked set_page_dirty() might interfere (or perhaps that's just
not possible: anything doing so should already hold an additional
reference to the old page, preventing its migration; but play safe).

But we do still need to transfer PageDirty in migrate_page_copy(), for
those who don't go the mapping route through migrate_page_move_mapping().

CVE-2016-3070

Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[ciwillia@brocade.com: backported to 3.10: adjusted context]
Signed-off-by: Charles (Chas) Williams <ciwillia@brocade.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>

Change-Id: Ifee7c4f76e277763ef2dd63c810590cd237575a4
2017-06-26 18:24:38 +03:00
..
backing-dev.c bdi: use deferable timer for sync_supers task 2013-02-27 18:16:50 -08:00
bootmem.c mm: sparse: fix usemap allocation above node descriptor section 2016-10-29 23:12:12 +08:00
bounce.c
cleancache.c
compaction.c cma: fix watermark checking 2013-03-15 17:06:38 -07:00
debug-pagealloc.c
dmapool.c
fadvise.c
failslab.c
filemap.c fs: introduce inode operation ->update_time 2015-07-13 11:17:49 -07:00
filemap_xip.c fs: introduce inode operation ->update_time 2015-07-13 11:17:49 -07:00
fremap.c
highmem.c
huge_memory.c
hugetlb.c hugetlb: prevent BUG_ON in hugetlb_fault() -> hugetlb_cow() 2012-05-10 15:06:44 -07:00
hwpoison-inject.c
init-mm.c
internal.h cma: fix watermark checking 2013-03-15 17:06:38 -07:00
Kconfig mm: mmzone: MIGRATE_CMA migration type added 2013-02-27 18:14:01 -08:00
Kconfig.debug
kmemcheck.c
kmemleak-test.c
kmemleak.c
ksm.c ksm: Provide support to use deferred timers for scanner thread 2016-10-29 23:12:17 +08:00
maccess.c
madvise.c mm: add a field to store names for private anonymous memory 2013-10-11 10:02:06 -07:00
Makefile mm: compaction: export some of the functions 2013-02-27 18:13:58 -08:00
memblock.c memblock: Add memblock_overlaps_memory() 2013-02-20 02:43:56 -08:00
memcontrol.c memcg,thp: fix res_counter:96 regression 2012-05-19 10:10:27 -07:00
memory-failure.c mm: page_isolation: MIGRATE_CMA isolation functions added 2013-02-27 18:14:02 -08:00
memory.c mm: avoid setting up anonymous pages into file mapping 2017-03-02 16:28:10 -07:00
memory_hotplug.c mm: page_isolation: MIGRATE_CMA isolation functions added 2013-02-27 18:14:02 -08:00
mempolicy.c mm: fix anon vma naming 2016-10-29 23:12:35 +08:00
mempool.c
migrate.c mm: migrate dirty page without clear_page_dirty_for_io etc 2017-06-26 18:24:38 +03:00
mincore.c
mlock.c mm: reorder can_do_mlock to fix audit denial 2015-06-16 23:08:46 -07:00
mm_init.c
mmap.c FROMLIST: mm: mmap: Add new /proc tunable for mmap_base ASLR. 2016-10-29 23:12:40 +08:00
mmu_context.c
mmu_notifier.c
mmzone.c
mprotect.c mm: add a field to store names for private anonymous memory 2013-10-11 10:02:06 -07:00
mremap.c
msync.c
nobootmem.c mm: nobootmem: fix sign extend problem in __free_pages_memory() 2012-05-10 15:06:44 -07:00
nommu.c kill mm argument of vm_munmap() 2012-04-21 01:58:20 -04:00
oom_kill.c mm, oom: make dump_tasks public 2014-11-18 15:13:25 -08:00
page-writeback.c mm: fix calculation of dirtyable memory 2016-10-29 23:12:16 +08:00
page_alloc.c mm: workaround for widevine playback failed 2013-05-22 07:57:36 +00:00
page_cgroup.c
page_io.c
page_isolation.c mm: page_isolation: MIGRATE_CMA isolation functions added 2013-02-27 18:14:02 -08:00
pagewalk.c
percpu-km.c
percpu-vm.c
percpu.c kmemleak: Fix the kmemleak tracking of the percpu areas with !SMP 2012-05-09 10:13:29 -07:00
pgtable-generic.c
prio_tree.c
process_vm_access.c
quicklist.c
readahead.c mm: change initial readahead window size calculation 2016-10-29 23:12:18 +08:00
rmap.c
shmem.c ashmem: Add shmem_set_file to mm/shmem.c 2012-04-09 13:53:14 -07:00
slab.c Merge branch 'slab/for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/penberg/linux 2012-03-28 15:04:26 -07:00
slob.c
slub.c slub: fix a memory leak in get_partial_node() 2013-03-15 17:09:26 -07:00
sparse-vmemmap.c
sparse.c msm: mm: Fix errors when turning on SPARSEMEM 2013-02-20 02:43:57 -08:00
swap.c
swap_state.c mm: fix s390 BUG by __set_page_dirty_no_writeback on swap 2012-04-23 18:19:22 -07:00
swapfile.c swapon: check validity of swap_flags 2012-03-28 17:14:35 -07:00
thrash.c
truncate.c mm for fs: add truncate_pagecache_range() 2012-03-28 17:14:35 -07:00
util.c nick kvfree() from apparmor 2014-11-18 15:13:23 -08:00
vmalloc.c mm: fix faulty initialization in vmalloc_init() 2013-02-20 02:43:59 -08:00
vmscan.c mm: vmscan: clear kswapd's special reclaim powers before exiting 2016-10-29 23:12:33 +08:00
vmstat.c mm: make counts of CMA free pages correct 2013-03-07 15:23:58 -08:00