Skip to contentSkip to conversation

A few fixup patches for memory failure

PATCH Superseded Miaohe Lin 4 participants 27 messages Feb 28, 2022 – Mar 11, 2022

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Miaohe Lin

author maintainer
#0 lore raw

cover A few fixup patches for memory failure

Hi everyone,
This series contains a few patches to fix the race with changing page compound page, fix potential VM_BUG_ON_PAGE and so on. More details can be found in the respective changelogs. Thanks!

Miaohe Lin (4):
mm/memory-failure.c: fix race with changing page compound again mm/memory-failure.c: fix wrong user reference report mm/memory-failure.c: avoid calling invalidate_inode_page() with
unexpected pages
mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in
split_huge_page_to_list

 mm/memory-failure.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)
Signature · 1 line
2.23.0
author maintainer
#1 lore raw

PATCH 1/4 mm/memory-failure.c: fix race with changing page compound again

There is a race window where we got the compound_head, the hugetlb page could be freed to buddy, or even changed to another compound page just before we try to get hwpoison page. If this happens, just bail out.

---
 mm/memory-failure.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
mm/memory-failure.c +11 -0
index 5444a8ef4867..0d7c58340a98 100644
@@ -1534,6 +1534,17 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags)
 	}
 
 	lock_page(head);
+
+	/**
+	 * The page could have changed compound pages due to race window.
+	 * If this happens just bail out.
+	 */
+	if (!PageHuge(p) || compound_head(p) != head) {
+		action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED);
+		res = -EBUSY;
+		goto out;
+	}
+
 	page_flags = head->flags;
 
 	if (hwpoison_filter(p)) {
Signature · 1 line
2.23.0
#2 lore raw

Re: [PATCH 1/4] mm/memory-failure.c: fix race with changing page compound again

Quoted 3 lines · Miaohe Lin

There is a race window where we got the compound_head, the hugetlb page could be freed to buddy, or even changed to another compound page just before we try to get hwpoison page. If this happens, just bail out.

I think that when some hugetlb page is about to change into other type/size of compound page, it has to go through buddy allocator because hugetlb pages are maintained in separate memory allocator and they never change into other normal state directly. memory_failure_hugetlb() takes refcount before lock_page(), so the hugetlb page seems not change between get_hwpoison_page() and lock_page(). So it this new check really necessary?

Thanks,
Naoya Horiguchi

Quoted 30 lines
---
 mm/memory-failure.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
mm/memory-failure.c +11 -0
index 5444a8ef4867..0d7c58340a98 100644
@@ -1534,6 +1534,17 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags)
 	}
 
 	lock_page(head);
+
+	/**
+	 * The page could have changed compound pages due to race window.
+	 * If this happens just bail out.
+	 */
+	if (!PageHuge(p) || compound_head(p) != head) {
+		action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED);
+		res = -EBUSY;
+		goto out;
+	}
+
 	page_flags = head->flags;
 
 	if (hwpoison_filter(p)) {
Signature · 1 line
2.23.0
#3 lore raw

Re: [PATCH 1/4] mm/memory-failure.c: fix race with changing page compound again

Quoted 11 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 3 lines · Miaohe Lin

There is a race window where we got the compound_head, the hugetlb page could be freed to buddy, or even changed to another compound page just before we try to get hwpoison page. If this happens, just bail out.

I think that when some hugetlb page is about to change into other type/size of compound page, it has to go through buddy allocator because hugetlb pages are maintained in separate memory allocator and they never change into other normal state directly. memory_failure_hugetlb() takes refcount before lock_page(), so the hugetlb page seems not change between get_hwpoison_page() and lock_page(). So it this new check really necessary?

A hugetlb page could change size without going through buddy via the new demote functionality [1]. Only hugetlb pages on the hugetlb free list can be demoted.

We should not demote a page if poison is set. However, there is no check in the demote code. IIUC, poison is set early in the memory error handling process, even before taking ref on page. Demote code needs to be fixed so that poisoned pages are not demoted. I can do that.

With this change in place, then I think Naoya's statement that hugetlb pages can not change state is correct and this patch is not necessary.

Does that sound reasonable?

[1] https://lore.kernel.org/linux-mm/[email protected]/

Signature · 1 line
Mike Kravetz
author maintainer
#4 lore raw

Re: [PATCH 1/4] mm/memory-failure.c: fix race with changing page compound again

Quoted 17 lines · Mike Kravetz
Quoted 11 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 3 lines · Miaohe Lin

There is a race window where we got the compound_head, the hugetlb page could be freed to buddy, or even changed to another compound page just before we try to get hwpoison page. If this happens, just bail out.

I think that when some hugetlb page is about to change into other type/size of compound page, it has to go through buddy allocator because hugetlb pages are maintained in separate memory allocator and they never change into other normal state directly. memory_failure_hugetlb() takes refcount before lock_page(), so the hugetlb page seems not change between get_hwpoison_page() and lock_page(). So it this new check really necessary?

A hugetlb page could change size without going through buddy via the new demote functionality [1]. Only hugetlb pages on the hugetlb free list can be demoted.

Quoted 8 lines

We should not demote a page if poison is set. However, there is no check in the demote code. IIUC, poison is set early in the memory error handling process, even before taking ref on page. Demote code needs to be fixed so that poisoned pages are not demoted. I can do that.

With this change in place, then I think Naoya's statement that hugetlb pages can not change state is correct and this patch is not necessary.

Sorry for my confusing commit words. What I mean to tell is indeed the below race:
CPU 1 CPU 2
memory_failure_hugetlb
struct page *head = compound_head(p);
hugetlb page is freed to buddy, or even changed to another compound page as we haven't held the page refcnt now
get_hwpoison_page -- page is not what we want now...

Does this make sense for both of you? Many thanks for comment and reply! :)

Quoted 3 lines

Does that sound reasonable?

[1] https://lore.kernel.org/linux-mm/[email protected]/

This is really a nice feature. Thanks.

Quoted 1 line
#5 lore raw

Re: [PATCH 1/4] mm/memory-failure.c: fix race with changing page compound again

Quoted 36 lines · Miaohe Lin
Quoted 17 lines · Mike Kravetz
Quoted 11 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 3 lines · Miaohe Lin

There is a race window where we got the compound_head, the hugetlb page could be freed to buddy, or even changed to another compound page just before we try to get hwpoison page. If this happens, just bail out.

I think that when some hugetlb page is about to change into other type/size of compound page, it has to go through buddy allocator because hugetlb pages are maintained in separate memory allocator and they never change into other normal state directly. memory_failure_hugetlb() takes refcount before lock_page(), so the hugetlb page seems not change between get_hwpoison_page() and lock_page(). So it this new check really necessary?

A hugetlb page could change size without going through buddy via the new demote functionality [1]. Only hugetlb pages on the hugetlb free list can be demoted.

Quoted 8 lines

We should not demote a page if poison is set. However, there is no check in the demote code. IIUC, poison is set early in the memory error handling process, even before taking ref on page. Demote code needs to be fixed so that poisoned pages are not demoted. I can do that.

With this change in place, then I think Naoya's statement that hugetlb pages can not change state is correct and this patch is not necessary.

Sorry for my confusing commit words. What I mean to tell is indeed the below race:
CPU 1 CPU 2
memory_failure_hugetlb
struct page *head = compound_head(p);
hugetlb page is freed to buddy, or even changed to another compound page as we haven't held the page refcnt now
get_hwpoison_page -- page is not what we want now...

Quoted 1 line

Does this make sense for both of you? Many thanks for comment and reply! :)

Thanks for elaboration, I agree with you (I simply overlooked this race, sorry). And please add this in the commit log.

mm/memory-failure.c static int memory_failure_hugetlb(unsigned long pfn, int flags) · line 1546

Quoted 10 lines
mm/memory-failure.c +10 -0
+
+       /**
+        * The page could have changed compound pages due to race window.
+        * If this happens just bail out.
+        */
+       if (!PageHuge(p) || compound_head(p) != head) {
+               action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED);
+               res = -EBUSY;
+               goto out;
+       }

Let me have one comment on the diff. The result code MF_MSG_DIFFERENT_COMPOUND might not fit when PageHuge is false in the check (because it's no longer a compound page). Maybe you may invent another result code, or changes MF_MSG_DIFFERENT_COMPOUND (for example) to MF_MSG_DIFFERENT_PAGE_SIZE?

Quoted 6 lines
Quoted 4 lines

Does that sound reasonable?

[1] https://lore.kernel.org/linux-mm/[email protected]/

This is really a nice feature. Thanks.

Yes. Hugepage demotion after entering memory_failure_hugetlb() should cause the race, so we need the check after page lock.

Thanks,
Naoya Horiguchi

#6 lore raw

Re: [PATCH 1/4] mm/memory-failure.c: fix race with changing page compound again

Quoted 37 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 36 lines · Miaohe Lin
Quoted 17 lines · Mike Kravetz
Quoted 11 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 3 lines · Miaohe Lin

There is a race window where we got the compound_head, the hugetlb page could be freed to buddy, or even changed to another compound page just before we try to get hwpoison page. If this happens, just bail out.

I think that when some hugetlb page is about to change into other type/size of compound page, it has to go through buddy allocator because hugetlb pages are maintained in separate memory allocator and they never change into other normal state directly. memory_failure_hugetlb() takes refcount before lock_page(), so the hugetlb page seems not change between get_hwpoison_page() and lock_page(). So it this new check really necessary?

A hugetlb page could change size without going through buddy via the new demote functionality [1]. Only hugetlb pages on the hugetlb free list can be demoted.

Quoted 8 lines

We should not demote a page if poison is set. However, there is no check in the demote code. IIUC, poison is set early in the memory error handling process, even before taking ref on page. Demote code needs to be fixed so that poisoned pages are not demoted. I can do that.

With this change in place, then I think Naoya's statement that hugetlb pages can not change state is correct and this patch is not necessary.

Sorry for my confusing commit words. What I mean to tell is indeed the below race:
CPU 1 CPU 2
memory_failure_hugetlb
struct page *head = compound_head(p);
hugetlb page is freed to buddy, or even changed to another compound page as we haven't held the page refcnt now
get_hwpoison_page -- page is not what we want now...

Quoted 3 lines
Quoted 1 line

Does this make sense for both of you? Many thanks for comment and reply! :)

Thanks for elaboration, I agree with you (I simply overlooked this race, sorry).

Yes, thank you.

Quoted 13 lines

And please add this in the commit log.

