Skip to contentSkip to conversation

mm/hwpoison: Check the subpage, not the head page

PATCH Applied Matthew Wilcox (Oracle) 5 participants 8 messages Jan 30, 2022 – Feb 1, 2022

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

PATCH 1/1 mm/hwpoison: Check the subpage, not the head page

Hardware poison is tracked on a per-page basis, not on the head page.

---
 mm/rmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/rmap.c +2 -2
index 6a1e8c7f6213..09b08888120e 100644
@@ -1553,7 +1553,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
 		/* Update high watermark before we lower rss */
 		update_hiwater_rss(mm);
 
-		if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) {
+		if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);
@@ -1873,7 +1873,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma,
 			 * memory are supported.
 			 */
 			subpage = page;
-		} else if (PageHWPoison(page)) {
+		} else if (PageHWPoison(subpage)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 21 lines · Matthew Wilcox (Oracle)

Hardware poison is tracked on a per-page basis, not on the head page.

---
 mm/rmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/rmap.c +1 -1
index 6a1e8c7f6213..09b08888120e 100644
@@ -1553,7 +1553,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
 		/* Update high watermark before we lower rss */
 		update_hiwater_rss(mm);
 
-		if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) {
+		if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);

mm/rmap.c static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, · line 1879

Quoted 8 lines
mm/rmap.c +1 -1
@@ -1873,7 +1873,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma,
 			 * memory are supported.
 			 */
 			subpage = page;
-		} else if (PageHWPoison(page)) {
+		} else if (PageHWPoison(subpage)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);

This looks correct. Correct me if I'm wrong that this is for consistency and cleanup and that there is no bug being fixed by this, however.

Thanks!

#2 lore raw
Quoted 26 lines · David Rientjes
Quoted 24 lines · Matthew Wilcox (Oracle)

Hardware poison is tracked on a per-page basis, not on the head page.

---
 mm/rmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/rmap.c +1 -1
index 6a1e8c7f6213..09b08888120e 100644
@@ -1553,7 +1553,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
 		/* Update high watermark before we lower rss */
 		update_hiwater_rss(mm);
 
-		if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) {
+		if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);
@@ -1873,7 +1873,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma,
 			 * memory are supported.
 			 */
 			subpage = page;
Quoted 8 lines

mm/rmap.c static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, · line 1879

Quoted 5 lines
mm/rmap.c +1 -1
-		} else if (PageHWPoison(page)) {
+		} else if (PageHWPoison(subpage)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);

This looks correct. Correct me if I'm wrong that this is for consistency and cleanup and that there is no bug being fixed by this, however.

Oh, no, I think there's a real bug here. It's just that we're looking at an uncommon & hence rarely-tested scenario -- a memory fault in the middle of a THP (in mainline; obviously it'll be a little more common with arbitrary sized folios). I don't do HWPoison testing myself, so this was by inspection and not from testing. A scenario where things would go wrong is a memory error on a non-head-page would go unnoticed when migrating or unmapping. Contrariwise, if there's a hardware error on a head page, all the subpages get treated as poisoned, even though they shouldn't be.

#3 lore raw
Quoted 36 lines · Matthew Wilcox
Quoted 26 lines · David Rientjes
Quoted 24 lines · Matthew Wilcox (Oracle)

Hardware poison is tracked on a per-page basis, not on the head page.

---
 mm/rmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/rmap.c +1 -1
index 6a1e8c7f6213..09b08888120e 100644
@@ -1553,7 +1553,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
 		/* Update high watermark before we lower rss */
 		update_hiwater_rss(mm);
 
-		if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) {
+		if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);
@@ -1873,7 +1873,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma,
 			 * memory are supported.
 			 */
 			subpage = page;
Quoted 8 lines

mm/rmap.c static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, · line 1879

Quoted 5 lines
mm/rmap.c +1 -1
-		} else if (PageHWPoison(page)) {
+		} else if (PageHWPoison(subpage)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);

This looks correct. Correct me if I'm wrong that this is for consistency and cleanup and that there is no bug being fixed by this, however.

Quoted 9 lines

Oh, no, I think there's a real bug here. It's just that we're looking at an uncommon & hence rarely-tested scenario -- a memory fault in the middle of a THP (in mainline; obviously it'll be a little more common with arbitrary sized folios). I don't do HWPoison testing myself, so this was by inspection and not from testing. A scenario where things would go wrong is a memory error on a non-head-page would go unnoticed when migrating or unmapping. Contrariwise, if there's a hardware error on a head page, all the subpages get treated as poisoned, even though they shouldn't be.

