Skip to contentSkip to conversation

mm/memory-failure: teach kill_accessing_process to accept hugetlb tail page pfn

PATCH Superseded Jane Chu 5 participants 12 messages Dec 19, 2025 – Dec 23, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jane Chu

author
#0 lore raw

PATCH 1/1 mm/memory-failure: teach kill_accessing_process to accept hugetlb tail page pfn

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

This issue has already been taken care of in the normal path, that is, hwpoison_user_mappings(), see [1][2]. Further more, for [3] to work correctly in the hugetlb repoisoning case, it's essential to inform VM the precise poisoned page, not the head page.

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

---
 mm/memory-failure.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
mm/memory-failure.c +12 -10
index 3edebb0cda30..c9d87811b1ea 100644
@@ -681,9 +681,11 @@ static void set_to_kill(struct to_kill *tk, unsigned long addr, short shift)
 }
 
 static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
-				unsigned long poisoned_pfn, struct to_kill *tk)
+				unsigned long poisoned_pfn, struct to_kill *tk,
+				int pte_nr)
 {
 	unsigned long pfn = 0;
+	unsigned long hwpoison_vaddr;
 
 	if (pte_present(pte)) {
 		pfn = pte_pfn(pte);
@@ -694,10 +696,11 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
 			pfn = swp_offset_pfn(swp);
 	}
 
-	if (!pfn || pfn != poisoned_pfn)
+	if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn))
 		return 0;
 
-	set_to_kill(tk, addr, shift);
+	hwpoison_vaddr = addr + ((poisoned_pfn - pfn) << PAGE_SHIFT);
+	set_to_kill(tk, hwpoison_vaddr, shift);
 	return 1;
 }
 
@@ -749,7 +752,7 @@ static int hwpoison_pte_range(pmd_t *pmdp, unsigned long addr,
 
 	for (; addr != end; ptep++, addr += PAGE_SIZE) {
 		ret = check_hwpoisoned_entry(ptep_get(ptep), addr, PAGE_SHIFT,
-					     hwp->pfn, &hwp->tk);
+					     hwp->pfn, &hwp->tk, 1);
 		if (ret == 1)
 			break;
 	}
@@ -772,8 +775,8 @@ static int hwpoison_hugetlb_range(pte_t *ptep, unsigned long hmask,
 
 	ptl = huge_pte_lock(h, walk->mm, ptep);
 	pte = huge_ptep_get(walk->mm, addr, ptep);
-	ret = check_hwpoisoned_entry(pte, addr, huge_page_shift(h),
-					hwp->pfn, &hwp->tk);
+	ret = check_hwpoisoned_entry(pte, addr, huge_page_shift(h), hwp->pfn,
+				&hwp->tk, pages_per_huge_page(h));
 	spin_unlock(ptl);
 	return ret;
 }
@@ -2023,10 +2026,8 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
 		*hugetlb = 0;
 		return 0;
 	} else if (res == -EHWPOISON) {
-		if (flags & MF_ACTION_REQUIRED) {
-			folio = page_folio(p);
-			res = kill_accessing_process(current, folio_pfn(folio), flags);
-		}
+		if (flags & MF_ACTION_REQUIRED)
+			res = kill_accessing_process(current, pfn, flags);
 		action_result(pfn, MF_MSG_ALREADY_POISONED, MF_FAILED);
 		return res;
 	} else if (res == -EBUSY) {
@@ -2037,6 +2038,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
 		return action_result(pfn, MF_MSG_GET_HWPOISON, MF_IGNORED);
 	}
 
+
 	folio = page_folio(p);
 	folio_lock(folio);
 
Signature · 1 line
2.43.5
maintainer
#1 lore raw
Quoted 5 lines · Jane Chu

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

Quoted 9 lines

This issue has already been taken care of in the normal path, that is, hwpoison_user_mappings(), see [1][2]. Further more, for [3] to work correctly in the hugetlb repoisoning case, it's essential to inform VM the precise poisoned page, not the head page.

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

Thanks for your patch.

