Skip to contentSkip to conversation

mm/memory-failure: fix hardware poison check in unpoison_memory()

PATCH Applied Sidhartha Kumar 5 participants 9 messages Jul 17, 2023 – Jul 20, 2023

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

PATCH 1/1 mm/memory-failure: fix hardware poison check in unpoison_memory()

It was pointed out[1] that using folio_test_hwpoison() is wrong as we need to check the indiviual page that has poison. folio_test_hwpoison() only checks the head page so go back to using PageHWPoison().

Fixes a6fddef49eef ("mm/memory-failure: convert unpoison_memory() to folios")

[1]: https://lore.kernel.org/lkml/[email protected]/

---
 mm/memory-failure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +1 -1
index 02b1d8f104d51..a114c8c3039cd 100644
@@ -2523,7 +2523,7 @@ int unpoison_memory(unsigned long pfn)
 		goto unlock_mutex;
 	}
 
-	if (!folio_test_hwpoison(folio)) {
+	if (!PageHWPoison(p)) {
 		unpoison_pr_info("Unpoison: Page was already unpoisoned %#lx\n",
 				 pfn, &unpoison_rs);
 		goto unlock_mutex;
Signature · 1 line
2.41.0
maintainer
#1 lore raw
Quoted 4 lines · On Mon, 17 Jul 2023 11:18:12 -0700 Sidhartha Kumar…

It was pointed out[1] that using folio_test_hwpoison() is wrong as we need to check the indiviual page that has poison. folio_test_hwpoison() only checks the head page so go back to using PageHWPoison().

Please describe the user-visible effects of the bug, especially when proposing a -stable backport.

#3 lore raw
In reply to Sidhartha Kumar
Quoted 20 lines · Sidhartha Kumar

It was pointed out[1] that using folio_test_hwpoison() is wrong as we need to check the indiviual page that has poison. folio_test_hwpoison() only checks the head page so go back to using PageHWPoison().

Fixes a6fddef49eef ("mm/memory-failure: convert unpoison_memory() to folios")

[1]: https://lore.kernel.org/lkml/[email protected]/

---
  mm/memory-failure.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +0 -0
index 02b1d8f104d51..a114c8c3039cd 100644

mm/memory-failure.c int unpoison_memory(unsigned long pfn) · line 2529

Quoted 8 lines
mm/memory-failure.c +1 -1
@@ -2523,7 +2523,7 @@ int unpoison_memory(unsigned long pfn)
  		goto unlock_mutex;
  	}
 
-	if (!folio_test_hwpoison(folio)) {
+	if (!PageHWPoison(p)) {
  		unpoison_pr_info("Unpoison: Page was already unpoisoned %#lx\n",
  				 pfn, &unpoison_rs);
  		goto unlock_mutex;

Would it worth the trouble to create folio_page_test_##lname(folio, index) macros to address folio subpage?

thanks!
-jane

#4 lore raw
In reply to Sidhartha Kumar
Quoted 20 lines · Sidhartha Kumar

It was pointed out[1] that using folio_test_hwpoison() is wrong as we need to check the indiviual page that has poison. folio_test_hwpoison() only checks the head page so go back to using PageHWPoison().

Fixes a6fddef49eef ("mm/memory-failure: convert unpoison_memory() to folios")

[1]: https://lore.kernel.org/lkml/[email protected]/

---
 mm/memory-failure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +0 -0
index 02b1d8f104d51..a114c8c3039cd 100644

mm/memory-failure.c int unpoison_memory(unsigned long pfn) · line 2526

Quoted 5 lines
mm/memory-failure.c +1 -1
@@ -2523,7 +2523,7 @@ int unpoison_memory(unsigned long pfn)
 		goto unlock_mutex;
 	}
 
-	if (!folio_test_hwpoison(folio)) {
+	if (!PageHWPoison(p)) {

I don't think this works for hwpoisoned hugetlb pages that have PageHWPoison set on the head page, rather than on the raw subpage. In the case of hwpoisoned thps, PageHWPoison is set on the raw subpage, not on the head pages. (I believe this is not detected because no one considers the scenario of unpoisoning hwpoisoned thps, which is a rare case). Perhaps the function is_page_hwpoison() would be useful for this purpose?

Thanks,
Naoya Horiguchi

Quoted 8 lines
mm/memory-failure.c +0 -0
 		unpoison_pr_info("Unpoison: Page was already unpoisoned %#lx\n",
 				 pfn, &unpoison_rs);
 		goto unlock_mutex;
Signature · 1 line
2.41.0
#5 lore raw
Quoted 24 lines · Naoya Horiguchi
Quoted 23 lines · Sidhartha Kumar

It was pointed out[1] that using folio_test_hwpoison() is wrong as we need to check the indiviual page that has poison. folio_test_hwpoison() only checks the head page so go back to using PageHWPoison().

Fixes a6fddef49eef ("mm/memory-failure: convert unpoison_memory() to folios")

[1]: https://lore.kernel.org/lkml/[email protected]/

---
 mm/memory-failure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +0 -0
index 02b1d8f104d51..a114c8c3039cd 100644
@@ -2523,7 +2523,7 @@ int unpoison_memory(unsigned long pfn)
 		goto unlock_mutex;
 	}
 
Quoted 10 lines

mm/memory-failure.c int unpoison_memory(unsigned long pfn) · line 2526

Quoted 2 lines
mm/memory-failure.c +1 -1
-	if (!folio_test_hwpoison(folio)) {
+	if (!PageHWPoison(p)) {

I don't think this works for hwpoisoned hugetlb pages that have PageHWPoison set on the head page, rather than on the raw subpage. In the case of hwpoisoned thps, PageHWPoison is set on the raw subpage, not on the head pages. (I believe this is not detected because no one considers the scenario of unpoisoning hwpoisoned thps, which is a rare case). Perhaps the function is_page_hwpoison() would be useful for this purpose?

Sorry, I was wrong. Checking PageHWPoison() is fine because the users of unpoison should know where the PageHWPoison is set via /proc/kpageflags. So this patch is OK to me after comments from other reviewers are resolved.

Thanks,
Naoya Horiguchi

#2 lore raw
In reply to Andrew Morton
Quoted 9 lines · Andrew Morton
Quoted 4 lines · On Mon, 17 Jul 2023 11:18:12 -0700 Sidhartha Kumar…

It was pointed out[1] that using folio_test_hwpoison() is wrong as we need to check the indiviual page that has poison. folio_test_hwpoison() only checks the head page so go back to using PageHWPoison().

Please describe the user-visible effects of the bug, especially when proposing a -stable backport.

User-visible effects include existing hwpoison-inject tests possibly failing as unpoisoning a single subpage could lead to unpoisoning an entire folio. Memory unpoisoning could also not work as expected as the function will break early due to only checking the head page and not the actually poisoned subpage.

#6 lore raw
In reply to Naoya Horiguchi
Quoted 36 lines · Naoya Horiguchi
Quoted 24 lines · Naoya Horiguchi
Quoted 23 lines · Sidhartha Kumar

It was pointed out[1] that using folio_test_hwpoison() is wrong as we need to check the indiviual page that has poison. folio_test_hwpoison() only checks the head page so go back to using PageHWPoison().

Fixes a6fddef49eef ("mm/memory-failure: convert unpoison_memory() to folios")

[1]: https://lore.kernel.org/lkml/[email protected]/

---
  mm/memory-failure.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +0 -0
index 02b1d8f104d51..a114c8c3039cd 100644
@@ -2523,7 +2523,7 @@ int unpoison_memory(unsigned long pfn)
  		goto unlock_mutex;
  	}
 
Quoted 10 lines

mm/memory-failure.c int unpoison_memory(unsigned long pfn) · line 2526

Quoted 2 lines
mm/memory-failure.c +1 -1
-	if (!folio_test_hwpoison(folio)) {
+	if (!PageHWPoison(p)) {

I don't think this works for hwpoisoned hugetlb pages that have PageHWPoison set on the head page, rather than on the raw subpage. In the case of hwpoisoned thps, PageHWPoison is set on the raw subpage, not on the head pages. (I believe this is not detected because no one considers the scenario of unpoisoning hwpoisoned thps, which is a rare case). Perhaps the function is_page_hwpoison() would be useful for this purpose?

Quoted 4 lines

Sorry, I was wrong. Checking PageHWPoison() is fine because the users of unpoison should know where the PageHWPoison is set via /proc/kpageflags. So this patch is OK to me after comments from other reviewers are resolved.

Hi Naoya,

While taking a closer at the patch, later in unpoison_memory() there is also:

- ret = TestClearPageHWPoison(page) ? 0 : -EBUSY;
+ ret = folio_test_clear_hwpoison(folio) ? 0 : -EBUSY;

I thought this folio conversion would be safe because page is the result of a compound_head() call but I'm wondering if the same issue exists here and we should be calling TestClearPageHWPoison() on the specific subpage by doing TestClearPageHWPoison(p).

Thanks,
Sidhartha Kumar

Quoted 5 lines

Thanks,
Naoya Horiguchi

#7 lore raw
Quoted 49 lines · Sidhartha Kumar
Quoted 35 lines · Naoya Horiguchi
Quoted 27 lines · Naoya Horiguchi
Quoted 20 lines · Sidhartha Kumar

It was pointed out[1] that using folio_test_hwpoison() is wrong as we need to check the indiviual page that has poison. folio_test_hwpoison() only checks the head page so go back to using PageHWPoison().

Fixes a6fddef49eef ("mm/memory-failure: convert unpoison_memory() to folios")

[1]: https://lore.kernel.org/lkml/[email protected]/

---
  mm/memory-failure.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +0 -0
index 02b1d8f104d51..a114c8c3039cd 100644

mm/memory-failure.c int unpoison_memory(unsigned long pfn) · line 2525

Quoted 4 lines
mm/memory-failure.c +1 -1
@@ -2523,7 +2523,7 @@ int unpoison_memory(unsigned long pfn)
  		goto unlock_mutex;
  	}
-	if (!folio_test_hwpoison(folio)) {
+	if (!PageHWPoison(p)) {
Quoted 6 lines

I don't think this works for hwpoisoned hugetlb pages that have PageHWPoison set on the head page, rather than on the raw subpage. In the case of hwpoisoned thps, PageHWPoison is set on the raw subpage, not on the head pages. (I believe this is not detected because no one considers the scenario of unpoisoning hwpoisoned thps, which is a rare case). Perhaps the function is_page_hwpoison() would be useful for this purpose?

Quoted 4 lines

Sorry, I was wrong. Checking PageHWPoison() is fine because the users of unpoison should know where the PageHWPoison is set via /proc/kpageflags. So this patch is OK to me after comments from other reviewers are resolved.

Hi Naoya,

While taking a closer at the patch, later in unpoison_memory() there is also:

(quoted diff) +1 -1
-               ret = TestClearPageHWPoison(page) ? 0 : -EBUSY;
+               ret = folio_test_clear_hwpoison(folio) ? 0 : -EBUSY;
Quoted 4 lines

I thought this folio conversion would be safe because page is the result of a compound_head() call but I'm wondering if the same issue exists here and we should be calling TestClearPageHWPoison() on the specific subpage by doing TestClearPageHWPoison(p).

In this case (get_hwpoison_page returns 0), the target of unpoison_memory was buddy page or free huge page, so there seems not any realistic problem. But putting back to TestClearPageHWPoison() looks consistent, so I'm fine with it.

Thanks,
Naoya Horiguchi

maintainer Reviewed-by on v1 1/1
#8 lore raw
In reply to Sidhartha Kumar
Quoted 20 lines · Sidhartha Kumar

It was pointed out[1] that using folio_test_hwpoison() is wrong as we need to check the indiviual page that has poison. folio_test_hwpoison() only checks the head page so go back to using PageHWPoison().

Fixes a6fddef49eef ("mm/memory-failure: convert unpoison_memory() to folios")

[1]: https://lore.kernel.org/lkml/[email protected]/

---
 mm/memory-failure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +0 -0
index 02b1d8f104d51..a114c8c3039cd 100644

mm/memory-failure.c int unpoison_memory(unsigned long pfn) · line 2526

Quoted 5 lines
mm/memory-failure.c +1 -1
@@ -2523,7 +2523,7 @@ int unpoison_memory(unsigned long pfn)
 		goto unlock_mutex;
 	}
 
-	if (!folio_test_hwpoison(folio)) {
+	if (!PageHWPoison(p)) {

For successfully handled pages, they should be non-compound pages (dissolved, splitted or normal pages). So this patch makes no change for them. But for failed to hwpoisoned thp and hugetlb, there's some difference. But since Naoya points out that, "the users of unpoison should know where the PageHWPoison is set via /proc/kpageflags.", I'm fine with this patch.

Thanks.