Thank you for reporting. As you point out, the current check does not handle thp properly. The reason of checking head page here is to handle hwpoisoned hugetlb (which has PG_hwpoison on the head page even if the error is on any of tail page). So I think that the proper fix is to add a helper function to check page type (normal, thp, or hugetlb) as well as PageHWPoison.

Thanks,
Naoya Horiguchi

#4 lore raw
Quoted 47 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 36 lines · Matthew Wilcox
Quoted 26 lines · David Rientjes
Quoted 24 lines · Matthew Wilcox (Oracle)

Hardware poison is tracked on a per-page basis, not on the head page.

---
 mm/rmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/rmap.c +1 -1
index 6a1e8c7f6213..09b08888120e 100644
@@ -1553,7 +1553,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
 		/* Update high watermark before we lower rss */
 		update_hiwater_rss(mm);
 
-		if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) {
+		if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);
@@ -1873,7 +1873,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma,
 			 * memory are supported.
 			 */
 			subpage = page;
Quoted 8 lines

mm/rmap.c static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, · line 1879

Quoted 5 lines
mm/rmap.c +1 -1
-		} else if (PageHWPoison(page)) {
+		} else if (PageHWPoison(subpage)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);

This looks correct. Correct me if I'm wrong that this is for consistency and cleanup and that there is no bug being fixed by this, however.

Quoted 9 lines

Oh, no, I think there's a real bug here. It's just that we're looking at an uncommon & hence rarely-tested scenario -- a memory fault in the middle of a THP (in mainline; obviously it'll be a little more common with arbitrary sized folios). I don't do HWPoison testing myself, so this was by inspection and not from testing. A scenario where things would go wrong is a memory error on a non-head-page would go unnoticed when migrating or unmapping. Contrariwise, if there's a hardware error on a head page, all the subpages get treated as poisoned, even though they shouldn't be.

Quoted 5 lines

Thank you for reporting. As you point out, the current check does not handle thp properly. The reason of checking head page here is to handle hwpoisoned hugetlb (which has PG_hwpoison on the head page even if the error is on any of tail page). So I think that the proper fix is to add a helper function to check page type (normal, thp, or hugetlb) as well as PageHWPoison.

I think this handles HugeTLB pages correctly:

                subpage = page - page_to_pfn(page) + pte_pfn(*pvmw.pte);

As I understand the HugeTLB code, pvmw.pte refers to the head page, not the subpage (unlike a PTE-mapped THP page, where it would refer to the precise page). But I cheerfully admit that the intricacies of the HugeTLB code are not something I'm an expert on.

#5 lore raw
Quoted 54 lines · Matthew Wilcox
Quoted 47 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 36 lines · Matthew Wilcox
Quoted 26 lines · David Rientjes
Quoted 24 lines · Matthew Wilcox (Oracle)

Hardware poison is tracked on a per-page basis, not on the head page.

---
 mm/rmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/rmap.c +1 -1
index 6a1e8c7f6213..09b08888120e 100644
@@ -1553,7 +1553,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
 		/* Update high watermark before we lower rss */
 		update_hiwater_rss(mm);
 
-		if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) {
+		if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);
@@ -1873,7 +1873,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma,
 			 * memory are supported.
 			 */
 			subpage = page;
Quoted 8 lines

mm/rmap.c static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, · line 1879

Quoted 5 lines
mm/rmap.c +1 -1
-		} else if (PageHWPoison(page)) {
+		} else if (PageHWPoison(subpage)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);

This looks correct. Correct me if I'm wrong that this is for consistency and cleanup and that there is no bug being fixed by this, however.

Quoted 9 lines

Oh, no, I think there's a real bug here. It's just that we're looking at an uncommon & hence rarely-tested scenario -- a memory fault in the middle of a THP (in mainline; obviously it'll be a little more common with arbitrary sized folios). I don't do HWPoison testing myself, so this was by inspection and not from testing. A scenario where things would go wrong is a memory error on a non-head-page would go unnoticed when migrating or unmapping. Contrariwise, if there's a hardware error on a head page, all the subpages get treated as poisoned, even though they shouldn't be.

Quoted 5 lines

Thank you for reporting. As you point out, the current check does not handle thp properly. The reason of checking head page here is to handle hwpoisoned hugetlb (which has PG_hwpoison on the head page even if the error is on any of tail page). So I think that the proper fix is to add a helper function to check page type (normal, thp, or hugetlb) as well as PageHWPoison.

Quoted 8 lines

I think this handles HugeTLB pages correctly:

                subpage = page - page_to_pfn(page) + pte_pfn(*pvmw.pte);