Quoted 24 lines
---
 mm/memory-failure.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
mm/memory-failure.c +3 -1
index 3edebb0cda30..c9d87811b1ea 100644
@@ -681,9 +681,11 @@ static void set_to_kill(struct to_kill *tk, unsigned long addr, short shift)
 }
 
 static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
-				unsigned long poisoned_pfn, struct to_kill *tk)
+				unsigned long poisoned_pfn, struct to_kill *tk,
+				int pte_nr)
 {
 	unsigned long pfn = 0;
+	unsigned long hwpoison_vaddr;
 
 	if (pte_present(pte)) {
 		pfn = pte_pfn(pte);

mm/memory-failure.c static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, · line 700

Quoted 6 lines
mm/memory-failure.c +1 -1
@@ -694,10 +696,11 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
 			pfn = swp_offset_pfn(swp);
 	}
 
-	if (!pfn || pfn != poisoned_pfn)
+	if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn))
 		return 0;

Can we get pte_nr from @shift? I.e. something like "pte_nr = 1UL << (shift - PAGE_SHIFT);"?

Thanks.
.

#2 lore raw
Quoted 45 lines · Miaohe Lin
Quoted 5 lines · Jane Chu

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

Quoted 9 lines

This issue has already been taken care of in the normal path, that is, hwpoison_user_mappings(), see [1][2]. Further more, for [3] to work correctly in the hugetlb repoisoning case, it's essential to inform VM the precise poisoned page, not the head page.

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

Thanks for your patch.

Quoted 27 lines
---
  mm/memory-failure.c | 22 ++++++++++++----------
  1 file changed, 12 insertions(+), 10 deletions(-)
mm/memory-failure.c +3 -1
index 3edebb0cda30..c9d87811b1ea 100644
@@ -681,9 +681,11 @@ static void set_to_kill(struct to_kill *tk, unsigned long addr, short shift)
  }
 
  static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
-				unsigned long poisoned_pfn, struct to_kill *tk)
+				unsigned long poisoned_pfn, struct to_kill *tk,
+				int pte_nr)
  {
  	unsigned long pfn = 0;
+	unsigned long hwpoison_vaddr;
 
  	if (pte_present(pte)) {
  		pfn = pte_pfn(pte);
@@ -694,10 +696,11 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
  			pfn = swp_offset_pfn(swp);
  	}
 
Quoted 5 lines

mm/memory-failure.c static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, · line 700

Quoted 3 lines
mm/memory-failure.c +1 -1
-	if (!pfn || pfn != poisoned_pfn)
+	if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn))
  		return 0;

Can we get pte_nr from @shift? I.e. something like "pte_nr = 1UL << (shift - PAGE_SHIFT);"?

Why? Is there any concern with using the macro pages_per_huge_page(h) ?

thanks!
-jane

Quoted 3 lines

Thanks.
.

maintainer
#3 lore raw
Quoted 51 lines · On 2025/12/19 16:06, [email protected] wrote:
Quoted 39 lines · Miaohe Lin
Quoted 5 lines · Jane Chu

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

Quoted 9 lines

This issue has already been taken care of in the normal path, that is, hwpoison_user_mappings(), see [1][2].  Further more, for [3] to work correctly in the hugetlb repoisoning case, it's essential to inform VM the precise poisoned page, not the head page.

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

Thanks for your patch.

Quoted 21 lines

---
  mm/memory-failure.c | 22 ++++++++++++----------

  1 file changed, 12 insertions(+), 10 deletions(-)
mm/memory-failure.c +3 -1
index 3edebb0cda30..c9d87811b1ea 100644
@@ -681,9 +681,11 @@ static void set_to_kill(struct to_kill *tk, unsigned long addr, short shift)
   }
     static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