mm/memory-failure.c static int memory_failure_hugetlb(unsigned long pfn, int flags) · line 1546

Quoted 10 lines
mm/memory-failure.c +10 -0
+
+       /**
+        * The page could have changed compound pages due to race window.
+        * If this happens just bail out.
+        */
+       if (!PageHuge(p) || compound_head(p) != head) {
+               action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED);
+               res = -EBUSY;
+               goto out;
+       }
Quoted 5 lines

Let me have one comment on the diff. The result code MF_MSG_DIFFERENT_COMPOUND might not fit when PageHuge is false in the check (because it's no longer a compound page). Maybe you may invent another result code, or changes MF_MSG_DIFFERENT_COMPOUND (for example) to MF_MSG_DIFFERENT_PAGE_SIZE?

Suppose we do encounter this race. Also, suppose p != head. At the beginning of memory_failure_hugetlb, we do:

struct page *head = compound_head(p);
...
if (TestSetPageHWPoison(head))

So, it could be that we set Poison in the 'head' page but the error was really in another page. Is that correct?

Now with the race, head is not a huge page and the pages could even be on buddy. Does this mean we could have poison set on the wrong page in buddy?

Signature · 1 line
Mike Kravetz
#7 lore raw

Re: [PATCH 1/4] mm/memory-failure.c: fix race with changing page compound again

On Mon, Mar 07, 2022 at 11:07:32AM -0800, Mike Kravetz wrote:
...

Quoted 25 lines
Quoted 12 lines

mm/memory-failure.c static int memory_failure_hugetlb(unsigned long pfn, int flags) · line 1546

Quoted 11 lines
mm/memory-failure.c +10 -0
+
+       /**
+        * The page could have changed compound pages due to race window.
+        * If this happens just bail out.
+        */
+       if (!PageHuge(p) || compound_head(p) != head) {
+               action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED);
+               res = -EBUSY;
+               goto out;
+       }
Quoted 5 lines

Let me have one comment on the diff. The result code MF_MSG_DIFFERENT_COMPOUND might not fit when PageHuge is false in the check (because it's no longer a compound page). Maybe you may invent another result code, or changes MF_MSG_DIFFERENT_COMPOUND (for example) to MF_MSG_DIFFERENT_PAGE_SIZE?

Suppose we do encounter this race. Also, suppose p != head. At the beginning of memory_failure_hugetlb, we do:

struct page *head = compound_head(p);
...
if (TestSetPageHWPoison(head))

Quoted 5 lines

So, it could be that we set Poison in the 'head' page but the error was really in another page. Is that correct?

Now with the race, head is not a huge page and the pages could even be on buddy. Does this mean we could have poison set on the wrong page in buddy?

Correct, the race might be rare, but this needs a fix.
I think that setting PageHWPoison first (before taking refcount and page lock) is the root of all related problems. This behavior came from the original concept in hwpoison that preventing consumption of corrupted data is the first priority. But now I think that this makes no sense if we have this kind of bugs.

I'll try to write a patch for this (I only fix memory_failure_hugetlb() first, but generic path should be fixed later).
Thank you for pointing out.

- Naoya Horiguchi

author maintainer
#8 lore raw

Re: [PATCH 1/4] mm/memory-failure.c: fix race with changing page compound again

Quoted 39 lines · HORIGUCHI NAOYA(堀口 直也)

On Mon, Mar 07, 2022 at 11:07:32AM -0800, Mike Kravetz wrote:
...

Quoted 25 lines
Quoted 12 lines

Review

Quoted 11 lines
(quoted diff) +10 -0
+
+       /**
+        * The page could have changed compound pages due to race window.
+        * If this happens just bail out.
+        */
+       if (!PageHuge(p) || compound_head(p) != head) {
+               action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED);
+               res = -EBUSY;
+               goto out;
+       }
Quoted 5 lines

Let me have one comment on the diff. The result code MF_MSG_DIFFERENT_COMPOUND might not fit when PageHuge is false in the check (because it's no longer a compound page). Maybe you may invent another result code, or changes MF_MSG_DIFFERENT_COMPOUND (for example) to MF_MSG_DIFFERENT_PAGE_SIZE?

Suppose we do encounter this race. Also, suppose p != head. At the beginning of memory_failure_hugetlb, we do:

struct page *head = compound_head(p);
...
if (TestSetPageHWPoison(head))

Quoted 5 lines

So, it could be that we set Poison in the 'head' page but the error was really in another page. Is that correct?

Now with the race, head is not a huge page and the pages could even be on buddy. Does this mean we could have poison set on the wrong page in buddy?

Correct, the race might be rare, but this needs a fix.
I think that setting PageHWPoison first (before taking refcount and page lock) is the root of all related problems. This behavior came from the original concept in hwpoison that preventing consumption of corrupted data is the first priority. But now I think that this makes no sense if we have this kind of bugs.

Quoted 3 lines

I'll try to write a patch for this (I only fix memory_failure_hugetlb() first, but generic path should be fixed later).
Thank you for pointing out.

Many thanks for both of you for doing this. :)

Quoted 3 lines

- Naoya Horiguchi

author maintainer
#9 lore raw

PATCH 2/4 mm/memory-failure.c: fix wrong user reference report

In reply to Miaohe Lin

The dirty swapcache page is still residing in the swap cache after it's hwpoisoned. So there is always one extra refcount for swap cache.

---
 mm/memory-failure.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