As I understand the HugeTLB code, pvmw.pte refers to the head page, not the subpage (unlike a PTE-mapped THP page, where it would refer to the precise page). But I cheerfully admit that the intricacies of the HugeTLB code are not something I'm an expert on.

Your understanding is correct. Here is the comment for the routine which sets pvmw.pte.

* For HugeTLB pages, @pvmw->pte is set to the relevant page table entry
* regardless of which page table level the page is mapped at. @pvmw->pmd is
* NULL.

Just another thought. With new hugetlb vmmemmap optimizations, it is not possible to set poison on hugetlb tail pages until after allocating struct pages.

Signature · 1 line
Mike Kravetz
#6 lore raw
Quoted 55 lines · Mike Kravetz
Quoted 54 lines · Matthew Wilcox
Quoted 52 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 36 lines · Matthew Wilcox
Quoted 26 lines · David Rientjes
Quoted 24 lines · Matthew Wilcox (Oracle)

Hardware poison is tracked on a per-page basis, not on the head page.

---
 mm/rmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/rmap.c +1 -1
index 6a1e8c7f6213..09b08888120e 100644
@@ -1553,7 +1553,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
 		/* Update high watermark before we lower rss */
 		update_hiwater_rss(mm);
 
-		if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) {
+		if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);
@@ -1873,7 +1873,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma,
 			 * memory are supported.
 			 */
 			subpage = page;
Quoted 8 lines

mm/rmap.c static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, · line 1879

Quoted 5 lines
mm/rmap.c +1 -1
-		} else if (PageHWPoison(page)) {
+		} else if (PageHWPoison(subpage)) {
 			pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
 			if (PageHuge(page)) {
 				hugetlb_count_sub(compound_nr(page), mm);

This looks correct. Correct me if I'm wrong that this is for consistency and cleanup and that there is no bug being fixed by this, however.

Quoted 9 lines

Oh, no, I think there's a real bug here. It's just that we're looking at an uncommon & hence rarely-tested scenario -- a memory fault in the middle of a THP (in mainline; obviously it'll be a little more common with arbitrary sized folios). I don't do HWPoison testing myself, so this was by inspection and not from testing. A scenario where things would go wrong is a memory error on a non-head-page would go unnoticed when migrating or unmapping. Contrariwise, if there's a hardware error on a head page, all the subpages get treated as poisoned, even though they shouldn't be.

Thank you for reporting. As you point out, the current check does not handle thp properly. The reason of checking head page here is to handle hwpoisoned hugetlb (which has PG_hwpoison on the head page even if the error is on any of tail page). So I think that the proper fix is to add a helper function to check page type (normal, thp, or hugetlb) as well as PageHWPoison.

Quoted 8 lines
Quoted 8 lines

I think this handles HugeTLB pages correctly:

                subpage = page - page_to_pfn(page) + pte_pfn(*pvmw.pte);

As I understand the HugeTLB code, pvmw.pte refers to the head page, not the subpage (unlike a PTE-mapped THP page, where it would refer to the precise page). But I cheerfully admit that the intricacies of the HugeTLB code are not something I'm an expert on.

Sorry, you're right.

Quoted 7 lines

Your understanding is correct. Here is the comment for the routine which sets pvmw.pte.

* For HugeTLB pages, @pvmw->pte is set to the relevant page table entry
* regardless of which page table level the page is mapped at. @pvmw->pmd is
* NULL.

Thank you for the clarification.

Quoted 4 lines

Just another thought. With new hugetlb vmmemmap optimizations, it is not possible to set poison on hugetlb tail pages until after allocating struct pages.

So the proposed patch is fine to me.

#7 lore raw
In reply to Matthew Wilcox (Oracle)
Quoted 2 lines · Matthew Wilcox (Oracle)

Hardware poison is tracked on a per-page basis, not on the head page.

Looks correct to me. Reviewed-by: Yang Shi <[email protected]>

Quoted 32 lines
---
 mm/rmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/rmap.c +2 -3
index 6a1e8c7f6213..09b08888120e 100644
@@ -1553,7 +1553,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
                /* Update high watermark before we lower rss */
                update_hiwater_rss(mm);
 
-               if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) {
+               if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) {
                        pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
                        if (PageHuge(page)) {
                                hugetlb_count_sub(compound_nr(page), mm);
@@ -1873,7 +1873,7 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma,
                         * memory are supported.
                         */
                        subpage = page;
-               } else if (PageHWPoison(page)) {
+               } else if (PageHWPoison(subpage)) {
                        pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
                        if (PageHuge(page)) {
                                hugetlb_count_sub(compound_nr(page), mm);
--

2.34.1