-                unsigned long poisoned_pfn, struct to_kill *tk)
+                unsigned long poisoned_pfn, struct to_kill *tk,
+                int pte_nr)
   {
       unsigned long pfn = 0;
+    unsigned long hwpoison_vaddr;
         if (pte_present(pte)) {
           pfn = pte_pfn(pte);
Quoted 8 lines

mm/memory-failure.c static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, · line 700

Quoted 6 lines
mm/memory-failure.c +1 -0
@@ -694,10 +696,11 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
               pfn = swp_offset_pfn(swp);
       }
   -    if (!pfn || pfn != poisoned_pfn)
+    if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn))
           return 0;

Can we get pte_nr from @shift? I.e. something like "pte_nr = 1UL << (shift - PAGE_SHIFT);"?

Quoted 1 line

Why?  Is there any concern with using the macro pages_per_huge_page(h) ?

No, I was trying to get rid of new @pte_nr parameter. Something like below:

static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,

-                               unsigned long poisoned_pfn, struct to_kill *tk,
-                               int pte_nr)
+                               unsigned long poisoned_pfn, struct to_kill *tk)
 {
        unsigned long pfn = 0;
        unsigned long hwpoison_vaddr;

+ int pte_nr;

        if (pte_present(pte)) {
                pfn = pte_pfn(pte);
@@ -701,7 +701,8 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
                        pfn = softleaf_to_pfn(entry);
        }
-       if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn))
+       pte_nr = 1UL << (shift - PAGE_SHIFT);
+       if (!pfn || (pfn > poisoned_pfn || (pfn +  pte_nr - 1) < poisoned_pfn))
                return 0;

        hwpoison_vaddr = addr + ((poisoned_pfn - pfn) << PAGE_SHIFT);

So we don't have to pass in pte_nr from all callers. But that's trivial.

Thanks.
.

#4 lore raw
Quoted 78 lines · Miaohe Lin
Quoted 51 lines · On 2025/12/19 16:06, [email protected] wrote:
Quoted 39 lines · Miaohe Lin
Quoted 5 lines · Jane Chu

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

Quoted 9 lines

This issue has already been taken care of in the normal path, that is, hwpoison_user_mappings(), see [1][2].  Further more, for [3] to work correctly in the hugetlb repoisoning case, it's essential to inform VM the precise poisoned page, not the head page.

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

Thanks for your patch.

Quoted 21 lines
---
   mm/memory-failure.c | 22 ++++++++++++----------
   1 file changed, 12 insertions(+), 10 deletions(-)
mm/memory-failure.c +3 -1
index 3edebb0cda30..c9d87811b1ea 100644
@@ -681,9 +681,11 @@ static void set_to_kill(struct to_kill *tk, unsigned long addr, short shift)
   }
     static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
-                unsigned long poisoned_pfn, struct to_kill *tk)
+                unsigned long poisoned_pfn, struct to_kill *tk,
+                int pte_nr)
   {
       unsigned long pfn = 0;
+    unsigned long hwpoison_vaddr;
         if (pte_present(pte)) {
           pfn = pte_pfn(pte);
Quoted 8 lines

mm/memory-failure.c static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, · line 700

Quoted 6 lines
mm/memory-failure.c +1 -0
@@ -694,10 +696,11 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
               pfn = swp_offset_pfn(swp);
       }
   -    if (!pfn || pfn != poisoned_pfn)
+    if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn))
           return 0;

Can we get pte_nr from @shift? I.e. something like "pte_nr = 1UL << (shift - PAGE_SHIFT);"?

Quoted 1 line

Why?  Is there any concern with using the macro pages_per_huge_page(h) ?

No, I was trying to get rid of new @pte_nr parameter. Something like below:

static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,

mm/memory-failure.c +4 -3
-                               unsigned long poisoned_pfn, struct to_kill *tk,
-                               int pte_nr)
+                               unsigned long poisoned_pfn, struct to_kill *tk)
  {
         unsigned long pfn = 0;
         unsigned long hwpoison_vaddr;
+       int pte_nr;
 
         if (pte_present(pte)) {
                 pfn = pte_pfn(pte);
@@ -701,7 +701,8 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
                         pfn = softleaf_to_pfn(entry);
         }
 
-       if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn))
+       pte_nr = 1UL << (shift - PAGE_SHIFT);
+       if (!pfn || (pfn > poisoned_pfn || (pfn +  pte_nr - 1) < poisoned_pfn))
                 return 0;
 
         hwpoison_vaddr = addr + ((poisoned_pfn - pfn) << PAGE_SHIFT);
