Merge tag 'folio-6.0' of git://git.infradead.org/users/willy/pagecache
[platform/kernel/linux-starfive.git] / mm / memory-failure.c
index a859486..b864c2e 100644 (file)
@@ -69,6 +69,8 @@ int sysctl_memory_failure_recovery __read_mostly = 1;
 
 atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
 
+static bool hw_memory_failure __read_mostly = false;
+
 static bool __page_handle_poison(struct page *page)
 {
        int ret;
@@ -1768,6 +1770,9 @@ int memory_failure(unsigned long pfn, int flags)
 
        mutex_lock(&mf_mutex);
 
+       if (!(flags & MF_SW_SIMULATED))
+               hw_memory_failure = true;
+
        p = pfn_to_online_page(pfn);
        if (!p) {
                res = arch_memory_failure(pfn, flags);
@@ -2103,6 +2108,13 @@ int unpoison_memory(unsigned long pfn)
 
        mutex_lock(&mf_mutex);
 
+       if (hw_memory_failure) {
+               unpoison_pr_info("Unpoison: Disabled after HW memory failure %#lx\n",
+                                pfn, &unpoison_rs);
+               ret = -EOPNOTSUPP;
+               goto unlock_mutex;
+       }
+
        if (!PageHWPoison(p)) {
                unpoison_pr_info("Unpoison: Page was already unpoisoned %#lx\n",
                                 pfn, &unpoison_rs);