Skip to contentSkip to conversation

mm, hwpoison: add is_free_buddy_page() in HWPoisonHandlable()

PATCH In review Naoya Horiguchi 4 participants 4 messages Sep 9, 2021 – Sep 10, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm, hwpoison: add is_free_buddy_page() in HWPoisonHandlable()

From: Naoya Horiguchi <[email protected]>

commit fcc00621d88b ("mm/hwpoison: retry with shake_page() for unhandlable pages") changes the return value of __get_hwpoison_page() to retry for transiently unhandlable cases. However, __get_hwpoison_page() currently fails to properly judge buddy pages as handlable, so hard/soft offline for buddy pages always fail as "unhandlable page". This is totally regrettable.

So let's add is_free_buddy_page() in HWPoisonHandlable(), so that __get_hwpoison_page() returns different return values between buddy pages and unhandlable pages as intended.

Fixes fcc00621d88b ("mm/hwpoison: retry with shake_page() for unhandlable pages")
---
 mm/memory-failure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +1 -1
index 60df8fcd0444..3416c55be810 100644
@@ -1126,7 +1126,7 @@ static int page_action(struct page_state *ps, struct page *p,
  */
 static inline bool HWPoisonHandlable(struct page *page)
 {
-	return PageLRU(page) || __PageMovable(page);
+	return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page);
 }
 
 static int __get_hwpoison_page(struct page *page)
Signature · 1 line
2.25.1
#1 lore raw
Quoted 26 lines · Naoya Horiguchi

From: Naoya Horiguchi <[email protected]>

commit fcc00621d88b ("mm/hwpoison: retry with shake_page() for unhandlable pages") changes the return value of __get_hwpoison_page() to retry for transiently unhandlable cases. However, __get_hwpoison_page() currently fails to properly judge buddy pages as handlable, so hard/soft offline for buddy pages always fail as "unhandlable page". This is totally regrettable.

So let's add is_free_buddy_page() in HWPoisonHandlable(), so that __get_hwpoison_page() returns different return values between buddy pages and unhandlable pages as intended.

Fixes fcc00621d88b ("mm/hwpoison: retry with shake_page() for unhandlable pages")
---
 mm/memory-failure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +0 -0
index 60df8fcd0444..3416c55be810 100644

mm/memory-failure.c static int page_action(struct page_state *ps, struct page *p, · line 1129

Quoted 5 lines
mm/memory-failure.c +1 -1
@@ -1126,7 +1126,7 @@ static int page_action(struct page_state *ps, struct page *p,
  */
 static inline bool HWPoisonHandlable(struct page *page)
 {
-       return PageLRU(page) || __PageMovable(page);
+       return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page);

It seems to work. Although this may change the return value of get_any_page() to 1 when MF_COUNT_INCREASED is set. This may cause soft offline to mishandle free buddy page, but MF_COUNT_INCREASED is only set when madvise is used, and madvise definitely can't soft offline free buddy page. It did take me a while to figure out this trick. Maybe need some refactor?

Anyway this patch looks fine to me. Reviewed-by: Yang Shi <[email protected]>

Quoted 6 lines
mm/memory-failure.c +0 -1
 }
 
 static int __get_hwpoison_page(struct page *page)
--

2.25.1

#2 lore raw
Quoted 23 lines · Yang Shi
Quoted 21 lines · Naoya Horiguchi

From: Naoya Horiguchi <[email protected]>

commit fcc00621d88b ("mm/hwpoison: retry with shake_page() for unhandlable pages") changes the return value of __get_hwpoison_page() to retry for transiently unhandlable cases. However, __get_hwpoison_page() currently fails to properly judge buddy pages as handlable, so hard/soft offline for buddy pages always fail as "unhandlable page". This is totally regrettable.

So let's add is_free_buddy_page() in HWPoisonHandlable(), so that __get_hwpoison_page() returns different return values between buddy pages and unhandlable pages as intended.

Fixes fcc00621d88b ("mm/hwpoison: retry with shake_page() for unhandlable pages")
---
 mm/memory-failure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

mm/memory-failure.c static int page_action(struct page_state *ps, struct page *p, · line 1129

Quoted 10 lines
mm/memory-failure.c +1 -1
index 60df8fcd0444..3416c55be810 100644
@@ -1126,7 +1126,7 @@ static int page_action(struct page_state *ps, struct page *p,
  */
 static inline bool HWPoisonHandlable(struct page *page)
 {
-       return PageLRU(page) || __PageMovable(page);
+       return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page);

It seems to work. Although this may change the return value of get_any_page() to 1 when MF_COUNT_INCREASED is set. This may cause soft offline to mishandle free buddy page, but MF_COUNT_INCREASED is only set when madvise is used, and madvise definitely can't soft offline free buddy page.

Yes, madvise(MADV_SOFT_OFFLINE) should not be called for free buddy pages, because the interface covers only user-mapped pages.

Quoted 2 lines

It did take me a while to figure out this
trick. Maybe need some refactor?

I think so, the current code looks to me fragile for future change, but I'm not sure how we can improve this.

One (maybe not related to MF_COUNT_INCREASED) room for refactoring is "if (PageTransHuge(head))" block in __get_hwpoison_page(), which might be old and useless code for now.

Quoted 2 lines

Anyway this patch looks fine to me. Reviewed-by: Yang Shi <[email protected]>

Thank you for the review.

- Naoya

Acked-by on v1 1/1
#3 lore raw
In reply to Naoya Horiguchi
Quoted 26 lines · Naoya Horiguchi

From: Naoya Horiguchi <[email protected]>

commit fcc00621d88b ("mm/hwpoison: retry with shake_page() for unhandlable pages") changes the return value of __get_hwpoison_page() to retry for transiently unhandlable cases. However, __get_hwpoison_page() currently fails to properly judge buddy pages as handlable, so hard/soft offline for buddy pages always fail as "unhandlable page". This is totally regrettable.

So let's add is_free_buddy_page() in HWPoisonHandlable(), so that __get_hwpoison_page() returns different return values between buddy pages and unhandlable pages as intended.

Fixes fcc00621d88b ("mm/hwpoison: retry with shake_page() for unhandlable pages")
---
  mm/memory-failure.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +0 -0
index 60df8fcd0444..3416c55be810 100644

mm/memory-failure.c static int page_action(struct page_state *ps, struct page *p, · line 1132

Quoted 8 lines
mm/memory-failure.c +1 -1
@@ -1126,7 +1126,7 @@ static int page_action(struct page_state *ps, struct page *p,
   */
  static inline bool HWPoisonHandlable(struct page *page)
  {
-	return PageLRU(page) || __PageMovable(page);
+	return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page);
  }
 
  static int __get_hwpoison_page(struct page *page)

LGTM and I agree that code might desrve some cleanups.

Signature · 3 lines
Thanks,

David / dhildenb