Quoted 1 line

So we don't have to pass in pte_nr from all callers. But that's trivial.

Got it, that's better. I will combine yours and Matthew's suggestion in v3.

Thanks a lot!
-jane

Quoted 4 lines

Thanks.
.

Reviewed-by on v1 1/1
#5 lore raw
In reply to Jane Chu
Quoted 10 lines · Jane Chu

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

This issue has already been taken care of in the normal path, that is, hwpoison_user_mappings(), see [1][2]. Further more, for [3] to work correctly in the hugetlb repoisoning case, it's essential to inform VM the precise poisoned page, not the head page.

Quoted 6 lines

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

I don't see stable in the Cc list, did you miss it?

Looks good, small nit below.

Quoted 69 lines
---
 mm/memory-failure.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
mm/memory-failure.c +11 -10
index 3edebb0cda30..c9d87811b1ea 100644
@@ -681,9 +681,11 @@ static void set_to_kill(struct to_kill *tk, unsigned long addr, short shift)
 }
 
 static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
-				unsigned long poisoned_pfn, struct to_kill *tk)
+				unsigned long poisoned_pfn, struct to_kill *tk,
+				int pte_nr)
 {
 	unsigned long pfn = 0;
+	unsigned long hwpoison_vaddr;
 
 	if (pte_present(pte)) {
 		pfn = pte_pfn(pte);
@@ -694,10 +696,11 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
 			pfn = swp_offset_pfn(swp);
 	}
 
-	if (!pfn || pfn != poisoned_pfn)
+	if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn))
 		return 0;
 
-	set_to_kill(tk, addr, shift);
+	hwpoison_vaddr = addr + ((poisoned_pfn - pfn) << PAGE_SHIFT);
+	set_to_kill(tk, hwpoison_vaddr, shift);
 	return 1;
 }
 
@@ -749,7 +752,7 @@ static int hwpoison_pte_range(pmd_t *pmdp, unsigned long addr,
 
 	for (; addr != end; ptep++, addr += PAGE_SIZE) {
 		ret = check_hwpoisoned_entry(ptep_get(ptep), addr, PAGE_SHIFT,
-					     hwp->pfn, &hwp->tk);
+					     hwp->pfn, &hwp->tk, 1);
 		if (ret == 1)
 			break;
 	}
@@ -772,8 +775,8 @@ static int hwpoison_hugetlb_range(pte_t *ptep, unsigned long hmask,
 
 	ptl = huge_pte_lock(h, walk->mm, ptep);
 	pte = huge_ptep_get(walk->mm, addr, ptep);
-	ret = check_hwpoisoned_entry(pte, addr, huge_page_shift(h),
-					hwp->pfn, &hwp->tk);
+	ret = check_hwpoisoned_entry(pte, addr, huge_page_shift(h), hwp->pfn,
+				&hwp->tk, pages_per_huge_page(h));
 	spin_unlock(ptl);
 	return ret;
 }
@@ -2023,10 +2026,8 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
 		*hugetlb = 0;
 		return 0;
 	} else if (res == -EHWPOISON) {
-		if (flags & MF_ACTION_REQUIRED) {
-			folio = page_folio(p);
-			res = kill_accessing_process(current, folio_pfn(folio), flags);
-		}
+		if (flags & MF_ACTION_REQUIRED)
+			res = kill_accessing_process(current, pfn, flags);
 		action_result(pfn, MF_MSG_ALREADY_POISONED, MF_FAILED);
 		return res;
 	} else if (res == -EBUSY) {

mm/memory-failure.c static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb · line 2041

Quoted 4 lines
mm/memory-failure.c +1 -0
@@ -2037,6 +2038,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
 		return action_result(pfn, MF_MSG_GET_HWPOISON, MF_IGNORED);
 	}
 
