Merge tag 'v4.3-rc1' into spi-fix-doc
[firefly-linux-kernel-4.4.55.git] / mm / memory-failure.c
index 5420d3819adf99f224233895900868752d6a3a66..95882692e747c2a534488190287e5954fba35d39 100644 (file)
@@ -130,27 +130,15 @@ static int hwpoison_filter_flags(struct page *p)
  * can only guarantee that the page either belongs to the memcg tasks, or is
  * a freed page.
  */
-#ifdef CONFIG_MEMCG_SWAP
+#ifdef CONFIG_MEMCG
 u64 hwpoison_filter_memcg;
 EXPORT_SYMBOL_GPL(hwpoison_filter_memcg);
 static int hwpoison_filter_task(struct page *p)
 {
-       struct mem_cgroup *mem;
-       struct cgroup_subsys_state *css;
-       unsigned long ino;
-
        if (!hwpoison_filter_memcg)
                return 0;
 
-       mem = try_get_mem_cgroup_from_page(p);
-       if (!mem)
-               return -EINVAL;
-
-       css = &mem->css;
-       ino = cgroup_ino(css->cgroup);
-       css_put(css);
-
-       if (ino != hwpoison_filter_memcg)
+       if (page_cgroup_ino(p) != hwpoison_filter_memcg)
                return -EINVAL;
 
        return 0;
@@ -1121,7 +1109,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
                nr_pages = 1 << compound_order(hpage);
        else /* normal page or thp */
                nr_pages = 1;
-       atomic_long_add(nr_pages, &num_poisoned_pages);
+       num_poisoned_pages_add(nr_pages);
 
        /*
         * We need/can do nothing about count=0 pages.
@@ -1149,7 +1137,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
                        if (PageHWPoison(hpage)) {
                                if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
                                    || (p != hpage && TestSetPageHWPoison(hpage))) {
-                                       atomic_long_sub(nr_pages, &num_poisoned_pages);
+                                       num_poisoned_pages_sub(nr_pages);
                                        unlock_page(hpage);
                                        return 0;
                                }
@@ -1173,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
                        else
                                pr_err("MCE: %#lx: thp split failed\n", pfn);
                        if (TestClearPageHWPoison(p))
-                               atomic_long_sub(nr_pages, &num_poisoned_pages);
+                               num_poisoned_pages_sub(nr_pages);
                        put_hwpoison_page(p);
                        return -EBUSY;
                }
@@ -1233,14 +1221,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
         */
        if (!PageHWPoison(p)) {
                printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
-               atomic_long_sub(nr_pages, &num_poisoned_pages);
+               num_poisoned_pages_sub(nr_pages);
                unlock_page(hpage);
                put_hwpoison_page(hpage);
                return 0;
        }
        if (hwpoison_filter(p)) {
                if (TestClearPageHWPoison(p))
-                       atomic_long_sub(nr_pages, &num_poisoned_pages);
+                       num_poisoned_pages_sub(nr_pages);
                unlock_page(hpage);
                put_hwpoison_page(hpage);
                return 0;
@@ -1445,6 +1433,22 @@ int unpoison_memory(unsigned long pfn)
                return 0;
        }
 
+       if (page_count(page) > 1) {
+               pr_info("MCE: Someone grabs the hwpoison page %#lx\n", pfn);
+               return 0;
+       }
+
+       if (page_mapped(page)) {
+               pr_info("MCE: Someone maps the hwpoison page %#lx\n", pfn);
+               return 0;
+       }
+
+       if (page_mapping(page)) {
+               pr_info("MCE: the hwpoison page has non-NULL mapping %#lx\n",
+                       pfn);
+               return 0;
+       }
+
        /*
         * unpoison_memory() can encounter thp only when the thp is being
         * worked by memory_failure() and the page lock is not held yet.
@@ -1469,7 +1473,7 @@ int unpoison_memory(unsigned long pfn)
                        return 0;
                }
                if (TestClearPageHWPoison(p))
-                       atomic_long_dec(&num_poisoned_pages);
+                       num_poisoned_pages_dec();
                pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
                return 0;
        }
@@ -1483,7 +1487,7 @@ int unpoison_memory(unsigned long pfn)
         */
        if (TestClearPageHWPoison(page)) {
                pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
-               atomic_long_sub(nr_pages, &num_poisoned_pages);
+               num_poisoned_pages_sub(nr_pages);
                freeit = 1;
                if (PageHuge(page))
                        clear_page_hwpoison_huge_page(page);
@@ -1505,7 +1509,7 @@ static struct page *new_page(struct page *p, unsigned long private, int **x)
                return alloc_huge_page_node(page_hstate(compound_head(p)),
                                                   nid);
        else
-               return alloc_pages_exact_node(nid, GFP_HIGHUSER_MOVABLE, 0);
+               return __alloc_pages_node(nid, GFP_HIGHUSER_MOVABLE, 0);
 }
 
 /*
@@ -1619,11 +1623,10 @@ static int soft_offline_huge_page(struct page *page, int flags)
                if (PageHuge(page)) {
                        set_page_hwpoison_huge_page(hpage);
                        dequeue_hwpoisoned_huge_page(hpage);
-                       atomic_long_add(1 << compound_order(hpage),
-                                       &num_poisoned_pages);
+                       num_poisoned_pages_add(1 << compound_order(hpage));
                } else {
                        SetPageHWPoison(page);
-                       atomic_long_inc(&num_poisoned_pages);
+                       num_poisoned_pages_inc();
                }
        }
        return ret;
@@ -1662,7 +1665,7 @@ static int __soft_offline_page(struct page *page, int flags)
                put_hwpoison_page(page);
                pr_info("soft_offline: %#lx: invalidated\n", pfn);
                SetPageHWPoison(page);
-               atomic_long_inc(&num_poisoned_pages);
+               num_poisoned_pages_inc();
                return 0;
        }
 
@@ -1682,8 +1685,6 @@ static int __soft_offline_page(struct page *page, int flags)
                inc_zone_page_state(page, NR_ISOLATED_ANON +
                                        page_is_file_cache(page));
                list_add(&page->lru, &pagelist);
-               if (!TestSetPageHWPoison(page))
-                       atomic_long_inc(&num_poisoned_pages);
                ret = migrate_pages(&pagelist, new_page, NULL, MPOL_MF_MOVE_ALL,
                                        MIGRATE_SYNC, MR_MEMORY_FAILURE);
                if (ret) {
@@ -1698,8 +1699,6 @@ static int __soft_offline_page(struct page *page, int flags)
                                pfn, ret, page->flags);
                        if (ret > 0)
                                ret = -EIO;
-                       if (TestClearPageHWPoison(page))
-                               atomic_long_dec(&num_poisoned_pages);
                }
        } else {
                pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
@@ -1765,11 +1764,10 @@ int soft_offline_page(struct page *page, int flags)
                if (PageHuge(page)) {
                        set_page_hwpoison_huge_page(hpage);
                        if (!dequeue_hwpoisoned_huge_page(hpage))
-                               atomic_long_add(1 << compound_order(hpage),
-                                       &num_poisoned_pages);
+                               num_poisoned_pages_add(1 << compound_order(hpage));
                } else {
                        if (!TestSetPageHWPoison(page))
-                               atomic_long_inc(&num_poisoned_pages);
+                               num_poisoned_pages_inc();
                }
        }
        return ret;