mm/memory-failure.c +1 -5
index 0d7c58340a98..5f9503573263 100644
@@ -984,7 +984,6 @@ static int me_pagecache_dirty(struct page_state *ps, struct page *p)
 static int me_swapcache_dirty(struct page_state *ps, struct page *p)
 {
 	int ret;
-	bool extra_pins = false;
 
 	ClearPageDirty(p);
 	/* Trigger EIO in shmem: */
@@ -993,10 +992,7 @@ static int me_swapcache_dirty(struct page_state *ps, struct page *p)
 	ret = delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED;
 	unlock_page(p);
 
-	if (ret == MF_DELAYED)
-		extra_pins = true;
-
-	if (has_extra_refcount(ps, p, extra_pins))
+	if (has_extra_refcount(ps, p, true))
 		ret = MF_FAILED;
 
 	return ret;
Signature · 1 line
2.23.0
#10 lore raw

Re: [PATCH 2/4] mm/memory-failure.c: fix wrong user reference report

Quoted 2 lines · Miaohe Lin

The dirty swapcache page is still residing in the swap cache after it's hwpoisoned. So there is always one extra refcount for swap cache.

The diff seems fine at a glance, but let me have a few question to understand the issue more.

- Is the behavior described above the effect of recent change on shmem where dirty pagecache is pinned on hwpoison (commit a76054266661 ("mm: shmem:
don't truncate page if memory failure happens"). Or the older kernels behave as the same?

- Is the behavior true for normal anonymous pages (not shmem pages)?

I'm trying to test hwpoison hitting the dirty swapcache, but it seems that in my testing memory_faliure() fails with "hwpoison: unhandlable page" warning at get_any_page(). So I'm still not sure that me_pagecache_dirty() fixes any visible problem.

Thanks,
Naoya Horiguchi

Quoted 32 lines
---
 mm/memory-failure.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
mm/memory-failure.c +1 -5
index 0d7c58340a98..5f9503573263 100644
@@ -984,7 +984,6 @@ static int me_pagecache_dirty(struct page_state *ps, struct page *p)
 static int me_swapcache_dirty(struct page_state *ps, struct page *p)
 {
 	int ret;
-	bool extra_pins = false;
 
 	ClearPageDirty(p);
 	/* Trigger EIO in shmem: */
@@ -993,10 +992,7 @@ static int me_swapcache_dirty(struct page_state *ps, struct page *p)
 	ret = delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED;
 	unlock_page(p);
 
-	if (ret == MF_DELAYED)
-		extra_pins = true;
-
-	if (has_extra_refcount(ps, p, extra_pins))
+	if (has_extra_refcount(ps, p, true))
 		ret = MF_FAILED;
 
 	return ret;
Signature · 1 line
2.23.0
author maintainer
#11 lore raw

Re: [PATCH 2/4] mm/memory-failure.c: fix wrong user reference report

Quoted 7 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 2 lines · Miaohe Lin

The dirty swapcache page is still residing in the swap cache after it's hwpoisoned. So there is always one extra refcount for swap cache.

The diff seems fine at a glance, but let me have a few question to understand the issue more.

Quoted 7 lines

- Is the behavior described above the effect of recent change on shmem where dirty pagecache is pinned on hwpoison (commit a76054266661 ("mm: shmem:
don't truncate page if memory failure happens"). Or the older kernels behave as the same?

- Is the behavior true for normal anonymous pages (not shmem pages)?

The behavior described above is aimed at swapcache not pagecache. So it should be irrelevant with the recent change on shmem.

What I try to fix here is that me_swapcache_dirty holds one extra pin via SwapCache regardless of the return value of delete_from_lru_cache. We should try to report more accurate extra refcount for debugging purpose.

Quoted 2 lines

I'm trying to test hwpoison hitting the dirty swapcache, but it seems that in my testing memory_faliure() fails with "hwpoison: unhandlable page"

Maybe memory_faliure is racing with page reclaim where page is isolated?

Quoted 2 lines

warning at get_any_page(). So I'm still not sure that me_pagecache_dirty() fixes any visible problem.

IIUC, me_pagecache_dirty can't do much except for the corresponding address_space supporting error_remove_page which can truncate the dirty pagecache page. But this may cause silent data loss. It's better to keep the page stay in the pagecache until the file is truncated, hole punched or removed as commit a76054266661 pointed out.

Thanks.

Quoted 35 lines
Quoted 1 line

Thanks,

Naoya Horiguchi

Quoted 32 lines
---
 mm/memory-failure.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
mm/memory-failure.c +1 -5
index 0d7c58340a98..5f9503573263 100644
@@ -984,7 +984,6 @@ static int me_pagecache_dirty(struct page_state *ps, struct page *p)
 static int me_swapcache_dirty(struct page_state *ps, struct page *p)
 {
 	int ret;
-	bool extra_pins = false;
 
 	ClearPageDirty(p);
 	/* Trigger EIO in shmem: */
@@ -993,10 +992,7 @@ static int me_swapcache_dirty(struct page_state *ps, struct page *p)
 	ret = delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED;
 	unlock_page(p);
 
-	if (ret == MF_DELAYED)
-		extra_pins = true;
-
-	if (has_extra_refcount(ps, p, extra_pins))
+	if (has_extra_refcount(ps, p, true))
 		ret = MF_FAILED;
 
 	return ret;
Signature · 1 line
2.23.0
#12 lore raw

Re: [PATCH 2/4] mm/memory-failure.c: fix wrong user reference report

Quoted 17 lines · Miaohe Lin
Quoted 7 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 2 lines · Miaohe Lin

The dirty swapcache page is still residing in the swap cache after it's hwpoisoned. So there is always one extra refcount for swap cache.

The diff seems fine at a glance, but let me have a few question to understand the issue more.

Quoted 7 lines

- Is the behavior described above the effect of recent change on shmem where dirty pagecache is pinned on hwpoison (commit a76054266661 ("mm: shmem:
don't truncate page if memory failure happens"). Or the older kernels behave as the same?

- Is the behavior true for normal anonymous pages (not shmem pages)?

Quoted 6 lines

The behavior described above is aimed at swapcache not pagecache. So it should be irrelevant with the recent change on shmem.

What I try to fix here is that me_swapcache_dirty holds one extra pin via SwapCache regardless of the return value of delete_from_lru_cache. We should try to report more accurate extra refcount for debugging purpose.

I think you misunderstood the code. The delete_from_lru_cache() returning 0 means the page was on LRU and isolated from LRU successfully now. Returning -EIO means the page was not on LRU, so it should have at least an extra pin on it.

So MF_DELAYED means there is no other pin other than hwpoison and swapcache which is expected, MF_FAILED means there might be extra pins.

The has_extra_refcount() raised error then there is *unexpected* refcount.

Quoted 53 lines
Quoted 3 lines

I'm trying to test hwpoison hitting the dirty swapcache, but it seems that in my testing memory_faliure() fails with "hwpoison: unhandlable page"

Maybe memory_faliure is racing with page reclaim where page is isolated?

Quoted 2 lines

warning at get_any_page(). So I'm still not sure that me_pagecache_dirty() fixes any visible problem.

IIUC, me_pagecache_dirty can't do much except for the corresponding address_space supporting error_remove_page which can truncate the dirty pagecache page. But this may cause silent data loss. It's better to keep the page stay in the pagecache until the file is truncated, hole punched or removed as commit a76054266661 pointed out.

Thanks.

Quoted 35 lines
Quoted 1 line

Thanks,

Naoya Horiguchi

Quoted 32 lines
---
 mm/memory-failure.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
mm/memory-failure.c +1 -6
index 0d7c58340a98..5f9503573263 100644
@@ -984,7 +984,6 @@ static int me_pagecache_dirty(struct page_state *ps, struct page *p)
 static int me_swapcache_dirty(struct page_state *ps, struct page *p)
 {
     int ret;
-    bool extra_pins = false;
 
     ClearPageDirty(p);
     /* Trigger EIO in shmem: */
@@ -993,10 +992,7 @@ static int me_swapcache_dirty(struct page_state *ps, struct page *p)
     ret = delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED;
     unlock_page(p);
 
-    if (ret == MF_DELAYED)
-            extra_pins = true;
-
-    if (has_extra_refcount(ps, p, extra_pins))
+    if (has_extra_refcount(ps, p, true))
             ret = MF_FAILED;
 
     return ret;
--

2.23.0

author maintainer
#13 lore raw

Re: [PATCH 2/4] mm/memory-failure.c: fix wrong user reference report

Quoted 30 lines · Yang Shi
Quoted 17 lines · Miaohe Lin
Quoted 7 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 2 lines · Miaohe Lin

The dirty swapcache page is still residing in the swap cache after it's hwpoisoned. So there is always one extra refcount for swap cache.

The diff seems fine at a glance, but let me have a few question to understand the issue more.

Quoted 7 lines

- Is the behavior described above the effect of recent change on shmem where dirty pagecache is pinned on hwpoison (commit a76054266661 ("mm: shmem:
don't truncate page if memory failure happens"). Or the older kernels behave as the same?

- Is the behavior true for normal anonymous pages (not shmem pages)?

Quoted 6 lines

The behavior described above is aimed at swapcache not pagecache. So it should be irrelevant with the recent change on shmem.

What I try to fix here is that me_swapcache_dirty holds one extra pin via SwapCache regardless of the return value of delete_from_lru_cache. We should try to report more accurate extra refcount for debugging purpose.

I think you misunderstood the code. The delete_from_lru_cache() returning 0 means the page was on LRU and isolated from LRU successfully now. Returning -EIO means the page was not on LRU, so it should have at least an extra pin on it.

Quoted 5 lines

So MF_DELAYED means there is no other pin other than hwpoison and swapcache which is expected, MF_FAILED means there might be extra pins.

The has_extra_refcount() raised error then there is *unexpected* refcount.

Many thanks for your explanation. It seems you're right. If page is held on the lru_pvecs when we try to do delete_from_lru_cache, and after that it's drained to the lru list( so its refcnt might be 2 now). Then we might have the following complain if extra_pins is always true:
"Memory failure: ... still referenced by 0 users\n"

But it seems the origin code can not report the correct reason too because if we retry, page can be delete_from_lru_cache and we can succeed now.

Anyway, many thanks for pointing this out.

Quoted 56 lines
Quoted 49 lines
Quoted 4 lines

I'm trying to test hwpoison hitting the dirty swapcache, but it seems that in my testing memory_faliure() fails with "hwpoison: unhandlable page"

Maybe memory_faliure is racing with page reclaim where page is isolated?

Quoted 2 lines

warning at get_any_page(). So I'm still not sure that me_pagecache_dirty() fixes any visible problem.

IIUC, me_pagecache_dirty can't do much except for the corresponding address_space supporting error_remove_page which can truncate the dirty pagecache page. But this may cause silent data loss. It's better to keep the page stay in the pagecache until the file is truncated, hole punched or removed as commit a76054266661 pointed out.

Thanks.

Quoted 32 lines
Quoted 1 line

Thanks,

Naoya Horiguchi

Quoted 29 lines
---
 mm/memory-failure.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
mm/memory-failure.c +1 -5
index 0d7c58340a98..5f9503573263 100644
@@ -984,7 +984,6 @@ static int me_pagecache_dirty(struct page_state *ps, struct page *p)
 static int me_swapcache_dirty(struct page_state *ps, struct page *p)
 {
     int ret;
-    bool extra_pins = false;
 
     ClearPageDirty(p);
     /* Trigger EIO in shmem: */
@@ -993,10 +992,7 @@ static int me_swapcache_dirty(struct page_state *ps, struct page *p)
     ret = delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED;
     unlock_page(p);
 
-    if (ret == MF_DELAYED)
-            extra_pins = true;
-
-    if (has_extra_refcount(ps, p, extra_pins))
+    if (has_extra_refcount(ps, p, true))
             ret = MF_FAILED;
 
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
mm/memory-failure.c +0 -1
     return ret;
--

2.23.0

.

#14 lore raw

Re: [PATCH 2/4] mm/memory-failure.c: fix wrong user reference report

Quoted 38 lines · Miaohe Lin
Quoted 30 lines · Yang Shi
Quoted 17 lines · Miaohe Lin
Quoted 7 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 2 lines · Miaohe Lin

The dirty swapcache page is still residing in the swap cache after it's hwpoisoned. So there is always one extra refcount for swap cache.

The diff seems fine at a glance, but let me have a few question to understand the issue more.

Quoted 7 lines

- Is the behavior described above the effect of recent change on shmem where dirty pagecache is pinned on hwpoison (commit a76054266661 ("mm: shmem:
don't truncate page if memory failure happens"). Or the older kernels behave as the same?

- Is the behavior true for normal anonymous pages (not shmem pages)?

Quoted 6 lines

The behavior described above is aimed at swapcache not pagecache. So it should be irrelevant with the recent change on shmem.

What I try to fix here is that me_swapcache_dirty holds one extra pin via SwapCache regardless of the return value of delete_from_lru_cache. We should try to report more accurate extra refcount for debugging purpose.

I think you misunderstood the code. The delete_from_lru_cache() returning 0 means the page was on LRU and isolated from LRU successfully now. Returning -EIO means the page was not on LRU, so it should have at least an extra pin on it.

Quoted 5 lines

So MF_DELAYED means there is no other pin other than hwpoison and swapcache which is expected, MF_FAILED means there might be extra pins.

The has_extra_refcount() raised error then there is *unexpected* refcount.

Quoted 8 lines

Many thanks for your explanation. It seems you're right. If page is held on the lru_pvecs when we try to do delete_from_lru_cache, and after that it's drained to the lru list( so its refcnt might be 2 now). Then we might have the following complain if extra_pins is always true:
"Memory failure: ... still referenced by 0 users\n"

But it seems the origin code can not report the correct reason too because if we retry, page can be delete_from_lru_cache and we can succeed now.

Retry is ok, but it seems overkilling to me IMHO.

Quoted 60 lines

Anyway, many thanks for pointing this out.

Quoted 56 lines
Quoted 49 lines
Quoted 4 lines

I'm trying to test hwpoison hitting the dirty swapcache, but it seems that in my testing memory_faliure() fails with "hwpoison: unhandlable page"

Maybe memory_faliure is racing with page reclaim where page is isolated?

Quoted 2 lines

warning at get_any_page(). So I'm still not sure that me_pagecache_dirty() fixes any visible problem.

IIUC, me_pagecache_dirty can't do much except for the corresponding address_space supporting error_remove_page which can truncate the dirty pagecache page. But this may cause silent data loss. It's better to keep the page stay in the pagecache until the file is truncated, hole punched or removed as commit a76054266661 pointed out.

Thanks.

Quoted 32 lines
Quoted 1 line

Thanks,

Naoya Horiguchi

Quoted 29 lines
---
 mm/memory-failure.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
mm/memory-failure.c +1 -5
index 0d7c58340a98..5f9503573263 100644
@@ -984,7 +984,6 @@ static int me_pagecache_dirty(struct page_state *ps, struct page *p)
 static int me_swapcache_dirty(struct page_state *ps, struct page *p)
 {
     int ret;
-    bool extra_pins = false;
 
     ClearPageDirty(p);
     /* Trigger EIO in shmem: */
@@ -993,10 +992,7 @@ static int me_swapcache_dirty(struct page_state *ps, struct page *p)
     ret = delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED;
     unlock_page(p);
 
-    if (ret == MF_DELAYED)
-            extra_pins = true;
-
-    if (has_extra_refcount(ps, p, extra_pins))
+    if (has_extra_refcount(ps, p, true))
             ret = MF_FAILED;
 
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
mm/memory-failure.c +0 -1
     return ret;
--

2.23.0

.

author maintainer
#15 lore raw

Re: [PATCH 2/4] mm/memory-failure.c: fix wrong user reference report

Quoted 45 lines · Yang Shi
Quoted 44 lines · Miaohe Lin
Quoted 30 lines · Yang Shi
Quoted 17 lines · Miaohe Lin
Quoted 7 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 2 lines · Miaohe Lin

The dirty swapcache page is still residing in the swap cache after it's hwpoisoned. So there is always one extra refcount for swap cache.

The diff seems fine at a glance, but let me have a few question to understand the issue more.

Quoted 7 lines

- Is the behavior described above the effect of recent change on shmem where dirty pagecache is pinned on hwpoison (commit a76054266661 ("mm: shmem:
don't truncate page if memory failure happens"). Or the older kernels behave as the same?

- Is the behavior true for normal anonymous pages (not shmem pages)?

Quoted 6 lines

The behavior described above is aimed at swapcache not pagecache. So it should be irrelevant with the recent change on shmem.

What I try to fix here is that me_swapcache_dirty holds one extra pin via SwapCache regardless of the return value of delete_from_lru_cache. We should try to report more accurate extra refcount for debugging purpose.

I think you misunderstood the code. The delete_from_lru_cache() returning 0 means the page was on LRU and isolated from LRU successfully now. Returning -EIO means the page was not on LRU, so it should have at least an extra pin on it.

Quoted 5 lines

So MF_DELAYED means there is no other pin other than hwpoison and swapcache which is expected, MF_FAILED means there might be extra pins.

The has_extra_refcount() raised error then there is *unexpected* refcount.

Many thanks for your explanation. It seems you're right. If page is held on the lru_pvecs when we try to do delete_from_lru_cache, and after that it's drained to the lru list( so its refcnt might be 2 now). Then we might have the following complain if extra_pins is always true:
"Memory failure: ... still referenced by 0 users\n"

Quoted 5 lines
Quoted 2 lines

But it seems the origin code can not report the correct reason too because if we retry, page can be delete_from_lru_cache and we can succeed now.

Retry is ok, but it seems overkilling to me IMHO.

Anyway, it seems I misunderstood the code. So I will drop this patch. Thanks for comment.

Quoted 62 lines
Quoted 60 lines

Anyway, many thanks for pointing this out.

Quoted 56 lines
Quoted 49 lines
Quoted 4 lines

I'm trying to test hwpoison hitting the dirty swapcache, but it seems that in my testing memory_faliure() fails with "hwpoison: unhandlable page"

Maybe memory_faliure is racing with page reclaim where page is isolated?

Quoted 2 lines

warning at get_any_page(). So I'm still not sure that me_pagecache_dirty() fixes any visible problem.

IIUC, me_pagecache_dirty can't do much except for the corresponding address_space supporting error_remove_page which can truncate the dirty pagecache page. But this may cause silent data loss. It's better to keep the page stay in the pagecache until the file is truncated, hole punched or removed as commit a76054266661 pointed out.

Thanks.

Quoted 32 lines
Quoted 1 line

Thanks,

Naoya Horiguchi

Quoted 29 lines
---
 mm/memory-failure.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
mm/memory-failure.c +1 -5
index 0d7c58340a98..5f9503573263 100644
@@ -984,7 +984,6 @@ static int me_pagecache_dirty(struct page_state *ps, struct page *p)
 static int me_swapcache_dirty(struct page_state *ps, struct page *p)
 {
     int ret;
-    bool extra_pins = false;
 
     ClearPageDirty(p);
     /* Trigger EIO in shmem: */
@@ -993,10 +992,7 @@ static int me_swapcache_dirty(struct page_state *ps, struct page *p)
     ret = delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED;
     unlock_page(p);
 
-    if (ret == MF_DELAYED)
-            extra_pins = true;
-
-    if (has_extra_refcount(ps, p, extra_pins))
+    if (has_extra_refcount(ps, p, true))
             ret = MF_FAILED;
 
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
mm/memory-failure.c +0 -1
     return ret;
--

2.23.0

.

.

author maintainer
#16 lore raw

PATCH 3/4 mm/memory-failure.c: avoid calling invalidate_inode_page() with unexpected pages

In reply to Miaohe Lin

Since commit 042c4f32323b ("mm/truncate: Inline invalidate_complete_page() into its one caller"), invalidate_inode_page() can invalidate the pages in the swap cache because the check of page->mapping != mapping is removed. But invalidate_inode_page() is not expected to deal with the pages in swap cache. Also non-lru movable page can reach here too. They're not page cache pages. Skip these pages by checking PageSwapCache and PageLRU.

---
 mm/memory-failure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +1 -1
index 5f9503573263..23bfd809dc8c 100644
@@ -2185,7 +2185,7 @@ static int __soft_offline_page(struct page *page)
 		return 0;
 	}
 
-	if (!PageHuge(page))
+	if (!PageHuge(page) && PageLRU(page) && !PageSwapCache(page))
 		/*
 		 * Try to invalidate first. This should work for
 		 * non dirty unmapped page cache pages.
Signature · 1 line
2.23.0
author maintainer
#17 lore raw

PATCH 4/4 mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list

In reply to Miaohe Lin

The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages.

---
 mm/memory-failure.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
mm/memory-failure.c +14 -0
index 23bfd809dc8c..ac6492e36978 100644
@@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags)
 	}
 
 	if (PageTransHuge(hpage)) {
+		/*
+		 * The non-lru compound movable pages could be taken for
+		 * transhuge pages. Also huge zero page could reach here
+		 * and if we ever try to split it, the VM_BUG_ON_PAGE will
+		 * be triggered in split_huge_page_to_list(). Skip these
+		 * pages by checking PageLRU because huge zero page isn't
+		 * lru page as non-lru compound movable pages.
+		 */
+		if (!PageLRU(hpage)) {
+			put_page(p);
+			action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
+			res = -EBUSY;
+			goto unlock_mutex;
+		}
 		/*
 		 * The flag must be set after the refcount is bumped
 		 * otherwise it may race with THP split.
Signature · 1 line
2.23.0
#18 lore raw

Re: [PATCH 4/4] mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list

Quoted 5 lines · Miaohe Lin

The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages.

It seems that memory_failure() also fails at get_any_page() with "hwpoison:
unhandlable page" message.

  [16478.203474] page:00000000b6acdbd1 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1810b4
  [16478.206612] flags: 0x57ffffc0801000(reserved|hwpoison|node=1|zone=2|lastcpupid=0x1fffff)
  [16478.209411] raw: 0057ffffc0801000 fffff11bc6042d08 fffff11bc6042d08 0000000000000000
  [16478.211921] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
  [16478.214473] page dumped because: hwpoison: unhandlable page
  [16478.216386] Memory failure: 0x1810b4: recovery action for unknown page: Ignored

We can't handle errors on huge (or normal) zero page, so the current behavior seems to me more suitable than "unsplit thp".

Or if you have some producer to reach the following path with huge zero page, could you share it?

Thanks,
Naoya Horiguchi

Quoted 33 lines
---
 mm/memory-failure.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
mm/memory-failure.c +14 -0
index 23bfd809dc8c..ac6492e36978 100644
@@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags)
 	}
 
 	if (PageTransHuge(hpage)) {
+		/*
+		 * The non-lru compound movable pages could be taken for
+		 * transhuge pages. Also huge zero page could reach here
+		 * and if we ever try to split it, the VM_BUG_ON_PAGE will
+		 * be triggered in split_huge_page_to_list(). Skip these
+		 * pages by checking PageLRU because huge zero page isn't
+		 * lru page as non-lru compound movable pages.
+		 */
+		if (!PageLRU(hpage)) {
+			put_page(p);
+			action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
+			res = -EBUSY;
+			goto unlock_mutex;
+		}
 		/*
 		 * The flag must be set after the refcount is bumped
 		 * otherwise it may race with THP split.
Signature · 1 line
2.23.0
author maintainer
#19 lore raw

Re: [PATCH 4/4] mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list

Quoted 10 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 5 lines · Miaohe Lin

The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages.

It seems that memory_failure() also fails at get_any_page() with "hwpoison:
unhandlable page" message.

Quoted 8 lines
  [16478.203474] page:00000000b6acdbd1 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1810b4
  [16478.206612] flags: 0x57ffffc0801000(reserved|hwpoison|node=1|zone=2|lastcpupid=0x1fffff)
  [16478.209411] raw: 0057ffffc0801000 fffff11bc6042d08 fffff11bc6042d08 0000000000000000
  [16478.211921] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
  [16478.214473] page dumped because: hwpoison: unhandlable page
  [16478.216386] Memory failure: 0x1810b4: recovery action for unknown page: Ignored

We can't handle errors on huge (or normal) zero page, so the current

Sorry for confusing commit log again. I should have a coffee before I make this patch. Huge or normal zero page will fail at get_any_page because they're neither HWPoisonHandlable nor PageHuge.

Quoted 5 lines

behavior seems to me more suitable than "unsplit thp".

Or if you have some producer to reach the following path with huge zero page, could you share it?

What I mean is that non-lru movable compound page can reach here unexpected because __PageMovable(page) is handleable now. So get_any_page could succeed to grab the page refcnt. And since it's compound page, it will go through the split_huge_page_to_list because PageTransHuge checks PageHead(page) which can also be true for compound page. But this type of pages is unexpected for split_huge_page_to_list.

Does this make sense for you? Thanks Naoya.

Quoted 36 lines

Thanks,
Naoya Horiguchi

Quoted 33 lines
---
 mm/memory-failure.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
mm/memory-failure.c +14 -0
index 23bfd809dc8c..ac6492e36978 100644
@@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags)
 	}
 
 	if (PageTransHuge(hpage)) {
+		/*
+		 * The non-lru compound movable pages could be taken for
+		 * transhuge pages. Also huge zero page could reach here
+		 * and if we ever try to split it, the VM_BUG_ON_PAGE will
+		 * be triggered in split_huge_page_to_list(). Skip these
+		 * pages by checking PageLRU because huge zero page isn't
+		 * lru page as non-lru compound movable pages.
+		 */
+		if (!PageLRU(hpage)) {
+			put_page(p);
+			action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
+			res = -EBUSY;
+			goto unlock_mutex;
+		}
 		/*
 		 * The flag must be set after the refcount is bumped
 		 * otherwise it may race with THP split.
Signature · 1 line
2.23.0
#20 lore raw

Re: [PATCH 4/4] mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list

Quoted 27 lines · Miaohe Lin
Quoted 10 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 5 lines · Miaohe Lin

The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages.

It seems that memory_failure() also fails at get_any_page() with "hwpoison:
unhandlable page" message.

Quoted 8 lines
  [16478.203474] page:00000000b6acdbd1 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1810b4
  [16478.206612] flags: 0x57ffffc0801000(reserved|hwpoison|node=1|zone=2|lastcpupid=0x1fffff)
  [16478.209411] raw: 0057ffffc0801000 fffff11bc6042d08 fffff11bc6042d08 0000000000000000
  [16478.211921] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
  [16478.214473] page dumped because: hwpoison: unhandlable page
  [16478.216386] Memory failure: 0x1810b4: recovery action for unknown page: Ignored

We can't handle errors on huge (or normal) zero page, so the current

Sorry for confusing commit log again. I should have a coffee before I make this patch. Huge or normal zero page will fail at get_any_page because they're neither HWPoisonHandlable nor PageHuge.

Quoted 2 lines

behavior seems to me more suitable than "unsplit thp".

Quoted 8 lines
Quoted 3 lines

Or if you have some producer to reach the following path with huge zero page, could you share it?

What I mean is that non-lru movable compound page can reach here unexpected because __PageMovable(page) is handleable now. So get_any_page could succeed to grab the page refcnt. And since it's compound page, it will go through the split_huge_page_to_list because PageTransHuge checks PageHead(page) which can also be true for compound page. But this type of pages is unexpected for split_huge_page_to_list.

Can we really handle non-LRU movable pages in memory failure (uncorrectable errors)? Typically they are balloon, zsmalloc, etc. Assuming we run into a base (4K) non-LRU movable page, we could reach as far as identify_page_state(), it should not fall into any category except me_unknown. So it seems we could just simply make it unhandlable.

But it should be handlable for soft-offline since it could be migrated.

Quoted 40 lines

Does this make sense for you? Thanks Naoya.

Quoted 36 lines

Thanks,
Naoya Horiguchi

Quoted 33 lines
---
 mm/memory-failure.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
mm/memory-failure.c +14 -1
index 23bfd809dc8c..ac6492e36978 100644
@@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags)
     }
 
     if (PageTransHuge(hpage)) {
+            /*
+             * The non-lru compound movable pages could be taken for
+             * transhuge pages. Also huge zero page could reach here
+             * and if we ever try to split it, the VM_BUG_ON_PAGE will
+             * be triggered in split_huge_page_to_list(). Skip these
+             * pages by checking PageLRU because huge zero page isn't
+             * lru page as non-lru compound movable pages.
+             */
+            if (!PageLRU(hpage)) {
+                    put_page(p);
+                    action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
+                    res = -EBUSY;
+                    goto unlock_mutex;
+            }
             /*
              * The flag must be set after the refcount is bumped
              * otherwise it may race with THP split.
--

2.23.0

author maintainer
#21 lore raw

Re: [PATCH 4/4] mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list

Quoted 37 lines · Yang Shi
Quoted 27 lines · Miaohe Lin
Quoted 10 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 5 lines · Miaohe Lin

The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages.

It seems that memory_failure() also fails at get_any_page() with "hwpoison:
unhandlable page" message.

Quoted 8 lines
  [16478.203474] page:00000000b6acdbd1 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1810b4
  [16478.206612] flags: 0x57ffffc0801000(reserved|hwpoison|node=1|zone=2|lastcpupid=0x1fffff)
  [16478.209411] raw: 0057ffffc0801000 fffff11bc6042d08 fffff11bc6042d08 0000000000000000
  [16478.211921] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
  [16478.214473] page dumped because: hwpoison: unhandlable page
  [16478.216386] Memory failure: 0x1810b4: recovery action for unknown page: Ignored

We can't handle errors on huge (or normal) zero page, so the current

Sorry for confusing commit log again. I should have a coffee before I make this patch. Huge or normal zero page will fail at get_any_page because they're neither HWPoisonHandlable nor PageHuge.

Quoted 2 lines

behavior seems to me more suitable than "unsplit thp".

Quoted 8 lines
Quoted 3 lines

Or if you have some producer to reach the following path with huge zero page, could you share it?

What I mean is that non-lru movable compound page can reach here unexpected because __PageMovable(page) is handleable now. So get_any_page could succeed to grab the page refcnt. And since it's compound page, it will go through the split_huge_page_to_list because PageTransHuge checks PageHead(page) which can also be true for compound page. But this type of pages is unexpected for split_huge_page_to_list.

Quoted 6 lines

Can we really handle non-LRU movable pages in memory failure (uncorrectable errors)? Typically they are balloon, zsmalloc, etc. Assuming we run into a base (4K) non-LRU movable page, we could reach as far as identify_page_state(), it should not fall into any category except me_unknown. So it seems we could just simply make it unhandlable.

There is the comment from memory_failure:
/*
* We ignore non-LRU pages for good reasons.
* - PG_locked is only well defined for LRU pages and a few others
* - to avoid races with __SetPageLocked()
* - to avoid races with __SetPageSlab*() (and more non-atomic ops)
* The check (unnecessarily) ignores LRU pages being isolated and
* walked by the page reclaim code, however that's not a big loss. */

So we could not handle non-LRU movable pages.

What do you mean is something like below?

mm/memory-failure.c +7 -0
index 5444a8ef4867..d80dbe0f20b6 100644
@@ -1784,6 +1784,13 @@ int memory_failure(unsigned long pfn, int flags)
                }
        }
 
+       if (__PageMovable(hpage)) {
+               put_page(p);
+               action_result(pfn, MF_MSG_MOVALBE_PAGE, MF_IGNORED);
+               res = -EBUSY;
+               goto unlock_mutex;
+       }
+
        if (PageTransHuge(hpage)) {
                /*
                 * The flag must be set after the refcount is bumped

i.e. Simply make non-LRU movable pages unhandlable ?

Quoted 3 lines

But it should be handlable for soft-offline since it could be migrated.

Yes, non-LRU movable pages can be simply migrated.

Many thanks.

Quoted 43 lines
Quoted 31 lines

Does this make sense for you? Thanks Naoya.

Quoted 28 lines

Thanks,
Naoya Horiguchi

Quoted 25 lines
---
 mm/memory-failure.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
mm/memory-failure.c +11 -0
index 23bfd809dc8c..ac6492e36978 100644
@@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags)
     }
 
     if (PageTransHuge(hpage)) {
+            /*
+             * The non-lru compound movable pages could be taken for
+             * transhuge pages. Also huge zero page could reach here
+             * and if we ever try to split it, the VM_BUG_ON_PAGE will
+             * be triggered in split_huge_page_to_list(). Skip these
+             * pages by checking PageLRU because huge zero page isn't
+             * lru page as non-lru compound movable pages.
+             */
+            if (!PageLRU(hpage)) {
+                    put_page(p);
+                    action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
mm/memory-failure.c +3 -1
+                    res = -EBUSY;
+                    goto unlock_mutex;
+            }
             /*
              * The flag must be set after the refcount is bumped
              * otherwise it may race with THP split.
--

2.23.0

.

#22 lore raw

Re: [PATCH 4/4] mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list

Quoted 80 lines · Miaohe Lin
Quoted 37 lines · Yang Shi
Quoted 27 lines · Miaohe Lin
Quoted 10 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 5 lines · Miaohe Lin

The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages.

It seems that memory_failure() also fails at get_any_page() with "hwpoison:
unhandlable page" message.

Quoted 8 lines
  [16478.203474] page:00000000b6acdbd1 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1810b4
  [16478.206612] flags: 0x57ffffc0801000(reserved|hwpoison|node=1|zone=2|lastcpupid=0x1fffff)
  [16478.209411] raw: 0057ffffc0801000 fffff11bc6042d08 fffff11bc6042d08 0000000000000000
  [16478.211921] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
  [16478.214473] page dumped because: hwpoison: unhandlable page
  [16478.216386] Memory failure: 0x1810b4: recovery action for unknown page: Ignored

We can't handle errors on huge (or normal) zero page, so the current

Sorry for confusing commit log again. I should have a coffee before I make this patch. Huge or normal zero page will fail at get_any_page because they're neither HWPoisonHandlable nor PageHuge.

Quoted 2 lines

behavior seems to me more suitable than "unsplit thp".

Quoted 8 lines
Quoted 3 lines

Or if you have some producer to reach the following path with huge zero page, could you share it?

What I mean is that non-lru movable compound page can reach here unexpected because __PageMovable(page) is handleable now. So get_any_page could succeed to grab the page refcnt. And since it's compound page, it will go through the split_huge_page_to_list because PageTransHuge checks PageHead(page) which can also be true for compound page. But this type of pages is unexpected for split_huge_page_to_list.

Quoted 6 lines

Can we really handle non-LRU movable pages in memory failure (uncorrectable errors)? Typically they are balloon, zsmalloc, etc. Assuming we run into a base (4K) non-LRU movable page, we could reach as far as identify_page_state(), it should not fall into any category except me_unknown. So it seems we could just simply make it unhandlable.

There is the comment from memory_failure:
/*
* We ignore non-LRU pages for good reasons.
* - PG_locked is only well defined for LRU pages and a few others
* - to avoid races with __SetPageLocked()
* - to avoid races with __SetPageSlab*() (and more non-atomic ops)
* The check (unnecessarily) ignores LRU pages being isolated and
* walked by the page reclaim code, however that's not a big loss. */

So we could not handle non-LRU movable pages.

What do you mean is something like below?

mm/memory-failure.c +7 -0
index 5444a8ef4867..d80dbe0f20b6 100644
@@ -1784,6 +1784,13 @@ int memory_failure(unsigned long pfn, int flags)
                }
        }
 
+       if (__PageMovable(hpage)) {
+               put_page(p);
+               action_result(pfn, MF_MSG_MOVALBE_PAGE, MF_IGNORED);
+               res = -EBUSY;
+               goto unlock_mutex;
+       }
+
        if (PageTransHuge(hpage)) {
                /*
                 * The flag must be set after the refcount is bumped
Quoted 1 line

i.e. Simply make non-LRU movable pages unhandlable ?

I'd prefer this personally. Something like the below (compile test only):

mm/memory-failure.c +10 -4
index 5444a8ef4867..789e40909ade 100644
@@ -1176,12 +1176,18 @@ void ClearPageHWPoisonTakenOff(struct page *page)
  * does not return true for hugetlb or device memory pages, so it's assumed
  * to be called only in the context where we never have such pages.
  */
-static inline bool HWPoisonHandlable(struct page *page)
+static inline bool HWPoisonHandlable(struct page *page, unsigned long flags)
 {
- return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page);
+ bool movable = false;
+
+ /* Soft offline could mirgate non-LRU movable pages */
+ if ((flags & MF_SOFT_OFFLINE) && __PageMovable(page))
+ movable = true;
+
+ return movable || PageLRU(page) || is_free_buddy_page(page);
 }
 
-static int __get_hwpoison_page(struct page *page)
+static int __get_hwpoison_page(struct page *page, unsigned long flags)
 {
  struct page *head = compound_head(page);
  int ret = 0;
@@ -1196,7 +1202,7 @@ static int __get_hwpoison_page(struct page *page)
  * for any unsupported type of page in order to reduce the risk of
  * unexpected races caused by taking a page refcount.
  */
- if (!HWPoisonHandlable(head))
+ if (!HWPoisonHandlable(head, flags))
  return -EBUSY;
 
  if (get_page_unless_zero(head)) {
@@ -1221,7 +1227,7 @@ static int get_any_page(struct page *p, unsigned

long flags)

try_again:
if (!count_increased) {
- ret = __get_hwpoison_page(p);
+ ret = __get_hwpoison_page(p, flags);
if (!ret) {
if (page_count(p)) {
/* We raced with an allocation, retry. */
@@ -1249,7 +1255,7 @@ static int get_any_page(struct page *p, unsigned long flags)
}
}

- if (PageHuge(p) || HWPoisonHandlable(p)) {
+ if (PageHuge(p) || HWPoisonHandlable(p, flags)) {

ret = 1;
} else {
/*

Quoted 53 lines
Quoted 4 lines

But it should be handlable for soft-offline since it could be migrated.

Yes, non-LRU movable pages can be simply migrated.

Many thanks.

Quoted 43 lines
Quoted 31 lines

Does this make sense for you? Thanks Naoya.

Quoted 28 lines

Thanks,
Naoya Horiguchi

Quoted 25 lines
---
 mm/memory-failure.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
mm/memory-failure.c +11 -0
index 23bfd809dc8c..ac6492e36978 100644
@@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags)
     }
 
     if (PageTransHuge(hpage)) {
+            /*
+             * The non-lru compound movable pages could be taken for
+             * transhuge pages. Also huge zero page could reach here
+             * and if we ever try to split it, the VM_BUG_ON_PAGE will
+             * be triggered in split_huge_page_to_list(). Skip these
+             * pages by checking PageLRU because huge zero page isn't
+             * lru page as non-lru compound movable pages.
+             */
+            if (!PageLRU(hpage)) {
+                    put_page(p);
+                    action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
mm/memory-failure.c +3 -1
+                    res = -EBUSY;
+                    goto unlock_mutex;
+            }
             /*
              * The flag must be set after the refcount is bumped
              * otherwise it may race with THP split.
--

2.23.0

.

author maintainer
#23 lore raw

Re: [PATCH 4/4] mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list

Quoted 81 lines · Yang Shi
Quoted 80 lines · Miaohe Lin
Quoted 37 lines · Yang Shi
Quoted 27 lines · Miaohe Lin
Quoted 10 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 5 lines · Miaohe Lin

The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages.

It seems that memory_failure() also fails at get_any_page() with "hwpoison:
unhandlable page" message.

Quoted 8 lines
  [16478.203474] page:00000000b6acdbd1 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1810b4
  [16478.206612] flags: 0x57ffffc0801000(reserved|hwpoison|node=1|zone=2|lastcpupid=0x1fffff)
  [16478.209411] raw: 0057ffffc0801000 fffff11bc6042d08 fffff11bc6042d08 0000000000000000
  [16478.211921] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
  [16478.214473] page dumped because: hwpoison: unhandlable page
  [16478.216386] Memory failure: 0x1810b4: recovery action for unknown page: Ignored

We can't handle errors on huge (or normal) zero page, so the current

Sorry for confusing commit log again. I should have a coffee before I make this patch. Huge or normal zero page will fail at get_any_page because they're neither HWPoisonHandlable nor PageHuge.

Quoted 2 lines

behavior seems to me more suitable than "unsplit thp".

Quoted 8 lines
Quoted 3 lines

Or if you have some producer to reach the following path with huge zero page, could you share it?

What I mean is that non-lru movable compound page can reach here unexpected because __PageMovable(page) is handleable now. So get_any_page could succeed to grab the page refcnt. And since it's compound page, it will go through the split_huge_page_to_list because PageTransHuge checks PageHead(page) which can also be true for compound page. But this type of pages is unexpected for split_huge_page_to_list.

Quoted 6 lines

Can we really handle non-LRU movable pages in memory failure (uncorrectable errors)? Typically they are balloon, zsmalloc, etc. Assuming we run into a base (4K) non-LRU movable page, we could reach as far as identify_page_state(), it should not fall into any category except me_unknown. So it seems we could just simply make it unhandlable.

There is the comment from memory_failure:
/*
* We ignore non-LRU pages for good reasons.
* - PG_locked is only well defined for LRU pages and a few others
* - to avoid races with __SetPageLocked()
* - to avoid races with __SetPageSlab*() (and more non-atomic ops)
* The check (unnecessarily) ignores LRU pages being isolated and
* walked by the page reclaim code, however that's not a big loss. */

So we could not handle non-LRU movable pages.

What do you mean is something like below?

mm/memory-failure.c +7 -0
index 5444a8ef4867..d80dbe0f20b6 100644
@@ -1784,6 +1784,13 @@ int memory_failure(unsigned long pfn, int flags)
                }
        }
 
+       if (__PageMovable(hpage)) {
+               put_page(p);
+               action_result(pfn, MF_MSG_MOVALBE_PAGE, MF_IGNORED);
+               res = -EBUSY;
+               goto unlock_mutex;
+       }
+
        if (PageTransHuge(hpage)) {
                /*
                 * The flag must be set after the refcount is bumped
Quoted 2 lines
Quoted 1 line

i.e. Simply make non-LRU movable pages unhandlable ?

The below change looks good to me except we need to ensure the caller passing in the MF_SOFT_OFFLINE flag while doing soft-offline now. This is false for madvise_inject_error but it's trivial to change this.

Will try to do this in V2.
Many thanks.

Quoted 113 lines

I'd prefer this personally. Something like the below (compile test only):

mm/memory-failure.c +11 -5
index 5444a8ef4867..789e40909ade 100644
@@ -1176,12 +1176,18 @@ void ClearPageHWPoisonTakenOff(struct page *page)
  * does not return true for hugetlb or device memory pages, so it's assumed
  * to be called only in the context where we never have such pages.
  */
-static inline bool HWPoisonHandlable(struct page *page)
+static inline bool HWPoisonHandlable(struct page *page, unsigned long flags)
 {
- return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page);
+ bool movable = false;
+
+ /* Soft offline could mirgate non-LRU movable pages */
+ if ((flags & MF_SOFT_OFFLINE) && __PageMovable(page))
+ movable = true;
+
+ return movable || PageLRU(page) || is_free_buddy_page(page);
 }
 
-static int __get_hwpoison_page(struct page *page)
+static int __get_hwpoison_page(struct page *page, unsigned long flags)
 {
  struct page *head = compound_head(page);
  int ret = 0;
@@ -1196,7 +1202,7 @@ static int __get_hwpoison_page(struct page *page)
  * for any unsupported type of page in order to reduce the risk of
  * unexpected races caused by taking a page refcount.
  */
- if (!HWPoisonHandlable(head))
+ if (!HWPoisonHandlable(head, flags))
  return -EBUSY;
 
  if (get_page_unless_zero(head)) {
@@ -1221,7 +1227,7 @@ static int get_any_page(struct page *p, unsigned
 long flags)
 
 try_again:
  if (!count_increased) {
- ret = __get_hwpoison_page(p);
+ ret = __get_hwpoison_page(p, flags);
  if (!ret) {
  if (page_count(p)) {

/* We raced with an allocation, retry. */

mm/memory-failure.c +1 -1
@@ -1249,7 +1255,7 @@ static int get_any_page(struct page *p, unsigned
 long flags)
  }
  }
 
- if (PageHuge(p) || HWPoisonHandlable(p)) {
+ if (PageHuge(p) || HWPoisonHandlable(p, flags)) {
  ret = 1;
  } else {

/*

Quoted 53 lines
Quoted 4 lines

But it should be handlable for soft-offline since it could be migrated.

Yes, non-LRU movable pages can be simply migrated.

Many thanks.

Quoted 43 lines
Quoted 31 lines

Does this make sense for you? Thanks Naoya.

Quoted 28 lines

Thanks,
Naoya Horiguchi

Quoted 25 lines
---
 mm/memory-failure.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
mm/memory-failure.c +11 -0
index 23bfd809dc8c..ac6492e36978 100644
@@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags)
     }
 
     if (PageTransHuge(hpage)) {
+            /*
+             * The non-lru compound movable pages could be taken for
+             * transhuge pages. Also huge zero page could reach here
+             * and if we ever try to split it, the VM_BUG_ON_PAGE will
+             * be triggered in split_huge_page_to_list(). Skip these
+             * pages by checking PageLRU because huge zero page isn't
+             * lru page as non-lru compound movable pages.
+             */
+            if (!PageLRU(hpage)) {
+                    put_page(p);
+                    action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
mm/memory-failure.c +3 -1
+                    res = -EBUSY;
+                    goto unlock_mutex;
+            }
             /*
              * The flag must be set after the refcount is bumped
              * otherwise it may race with THP split.
--

2.23.0

.

.

author maintainer
#24 lore raw

Re: [PATCH 4/4] mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list

In reply to Yang Shi
Quoted 81 lines · Yang Shi
Quoted 80 lines · Miaohe Lin
Quoted 37 lines · Yang Shi
Quoted 27 lines · Miaohe Lin
Quoted 10 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 5 lines · Miaohe Lin

The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages.

It seems that memory_failure() also fails at get_any_page() with "hwpoison:
unhandlable page" message.

Quoted 8 lines
  [16478.203474] page:00000000b6acdbd1 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1810b4
  [16478.206612] flags: 0x57ffffc0801000(reserved|hwpoison|node=1|zone=2|lastcpupid=0x1fffff)
  [16478.209411] raw: 0057ffffc0801000 fffff11bc6042d08 fffff11bc6042d08 0000000000000000
  [16478.211921] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
  [16478.214473] page dumped because: hwpoison: unhandlable page
  [16478.216386] Memory failure: 0x1810b4: recovery action for unknown page: Ignored

We can't handle errors on huge (or normal) zero page, so the current

Sorry for confusing commit log again. I should have a coffee before I make this patch. Huge or normal zero page will fail at get_any_page because they're neither HWPoisonHandlable nor PageHuge.

Quoted 2 lines

behavior seems to me more suitable than "unsplit thp".

Quoted 8 lines
Quoted 3 lines

Or if you have some producer to reach the following path with huge zero page, could you share it?

What I mean is that non-lru movable compound page can reach here unexpected because __PageMovable(page) is handleable now. So get_any_page could succeed to grab the page refcnt. And since it's compound page, it will go through the split_huge_page_to_list because PageTransHuge checks PageHead(page) which can also be true for compound page. But this type of pages is unexpected for split_huge_page_to_list.

Quoted 6 lines

Can we really handle non-LRU movable pages in memory failure (uncorrectable errors)? Typically they are balloon, zsmalloc, etc. Assuming we run into a base (4K) non-LRU movable page, we could reach as far as identify_page_state(), it should not fall into any category except me_unknown. So it seems we could just simply make it unhandlable.

There is the comment from memory_failure:
/*
* We ignore non-LRU pages for good reasons.
* - PG_locked is only well defined for LRU pages and a few others
* - to avoid races with __SetPageLocked()
* - to avoid races with __SetPageSlab*() (and more non-atomic ops)
* The check (unnecessarily) ignores LRU pages being isolated and
* walked by the page reclaim code, however that's not a big loss. */

So we could not handle non-LRU movable pages.

What do you mean is something like below?

mm/memory-failure.c +7 -0
index 5444a8ef4867..d80dbe0f20b6 100644
@@ -1784,6 +1784,13 @@ int memory_failure(unsigned long pfn, int flags)
                }
        }
 
+       if (__PageMovable(hpage)) {
+               put_page(p);
+               action_result(pfn, MF_MSG_MOVALBE_PAGE, MF_IGNORED);
+               res = -EBUSY;
+               goto unlock_mutex;
+       }
+
        if (PageTransHuge(hpage)) {
                /*
                 * The flag must be set after the refcount is bumped
Quoted 2 lines
Quoted 1 line

i.e. Simply make non-LRU movable pages unhandlable ?

I think about the below code more carefully and I found that this will make hwpoison_filter can't handle the non-LRU movable pages now. Because non-LRU movable pages return early now and thus can't reach the hwpoison_filter. This results in a inconsistent behavior with previous one. So I think the origin fixup of this patch is more suitable. What do you think?

Thanks.

Quoted 113 lines

I'd prefer this personally. Something like the below (compile test only):

mm/memory-failure.c +11 -5
index 5444a8ef4867..789e40909ade 100644
@@ -1176,12 +1176,18 @@ void ClearPageHWPoisonTakenOff(struct page *page)
  * does not return true for hugetlb or device memory pages, so it's assumed
  * to be called only in the context where we never have such pages.
  */
-static inline bool HWPoisonHandlable(struct page *page)
+static inline bool HWPoisonHandlable(struct page *page, unsigned long flags)
 {
- return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page);
+ bool movable = false;
+
+ /* Soft offline could mirgate non-LRU movable pages */
+ if ((flags & MF_SOFT_OFFLINE) && __PageMovable(page))
+ movable = true;
+
+ return movable || PageLRU(page) || is_free_buddy_page(page);
 }
 
-static int __get_hwpoison_page(struct page *page)
+static int __get_hwpoison_page(struct page *page, unsigned long flags)
 {
  struct page *head = compound_head(page);
  int ret = 0;
@@ -1196,7 +1202,7 @@ static int __get_hwpoison_page(struct page *page)
  * for any unsupported type of page in order to reduce the risk of
  * unexpected races caused by taking a page refcount.
  */
- if (!HWPoisonHandlable(head))
+ if (!HWPoisonHandlable(head, flags))
  return -EBUSY;
 
  if (get_page_unless_zero(head)) {
@@ -1221,7 +1227,7 @@ static int get_any_page(struct page *p, unsigned
 long flags)
 
 try_again:
  if (!count_increased) {
- ret = __get_hwpoison_page(p);
+ ret = __get_hwpoison_page(p, flags);
  if (!ret) {
  if (page_count(p)) {

/* We raced with an allocation, retry. */

mm/memory-failure.c +1 -1
@@ -1249,7 +1255,7 @@ static int get_any_page(struct page *p, unsigned
 long flags)
  }
  }
 
- if (PageHuge(p) || HWPoisonHandlable(p)) {
+ if (PageHuge(p) || HWPoisonHandlable(p, flags)) {
  ret = 1;
  } else {

/*

Quoted 53 lines
Quoted 4 lines

But it should be handlable for soft-offline since it could be migrated.

Yes, non-LRU movable pages can be simply migrated.

Many thanks.

Quoted 43 lines
Quoted 31 lines

Does this make sense for you? Thanks Naoya.

Quoted 28 lines

Thanks,
Naoya Horiguchi

Quoted 25 lines
---
 mm/memory-failure.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
mm/memory-failure.c +11 -0
index 23bfd809dc8c..ac6492e36978 100644
@@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags)
     }
 
     if (PageTransHuge(hpage)) {
+            /*
+             * The non-lru compound movable pages could be taken for
+             * transhuge pages. Also huge zero page could reach here
+             * and if we ever try to split it, the VM_BUG_ON_PAGE will
+             * be triggered in split_huge_page_to_list(). Skip these
+             * pages by checking PageLRU because huge zero page isn't
+             * lru page as non-lru compound movable pages.
+             */
+            if (!PageLRU(hpage)) {
+                    put_page(p);
+                    action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
mm/memory-failure.c +3 -1
+                    res = -EBUSY;
+                    goto unlock_mutex;
+            }
             /*
              * The flag must be set after the refcount is bumped
              * otherwise it may race with THP split.
--

2.23.0

.

.

#25 lore raw

Re: [PATCH 4/4] mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list

Quoted 83 lines · Miaohe Lin
Quoted 81 lines · Yang Shi
Quoted 80 lines · Miaohe Lin
Quoted 37 lines · Yang Shi
Quoted 27 lines · Miaohe Lin
Quoted 10 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 5 lines · Miaohe Lin

The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages.

It seems that memory_failure() also fails at get_any_page() with "hwpoison:
unhandlable page" message.

Quoted 8 lines
  [16478.203474] page:00000000b6acdbd1 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1810b4
  [16478.206612] flags: 0x57ffffc0801000(reserved|hwpoison|node=1|zone=2|lastcpupid=0x1fffff)
  [16478.209411] raw: 0057ffffc0801000 fffff11bc6042d08 fffff11bc6042d08 0000000000000000
  [16478.211921] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
  [16478.214473] page dumped because: hwpoison: unhandlable page
  [16478.216386] Memory failure: 0x1810b4: recovery action for unknown page: Ignored

We can't handle errors on huge (or normal) zero page, so the current

Sorry for confusing commit log again. I should have a coffee before I make this patch. Huge or normal zero page will fail at get_any_page because they're neither HWPoisonHandlable nor PageHuge.

Quoted 2 lines

behavior seems to me more suitable than "unsplit thp".

Quoted 8 lines
Quoted 3 lines

Or if you have some producer to reach the following path with huge zero page, could you share it?

What I mean is that non-lru movable compound page can reach here unexpected because __PageMovable(page) is handleable now. So get_any_page could succeed to grab the page refcnt. And since it's compound page, it will go through the split_huge_page_to_list because PageTransHuge checks PageHead(page) which can also be true for compound page. But this type of pages is unexpected for split_huge_page_to_list.

Quoted 6 lines

Can we really handle non-LRU movable pages in memory failure (uncorrectable errors)? Typically they are balloon, zsmalloc, etc. Assuming we run into a base (4K) non-LRU movable page, we could reach as far as identify_page_state(), it should not fall into any category except me_unknown. So it seems we could just simply make it unhandlable.

There is the comment from memory_failure:
/*
* We ignore non-LRU pages for good reasons.
* - PG_locked is only well defined for LRU pages and a few others
* - to avoid races with __SetPageLocked()
* - to avoid races with __SetPageSlab*() (and more non-atomic ops)
* The check (unnecessarily) ignores LRU pages being isolated and
* walked by the page reclaim code, however that's not a big loss. */

So we could not handle non-LRU movable pages.

What do you mean is something like below?

mm/memory-failure.c +7 -0
index 5444a8ef4867..d80dbe0f20b6 100644
@@ -1784,6 +1784,13 @@ int memory_failure(unsigned long pfn, int flags)
                }
        }
 
+       if (__PageMovable(hpage)) {
+               put_page(p);
+               action_result(pfn, MF_MSG_MOVALBE_PAGE, MF_IGNORED);
+               res = -EBUSY;
+               goto unlock_mutex;
+       }
+
        if (PageTransHuge(hpage)) {
                /*
                 * The flag must be set after the refcount is bumped
Quoted 8 lines
Quoted 2 lines
Quoted 1 line

i.e. Simply make non-LRU movable pages unhandlable ?

I think about the below code more carefully and I found that this will make hwpoison_filter can't handle the non-LRU movable pages now. Because non-LRU movable pages return early now and thus can't reach the hwpoison_filter. This results in a inconsistent behavior with previous one. So I think the origin fixup of this patch is more suitable. What do you think?

I'm not familiar with hwpoison_filter(), it seems like a test helper for error injection. I don't think hwpoison_filter() is used to filter unhandlable page, for example, slab page, IIUC. So the non-LRU movable pages should be treated the same. If so, the old behavior was simply wrong.

Quoted 118 lines

Thanks.

Quoted 113 lines

I'd prefer this personally. Something like the below (compile test only):

mm/memory-failure.c +11 -5
index 5444a8ef4867..789e40909ade 100644
@@ -1176,12 +1176,18 @@ void ClearPageHWPoisonTakenOff(struct page *page)
  * does not return true for hugetlb or device memory pages, so it's assumed
  * to be called only in the context where we never have such pages.
  */
-static inline bool HWPoisonHandlable(struct page *page)
+static inline bool HWPoisonHandlable(struct page *page, unsigned long flags)
 {
- return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page);
+ bool movable = false;
+
+ /* Soft offline could mirgate non-LRU movable pages */
+ if ((flags & MF_SOFT_OFFLINE) && __PageMovable(page))
+ movable = true;
+
+ return movable || PageLRU(page) || is_free_buddy_page(page);
 }
 
-static int __get_hwpoison_page(struct page *page)
+static int __get_hwpoison_page(struct page *page, unsigned long flags)
 {
  struct page *head = compound_head(page);
  int ret = 0;
@@ -1196,7 +1202,7 @@ static int __get_hwpoison_page(struct page *page)
  * for any unsupported type of page in order to reduce the risk of
  * unexpected races caused by taking a page refcount.
  */
- if (!HWPoisonHandlable(head))
+ if (!HWPoisonHandlable(head, flags))
  return -EBUSY;
 
  if (get_page_unless_zero(head)) {
@@ -1221,7 +1227,7 @@ static int get_any_page(struct page *p, unsigned
 long flags)
 
 try_again:
  if (!count_increased) {
- ret = __get_hwpoison_page(p);
+ ret = __get_hwpoison_page(p, flags);
  if (!ret) {
  if (page_count(p)) {

/* We raced with an allocation, retry. */

mm/memory-failure.c +1 -1
@@ -1249,7 +1255,7 @@ static int get_any_page(struct page *p, unsigned
 long flags)
  }
  }
 
- if (PageHuge(p) || HWPoisonHandlable(p)) {
+ if (PageHuge(p) || HWPoisonHandlable(p, flags)) {
  ret = 1;
  } else {

/*

Quoted 53 lines
Quoted 4 lines

But it should be handlable for soft-offline since it could be migrated.

Yes, non-LRU movable pages can be simply migrated.

Many thanks.

Quoted 43 lines
Quoted 31 lines

Does this make sense for you? Thanks Naoya.

Quoted 28 lines

Thanks,
Naoya Horiguchi

Quoted 25 lines
---
 mm/memory-failure.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
mm/memory-failure.c +11 -0
index 23bfd809dc8c..ac6492e36978 100644
@@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags)
     }
 
     if (PageTransHuge(hpage)) {
+            /*
+             * The non-lru compound movable pages could be taken for
+             * transhuge pages. Also huge zero page could reach here
+             * and if we ever try to split it, the VM_BUG_ON_PAGE will
+             * be triggered in split_huge_page_to_list(). Skip these
+             * pages by checking PageLRU because huge zero page isn't
+             * lru page as non-lru compound movable pages.
+             */
+            if (!PageLRU(hpage)) {
+                    put_page(p);
+                    action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
mm/memory-failure.c +3 -1
+                    res = -EBUSY;
+                    goto unlock_mutex;
+            }
             /*
              * The flag must be set after the refcount is bumped
              * otherwise it may race with THP split.
--

2.23.0

.

.

author maintainer
#26 lore raw

Re: [PATCH 4/4] mm/memory-failure.c: fix potential VM_BUG_ON_PAGE in split_huge_page_to_list

Quoted 93 lines · Yang Shi
Quoted 83 lines · Miaohe Lin
Quoted 81 lines · Yang Shi
Quoted 80 lines · Miaohe Lin
Quoted 37 lines · Yang Shi
Quoted 27 lines · Miaohe Lin
Quoted 10 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 5 lines · Miaohe Lin

The huge zero page could reach here and if we ever try to split it, the VM_BUG_ON_PAGE will be triggered in split_huge_page_to_list(). Also the non-lru compound movable pages could be taken for transhuge pages. Skip these pages by checking PageLRU because huge zero page isn't lru page as non-lru compound movable pages.

It seems that memory_failure() also fails at get_any_page() with "hwpoison:
unhandlable page" message.

Quoted 8 lines
  [16478.203474] page:00000000b6acdbd1 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1810b4
  [16478.206612] flags: 0x57ffffc0801000(reserved|hwpoison|node=1|zone=2|lastcpupid=0x1fffff)
  [16478.209411] raw: 0057ffffc0801000 fffff11bc6042d08 fffff11bc6042d08 0000000000000000
  [16478.211921] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
  [16478.214473] page dumped because: hwpoison: unhandlable page
  [16478.216386] Memory failure: 0x1810b4: recovery action for unknown page: Ignored

We can't handle errors on huge (or normal) zero page, so the current

Sorry for confusing commit log again. I should have a coffee before I make this patch. Huge or normal zero page will fail at get_any_page because they're neither HWPoisonHandlable nor PageHuge.

Quoted 2 lines

behavior seems to me more suitable than "unsplit thp".

Quoted 8 lines
Quoted 3 lines

Or if you have some producer to reach the following path with huge zero page, could you share it?

What I mean is that non-lru movable compound page can reach here unexpected because __PageMovable(page) is handleable now. So get_any_page could succeed to grab the page refcnt. And since it's compound page, it will go through the split_huge_page_to_list because PageTransHuge checks PageHead(page) which can also be true for compound page. But this type of pages is unexpected for split_huge_page_to_list.

Quoted 6 lines

Can we really handle non-LRU movable pages in memory failure (uncorrectable errors)? Typically they are balloon, zsmalloc, etc. Assuming we run into a base (4K) non-LRU movable page, we could reach as far as identify_page_state(), it should not fall into any category except me_unknown. So it seems we could just simply make it unhandlable.

There is the comment from memory_failure:
/*
* We ignore non-LRU pages for good reasons.
* - PG_locked is only well defined for LRU pages and a few others
* - to avoid races with __SetPageLocked()
* - to avoid races with __SetPageSlab*() (and more non-atomic ops)
* The check (unnecessarily) ignores LRU pages being isolated and
* walked by the page reclaim code, however that's not a big loss. */

So we could not handle non-LRU movable pages.

What do you mean is something like below?

mm/memory-failure.c +7 -0
index 5444a8ef4867..d80dbe0f20b6 100644
@@ -1784,6 +1784,13 @@ int memory_failure(unsigned long pfn, int flags)
                }
        }
 
+       if (__PageMovable(hpage)) {
+               put_page(p);
+               action_result(pfn, MF_MSG_MOVALBE_PAGE, MF_IGNORED);
+               res = -EBUSY;
+               goto unlock_mutex;
+       }
+
        if (PageTransHuge(hpage)) {
                /*
                 * The flag must be set after the refcount is bumped
Quoted 8 lines
Quoted 2 lines
Quoted 1 line

i.e. Simply make non-LRU movable pages unhandlable ?

I think about the below code more carefully and I found that this will make hwpoison_filter can't handle the non-LRU movable pages now. Because non-LRU movable pages return early now and thus can't reach the hwpoison_filter. This results in a inconsistent behavior with previous one. So I think the origin fixup of this patch is more suitable. What do you think?

Quoted 5 lines

I'm not familiar with hwpoison_filter(), it seems like a test helper for error injection. I don't think hwpoison_filter() is used to filter unhandlable page, for example, slab page, IIUC. So the non-LRU movable pages should be treated the same. If so, the old behavior was simply wrong.

I think you're right. hwpoison_filter should filter the handleable error.

Thanks.

Quoted 121 lines
Quoted 119 lines

Thanks.

Quoted 113 lines

I'd prefer this personally. Something like the below (compile test only):

mm/memory-failure.c +11 -5
index 5444a8ef4867..789e40909ade 100644
@@ -1176,12 +1176,18 @@ void ClearPageHWPoisonTakenOff(struct page *page)
  * does not return true for hugetlb or device memory pages, so it's assumed
  * to be called only in the context where we never have such pages.
  */
-static inline bool HWPoisonHandlable(struct page *page)
+static inline bool HWPoisonHandlable(struct page *page, unsigned long flags)
 {
- return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page);
+ bool movable = false;
+
+ /* Soft offline could mirgate non-LRU movable pages */
+ if ((flags & MF_SOFT_OFFLINE) && __PageMovable(page))
+ movable = true;
+
+ return movable || PageLRU(page) || is_free_buddy_page(page);
 }
 
-static int __get_hwpoison_page(struct page *page)
+static int __get_hwpoison_page(struct page *page, unsigned long flags)
 {
  struct page *head = compound_head(page);
  int ret = 0;
@@ -1196,7 +1202,7 @@ static int __get_hwpoison_page(struct page *page)
  * for any unsupported type of page in order to reduce the risk of
  * unexpected races caused by taking a page refcount.
  */
- if (!HWPoisonHandlable(head))
+ if (!HWPoisonHandlable(head, flags))
  return -EBUSY;
 
  if (get_page_unless_zero(head)) {
@@ -1221,7 +1227,7 @@ static int get_any_page(struct page *p, unsigned
 long flags)
 
 try_again:
  if (!count_increased) {
- ret = __get_hwpoison_page(p);
+ ret = __get_hwpoison_page(p, flags);
  if (!ret) {
  if (page_count(p)) {

/* We raced with an allocation, retry. */

mm/memory-failure.c +1 -1
@@ -1249,7 +1255,7 @@ static int get_any_page(struct page *p, unsigned
 long flags)
  }
  }
 
- if (PageHuge(p) || HWPoisonHandlable(p)) {
+ if (PageHuge(p) || HWPoisonHandlable(p, flags)) {
  ret = 1;
  } else {

/*

Quoted 53 lines
Quoted 4 lines

But it should be handlable for soft-offline since it could be migrated.

Yes, non-LRU movable pages can be simply migrated.

Many thanks.

Quoted 43 lines
Quoted 31 lines

Does this make sense for you? Thanks Naoya.

Quoted 28 lines

Thanks,
Naoya Horiguchi

Quoted 25 lines
---
 mm/memory-failure.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
mm/memory-failure.c +11 -0
index 23bfd809dc8c..ac6492e36978 100644
@@ -1792,6 +1792,20 @@ int memory_failure(unsigned long pfn, int flags)
     }
 
     if (PageTransHuge(hpage)) {
+            /*
+             * The non-lru compound movable pages could be taken for
+             * transhuge pages. Also huge zero page could reach here
+             * and if we ever try to split it, the VM_BUG_ON_PAGE will
+             * be triggered in split_huge_page_to_list(). Skip these
+             * pages by checking PageLRU because huge zero page isn't
+             * lru page as non-lru compound movable pages.
+             */
+            if (!PageLRU(hpage)) {
+                    put_page(p);
+                    action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED);
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
mm/memory-failure.c +3 -1
+                    res = -EBUSY;
+                    goto unlock_mutex;
+            }
             /*
              * The flag must be set after the refcount is bumped
              * otherwise it may race with THP split.
--

2.23.0

.

.

.