+

nit: extra witespace added.

Quoted 6 lines
mm/memory-failure.c +0 -0
 	folio = page_folio(p);
 	folio_lock(folio);
 
Signature · 1 line
2.43.5
#6 lore raw
Quoted 11 lines · Liam R. Howlett
Quoted 10 lines · Jane Chu

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

This issue has already been taken care of in the normal path, that is, hwpoison_user_mappings(), see [1][2]. Further more, for [3] to work correctly in the hugetlb repoisoning case, it's essential to inform VM the precise poisoned page, not the head page.

Quoted 8 lines
Quoted 6 lines

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

I don't see stable in the Cc list, did you miss it?

Good catch, thank you!

Quoted 4 lines

Looks good, small nit below.

Thanks!
-jane

Quoted 83 lines
Quoted 70 lines
---
  mm/memory-failure.c | 22 ++++++++++++----------
  1 file changed, 12 insertions(+), 10 deletions(-)
mm/memory-failure.c +11 -10
index 3edebb0cda30..c9d87811b1ea 100644
@@ -681,9 +681,11 @@ static void set_to_kill(struct to_kill *tk, unsigned long addr, short shift)
  }
 
  static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
-				unsigned long poisoned_pfn, struct to_kill *tk)
+				unsigned long poisoned_pfn, struct to_kill *tk,
+				int pte_nr)
  {
  	unsigned long pfn = 0;
+	unsigned long hwpoison_vaddr;
 
  	if (pte_present(pte)) {
  		pfn = pte_pfn(pte);
@@ -694,10 +696,11 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,
  			pfn = swp_offset_pfn(swp);
  	}
 
-	if (!pfn || pfn != poisoned_pfn)
+	if (!pfn || (pfn > poisoned_pfn || (pfn + pte_nr - 1) < poisoned_pfn))
  		return 0;
 
-	set_to_kill(tk, addr, shift);
+	hwpoison_vaddr = addr + ((poisoned_pfn - pfn) << PAGE_SHIFT);
+	set_to_kill(tk, hwpoison_vaddr, shift);
  	return 1;
  }
 
@@ -749,7 +752,7 @@ static int hwpoison_pte_range(pmd_t *pmdp, unsigned long addr,
 
  	for (; addr != end; ptep++, addr += PAGE_SIZE) {
  		ret = check_hwpoisoned_entry(ptep_get(ptep), addr, PAGE_SHIFT,
-					     hwp->pfn, &hwp->tk);
+					     hwp->pfn, &hwp->tk, 1);
  		if (ret == 1)
  			break;
  	}
@@ -772,8 +775,8 @@ static int hwpoison_hugetlb_range(pte_t *ptep, unsigned long hmask,
 
  	ptl = huge_pte_lock(h, walk->mm, ptep);
  	pte = huge_ptep_get(walk->mm, addr, ptep);
-	ret = check_hwpoisoned_entry(pte, addr, huge_page_shift(h),
-					hwp->pfn, &hwp->tk);
+	ret = check_hwpoisoned_entry(pte, addr, huge_page_shift(h), hwp->pfn,
+				&hwp->tk, pages_per_huge_page(h));
  	spin_unlock(ptl);
  	return ret;
  }
@@ -2023,10 +2026,8 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
  		*hugetlb = 0;
  		return 0;
  	} else if (res == -EHWPOISON) {
-		if (flags & MF_ACTION_REQUIRED) {
-			folio = page_folio(p);
-			res = kill_accessing_process(current, folio_pfn(folio), flags);
-		}
+		if (flags & MF_ACTION_REQUIRED)
+			res = kill_accessing_process(current, pfn, flags);
  		action_result(pfn, MF_MSG_ALREADY_POISONED, MF_FAILED);
  		return res;
  	} else if (res == -EBUSY) {

mm/memory-failure.c static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb · line 2041

Quoted 4 lines
mm/memory-failure.c +1 -0
@@ -2037,6 +2038,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
  		return action_result(pfn, MF_MSG_GET_HWPOISON, MF_IGNORED);
  	}
 
