struct page *hpage;
        int res;
        unsigned int nr_pages;
+       unsigned long page_flags;
 
        if (!sysctl_memory_failure_recovery)
                panic("Memory failure from trap %d on page %lx", trapno, pfn);
         */
        lock_page(hpage);
 
+       /*
+        * We use page flags to determine what action should be taken, but
+        * the flags can be modified by the error containment action.  One
+        * example is an mlocked page, where PG_mlocked is cleared by
+        * page_remove_rmap() in try_to_unmap_one(). So to determine page status
+        * correctly, we save a copy of the page flags at this time.
+        */
+       page_flags = p->flags;
+
        /*
         * unpoison always clear PG_hwpoison inside page lock
         */
        }
 
        res = -EBUSY;
-       for (ps = error_states;; ps++) {
-               if ((p->flags & ps->mask) == ps->res) {
-                       res = page_action(ps, p, pfn);
+       /*
+        * The first check uses the current page flags which may not have any
+        * relevant information. The second check with the saved page flagss is
+        * carried out only if the first check can't determine the page status.
+        */
+       for (ps = error_states;; ps++)
+               if ((p->flags & ps->mask) == ps->res)
                        break;
-               }
-       }
+       if (!ps->mask)
+               for (ps = error_states;; ps++)
+                       if ((page_flags & ps->mask) == ps->res)
+                               break;
+       res = page_action(ps, p, pfn);
 out:
        unlock_page(hpage);
        return res;