
From: Jane Chu <jane.chu@oracle.com> mainline inclusion from mainline-v6.11-rc1 commit 9b0ab153d76972a3bee4f363058ff06edf9255a3 category: feature bugzilla: https://gitee.com/src-openeuler/kernel/issues/ICTDP9 CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- Move hwpoison_filter() higher up as there is no need to spend a lot cycles only to find out later that the page is supposed to be skipped from hwpoison handling. Link: https://lkml.kernel.org/r/20240524215306.2705454-5-jane.chu@oracle.com Signed-off-by: Jane Chu <jane.chu@oracle.com> Reviewed-by: Oscar Salvador <osalvador@suse.de> Acked-by: Miaohe Lin <linmiaohe@huawei.com> Cc: Naoya Horiguchi <nao.horiguchi@gmail.com> Cc: Oscar Salvador <oalvador@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Conflicts: mm/memory-failure.c [context conflict] Signed-off-by: Tong Tiangen <tongtiangen@huawei.com> --- mm/memory-failure.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 22556ef8aadd..5139ff34b83e 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2305,6 +2305,17 @@ int memory_failure(unsigned long pfn, int flags) } } + /* filter pages that are protected from hwpoison test by users */ + lock_page(p); + if (hwpoison_filter(p)) { + ClearPageHWPoison(p); + unlock_page(p); + put_page(p); + res = -EOPNOTSUPP; + goto unlock_mutex; + } + unlock_page(p); + hpage = compound_head(p); if (PageTransHuge(hpage)) { /* @@ -2368,14 +2379,6 @@ int memory_failure(unsigned long pfn, int flags) */ page_flags = p->flags; - if (hwpoison_filter(p)) { - ClearPageHWPoison(p); - unlock_page(p); - put_page(p); - res = -EOPNOTSUPP; - goto unlock_mutex; - } - /* * __munlock_folio() may clear a writeback page's LRU flag without * page_lock. We need wait writeback completion for this page or it -- 2.25.1