+

nit: extra witespace added.

Quoted 6 lines
mm/memory-failure.c +0 -0
  	folio = page_folio(p);
  	folio_lock(folio);
 
Signature · 1 line
2.43.5
maintainer
#7 lore raw
In reply to Jane Chu
Quoted 9 lines · On Thu, 18 Dec 2025 23:28:19 -0700 Jane Chu <[email protected]> wrote:

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

This issue has already been taken care of in the normal path, that is, hwpoison_user_mappings(), see [1][2]. Further more, for [3] to work correctly in the hugetlb repoisoning case, it's essential to inform VM the precise poisoned page, not the head page.

This conflicts with your "mm/memory-failure: fix missing ->mf_stats count in hugetlb poison".

Also conflicts a bit with "mm: fixup pfnmap memory failure handling to use pgoff" but that one isn't cc:stable, so this patch (which *is* cc:stable) takes priority.

Help?

#8 lore raw
Quoted 12 lines · Andrew Morton
Quoted 9 lines · On Thu, 18 Dec 2025 23:28:19 -0700 Jane Chu <[email protected]> wrote:

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

This issue has already been taken care of in the normal path, that is, hwpoison_user_mappings(), see [1][2]. Further more, for [3] to work correctly in the hugetlb repoisoning case, it's essential to inform VM the precise poisoned page, not the head page.

Quoted 9 lines

This conflicts with your "mm/memory-failure: fix missing ->mf_stats count in hugetlb poison".

Also conflicts a bit with "mm: fixup pfnmap memory failure handling to use pgoff" but that one isn't cc:stable, so this patch (which *is* cc:stable) takes priority.

Help?

Sorry Andrew. Let me try rebase v3 on top of my other patch. Will also take a look at this other conflict.

thanks,
-jane

#9 lore raw
In reply to Andrew Morton

Hi, Andrew,

Quoted 12 lines · Andrew Morton
Quoted 9 lines · On Thu, 18 Dec 2025 23:28:19 -0700 Jane Chu <[email protected]> wrote:

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

This issue has already been taken care of in the normal path, that is, hwpoison_user_mappings(), see [1][2]. Further more, for [3] to work correctly in the hugetlb repoisoning case, it's essential to inform VM the precise poisoned page, not the head page.

Quoted 6 lines

This conflicts with your "mm/memory-failure: fix missing ->mf_stats count in hugetlb poison".

Also conflicts a bit with "mm: fixup pfnmap memory failure handling to use pgoff" but that one isn't cc:stable, so this patch (which *is* cc:stable) takes priority.

I looked at
https://lore.kernel.org/lkml/[email protected]/
looks like we're changing different function, perhaps the conflict is peripheral?

thanks,
-jane

Quoted 3 lines

Help?

#10 lore raw
In reply to Jane Chu
Quoted 4 lines · Jane Chu

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

I don't think so? IIRC, for hugetlb folios we always reported the head PFN. And user space must assume that the whole thing is poisoned and will go away.

I recall that older QEMU even depended on that behavior, for example.

Signature · 3 lines
Cheers

David
#11 lore raw
Quoted 10 lines · David Hildenbrand (Red Hat)
Quoted 4 lines · Jane Chu

When a hugetlb folio is being poisoned again, try_memory_failure_hugetlb() passed head pfn to kill_accessing_process(), that is not right. The precise pfn of the poisoned page should be used in order to determine the precise vaddr as the SIGBUS payload.

I don't think so? IIRC, for hugetlb folios we always reported the head PFN. And user space must assume that the whole thing is poisoned and will go away.

I recall that older QEMU even depended on that behavior, for example.

What happens if non-head PFN of hugetlb is indicated in a SIGBUG to QEMU? Because, the regular path, the path via hwpoison_user_mappings() already behave this way.

I'm not familiar with QEMU. AFAIK, the need for this patch came from our VM/QEMU team.

thanks,
-jane