]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - mm/rmap.c
rmap: fix theoretical race between do_wp_page and shrink_active_list
[mirror_ubuntu-bionic-kernel.git] / mm / rmap.c
index 24dd3f9fee27dfe577c7f605bd0c260f0bc143c7..9f47f152b01e1ee5f155657837ae13a0e2b9f9f6 100644 (file)
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -950,7 +950,12 @@ void page_move_anon_rmap(struct page *page,
        VM_BUG_ON_PAGE(page->index != linear_page_index(vma, address), page);
 
        anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON;
-       page->mapping = (struct address_space *) anon_vma;
+       /*
+        * Ensure that anon_vma and the PAGE_MAPPING_ANON bit are written
+        * simultaneously, so a concurrent reader (eg page_referenced()'s
+        * PageAnon()) will not see one without the other.
+        */
+       WRITE_ONCE(page->mapping, (struct address_space *) anon_vma);
 }
 
 /**